- class platypush.plugins.slack.SlackPlugin(app_token: str, bot_token: str, user_token: str | None = 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 <https://api.slack.com/apps> 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: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: str | None = None, **kwargs)#
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)#
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.
Stop the plugin.