Slack
To make your Chainlit app available on Slack, you will need to create a Slack app and set up the necessary environment variables.
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.
This will give you a public URL that you can use to set up the app manifest. Do not forget to replace it once you deploy Chainlit to a public host.
Set the App Manifest
Go to App Manifest and paste the following Yaml.
{placeholders}
with your own values.Click on Save Changes.
Set the App Manifest
You will see a warning stating that the URL is not verified. You can ignore this for now.
[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
Install the Slack App to Your Workspace
Navigate to the Install App tab and click on Install to Workspace.
Set the Environment Variables
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:
Reminder: Make sure the environment variables are set and that your local chainlit app is exposed to the internet via ngrok.
Start the Chainlit app:
Using -h to not open the default Chainlit UI since we are using Slack.
You should now be able to interact with your Chainlit app through Slack.
Chat History
Chat history is directly available through the fetch_slack_message_history
method.
It will fetch the last messages from the current thread or DM channel.