class platypush.plugins.slack.SlackPlugin(app_token: str, bot_token: str, user_token: str | None = None, **kwargs)[source]#

Bases: ChatPlugin, RunnablePlugin

Plugin used to interact with Slack instances.

You’ll have to generate your own Slack app and tokens in order to use this plugin. Steps:

  • Create a new Slack app here <> and associate a Slack workspace to it.

  • In the configuration panel of your app scroll to Socket Mode and select Enable Socket Mode.

  • Scroll to Event Subscriptions and select Enable Events.

  • Choose the type of events that you want to subscribe to. You can select bot events (i.e. when somebody in the channel mentions the name of your app) or any of the workspace events (e.g. creation of messages, user events etc.).

  • Scroll to App-Level Tokens and generate a new token with connections:write scope. This token will be used to receive Slack events over websocket.

  • Scroll to OAuth & Permissions and select the scopes that you want to enable. You may usually want to enable Bot Token Scopes -> app_mentions:read, so the script can react when somebody mentions its name. You may also want to select the user scopes relevant to your application - e.g. read/write messages, manage users etc.

  • If you changed scopes and settings, you may have to reinstall the app in the workspace through the Install App menu.

  • Navigate to the Install App menu. If the app has been correctly installed in your workspace then you should see a Bot User OAuth Token, used to authenticate API calls performed as the app/bot. If you also granted user permissions to the app then you should also see a User OAuth Token on the page.


__init__(app_token: str, bot_token: str, user_token: str | None = None, **kwargs)[source]#
  • app_token – Your Slack app token.

  • bot_token – Bot OAuth token reported on the Install App menu.

  • user_token – User OAuth token reported on the Install App menu.


Implementation of the main loop of the plugin.

send_message(channel: str, as_user: bool = False, text: str | None = None, blocks: Iterable[str] | None = None, **kwargs)[source]#

Send a message to a channel. It requires a token with chat:write bot/user scope.

  • channel – Channel ID or name.

  • as_user – If true then the message will be sent as the authorized user, otherwise as the application bot (default: false).

  • text – Text to be sent.

  • blocks – Extra blocks to be added to the message (e.g. images, links, markdown). See Slack documentation for blocks.


Stop the plugin.