New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom function support #1021
base: main
Are you sure you want to change the base?
Conversation
* add listener --------- Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1021 +/- ##
==========================================
+ Coverage 91.76% 91.96% +0.20%
==========================================
Files 181 190 +9
Lines 6315 6512 +197
==========================================
+ Hits 5795 5989 +194
- Misses 520 523 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments
self.client = client | ||
self.function_execution_id = function_execution_id | ||
|
||
def __call__(self, outputs: Dict[str, Any] = {}) -> SlackResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a default value here, you should not use an empty dict value for argument default. See https://stackoverflow.com/questions/26320899/why-is-the-empty-dictionary-a-dangerous-default-value-in-python for more details
def __call__(self, outputs: Dict[str, Any] = {}) -> SlackResponse: | |
def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> SlackResponse: |
And the following lines of code should be updated accordingly.
If the default value is not necessary, you can simply remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow TIL, did not think the default value would be assigned to the function itself 😮
self.client = client | ||
self.function_execution_id = function_execution_id | ||
|
||
async def __call__(self, error: str = "") -> AsyncSlackResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to allow no error here? I believe we don't need to have the default value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we don't need the default value here 👍
Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
This PR includes all the changes from #986 aims to add support for custom functions in Bolt Python
Feedback
I'm looking for feedback on
Testing
This gist was created to show how to test these new feature, use it with the following steps
a. Head to https://api.slack.com/apps/?new_app=1
b. Click "From an app manifest"
c. Select YAML and paste the above manifest.yml content
d. Click create button
a. Install the app anyways (when the workspace is in an Org, org-wide installation is required to publish functions)
b. Grab the xoxb- token (Settings > Install App > Bot User OAuth Token)
c.
export SLACK_BOT_TOKEN=xoxb-...
a. Head to Settings > Basic Information > App-Level Tokens on the https://api.slack.com/apps page
b. Generate a new token with connections:write scope
c.
export SLACK_APP_TOKEN=xapp-...
a. Add
app.py
andasync_app.py
with the above source codeb. Pull the latest PR branch of bolt python to your local
c. Run
scripts/build_pypi_package.sh
this will generate a.whl
in thedist/
folderd. (Optional) In your project set up a venv with
python -m venv .venv
andsource .venv/bin/activate
e.
pip install global/path/to/bolt-python/dist/something.whl
f.
pip install aiohttp
g
python app.py
orpython async_app.py
a. Open the workflow builder
b. Create a new workflow with a link trigger
d. Seach "Hello" in the Steps view on the right side
e. Add the step to the workflow (you can set any user ID as the input)
f. Publish the workflow
Category
slack_bolt.App
and/or its core componentsslack_bolt.async_app.AsyncApp
and/or its core componentsslack_bolt.adapter
/docs
Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
./scripts/install_all_and_run_tests.sh
after making the changes.