slack

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

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.

Triggers:

__init__(app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs)[source]
Parameters
  • 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.

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

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

Parameters
  • 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.