github slackapi/bolt-python v1.5.0
version 1.5.0

latest releases: v1.19.0rc1, v1.18.1, v1.18.0.dev1...
3 years ago

New Features

Underlying SDK Upgrade

This release upgrades the underlying slack-sdk package from 3.4 to 3.5 (or higher). Refer to the package's release note for more details: https://github.com/slackapi/python-slack-sdk/releases/tag/v3.5.0

Built-in Token Revocation Handlers

Since this version, the out-of-the-box support for the following events is available:

To use this feature, all you need to do are:

  • Enable installation_store of the OAuth settings (see the document)
  • Call enable_token_revocation_listeners() method of the App / AsyncApp instance
app = App(
  # Enabling installation_store required
)
app.enable_token_revocation_listeners()

This is equivalent to the following code:

app = App()  # installation_store required
app.event("tokens_revoked")(app.default_tokens_revoked_event_listener)
app.event("app_uninstalled")(app.default_app_uninstalled_event_listener)

These event listeners properly utilize the data deletion methods in the InstallationStore you use. If you have your own InstallationStore implementation, please implement deletion methods in the classes. Refer to slackapi/python-slack-sdk#995 for more details.

Customize Unhandled Error Handling

Handling unmatched request patterns had not been customizable in the past versions. The pull request #290 introduced a new option to enable using @app.error handlers for unmatched requests. The default is set to False, which is fully backward compatible. If the option is True, Bolt raises a BoltUnhandledRequestError with sufficient information. @app.error handler can customize the behavior for the patterns (e.g., having custom logging, changing HTTP status from 404 to something else).

app = App(
    token=os.environ["SLACK_BOT_TOKEN"],
    signing_secret=os.environ["SLACK_SIGNING_SECRET"],
    # enable @app.error handler to catch the patterns
    raise_error_for_unhandled_request=True,
)

@app.error
def handle_errors(error):
    if isinstance(error, BoltUnhandledRequestError):
        # You may want to have debug/info logging here
        return BoltResponse(status=200, body="")
    else:
        # other error patterns
        return BoltResponse(status=500, body="Something wrong")

Add respond to app.view Listeners

When an input block in your modal has response_url_enabled: true, view_submission payloads can have response_urls. Since this version, you can use respond utility to use the primary element in the array.

@app.view("view-id")
def check(ack, respond):
    # if there is an input block with response_url_enabled: true
    respond("This message will be posted in the selected channel")
    ack()

see also:

Better Compatibility with Thread-local feature based Libraries

ListenerCompletionHandler is a new addition, which enables developers to customize callbacks for listener runner completion. The callbacks can be useful, especially when you use a library/framework that utilizes thread-local variables (e.g., Django ORM, thread-local sessions in SQLAlchemy) along with Bolt for Python.

If you're interested in how it works, check the updated Django adapter implementation for details: https://github.com/slackapi/bolt-python/blob/v1.5.0/slack_bolt/adapter/django/handler.py

from django.db import connections

class DjangoListenerCompletionHandler(ListenerCompletionHandler):
    def handle(self, request: BoltRequest, response: Optional[BoltResponse]) -> None:
        # closes all the thread-local connections in the current thread
        connections.close_all()

Changes

  • #270 Add support for lazy listeners when running with chalice local - Thanks @jlujan-invitae
  • #281 Fix #280 Django thread-local connection cleanup in multi threads - Thanks @seratch
  • #287 Enable installation_store authorize to fallback to bots (prep for #254) - Thanks @seratch
  • #289 Fix #254 Add built-in tokens_revoked/app_uninstalled event handlers - Thanks @seratch
  • #288 Fix #260 Enable to use respond utility in app.view listeners (only when response_urls exists) - Thanks @seratch
  • #290 Fix #273 Enable developers to customize the way to handle unmatched requests - Thanks @seratch

References

Don't miss a new bolt-python release

NewReleases is sending notifications on new releases.