- class platypush.plugins.slack.SlackPlugin(app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs)¶
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.
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:writescope. 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.
platypush.message.event.chat.slack.SlackMessageReceivedEventwhen a message is received on a
platypush.message.event.chat.slack.SlackMessageEditedEventwhen a message is edited on a
platypush.message.event.chat.slack.SlackMessageDeletedEventwhen a message is deleted from a
platypush.message.event.chat.slack.SlackAppMentionReceivedEventwhen a message that mentions
the app is received on a monitored channel.
- __init__(app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs)¶
- send_message(channel: str, as_user: bool = False, text: Optional[str] = None, blocks: Optional[Iterable[str]] = None, **kwargs)¶
Send a message to a channel. It requires a token with
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.