How it Works
The Slack bot will listen to messages mentioning it in channels and direct messages. It will send replies to a dedicated thread or DM depending on the context.
Preview
Supported Features
Message | Streaming | Elements | Audio | Ask User | Chat History | Chat Profiles | Feedback |
---|---|---|---|---|---|---|---|
✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ |
Install the Slack Bolt Library
The Slack Bolt library is not included in the Chainlit dependencies. You will have to install it manually.Create a Slack App
To start, navigate to the Slack apps dashboard for the Slack API. Here, you should find a green button that says Create New App. When you click this button, select the option to create your app from scratch. Create a name for your bot, such as “ChainlitDemo”. Select the workspace you would like your bot to exist in.
Create a Slack App
Working Locally
If you are working locally, you will have to expose your local Chainlit app to the internet to receive incoming messages to Slack. You can use ngrok for this.Set the App Manifest
Go to App Manifest and paste the following Yaml.Replace the
{placeholders}
with your own values.
Set the App Manifest
[Optional] Allow users to send DMs to Chainlit
By default the app will only listen to mentions in channels. If you want to allow users to send direct messages to the app, go to App Home and enable “Allow users to send Slash commands and messages from the messages tab”.
Allow DMs
[Optional] Emoji Reaction on Message Received
Adds an optional feature to show emoji reactions when Slack messages are received, providing immediate user feedback while the bot processes the request.This feature requires the
reactions:write
OAuth scope. If you enable this feature, you’ll need to add this scope to your Slack app’s OAuth configuration.chainlit.md
file:
This feature is disabled by default to maintain backward compatibility. If you enable this feature, you’ll need to add the
reactions:write
scope to your Slack app’s OAuth configuration.
How it will look like
Install the Slack App to Your Workspace
Navigate to the Install App tab and click on Install to Workspace.Set the Environment Variables
Set the environment variables outside of your application code.
Bot Token
Once the slack application is installed, you will see the Bot User OAuth Token. Set this as an environment variable in your Chainlit app.
Copy the Bot Token
Signing Secret
Navigate to the Basic Information tab and copy the Signing Secret. Then set it as an environment variable in your Chainlit app.
Copy the Signing Secret
Start the Chainlit App
Since the Chainlit app is not running, the Slack app will not be able to communicate with it. For the example, we will use this simple app:my_app.py
Reminder: Make sure the environment variables are set and that your local
chainlit app is exposed to the internet via ngrok.
Using -h to not open the default Chainlit UI since we are using Slack.
Chat History
Chat history is directly available through thefetch_slack_message_history
method.
It will fetch the last messages from the current thread or DM channel.