Skip to content
Dispatch Dispatch Dispatch

Slack

Dispatch provides a built-in integration with Slack SDK, offering error handling out of the box. It’s enabled by default and it takes no extra code to set it up.

import dispatch
from slack_sdk import WebClient
slack = WebClient(token="<your bot token>")
@dispatch.function
def send_slack_notification():
slack.chat_postMessage(channel="#random", text="Hello world")
def main():
send_slack_notification.dispatch()
dispatch.run(main)

Exception handling

SlackApiError

Depending on the response.status_code attribute, a different Dispatch behavior is applied.

HTTP status codeDescriptionDispatch status
1xxInformationalStatus.PERMANENT_ERROR
2xxSuccessfulStatus.OK
3xxRedirectionStatus.PERMANENT_ERROR
3xxRedirectionStatus.PERMANENT_ERROR
4xxClient errorStatus.PERMANENT_ERROR
400Bad requestStatus.INVALID_ARGUMENT
401UnauthorizedStatus.UNAUTHENTICATED
403ForbiddenStatus.PERMISSION_DENIED
404Not foundStatus.NOT_FOUND
408Request timeoutStatus.TIMEOUT
429Too many requestsStatus.THROTTLED
5xxServer errorStatus.TEMPORARY_ERROR
501Not implementedStatus.PERMANENT_ERROR

SlackClientError

Returns Status.TEMPORARY_ERROR, unless exception is SlackApiError, since SlackClientError is a parent class of that exception. Learn more in Slack SDK documentation.

Response handling

If a function returns slack_sdk.web.SlackResponse instance, Dispatch looks at the status_code attribute and determines behavior the same way as SlackApiError exception.

import dispatch
from slack_sdk import WebClient
slack = WebClient(token="<your bot token>")
@dispatch.function
def send_slack_notification():
response = slack.chat_postMessage(channel="#random", text="Hello world")
return response
def main():
send_slack_notification.dispatch()
dispatch.run(main)