This documentation describes the integration of MindsDB with Slack, a cloud-based collaboration platform.
The integration allows MindsDB to access data from Slack and enhance Slack with AI capabilities.
Method 1: Chatbot responds in direct messages to a Slack app
One way to connect Slack is to use both bot and app tokens. By following the instructions below, you’ll set up the Slack app and be able to message this Slack app directly to chat with the bot.
If you want to use Slack in the CREATE CHATBOT syntax, use this method of connecting Slack to MindsDB.
Here is how to set up a Slack app and generate both a Slack bot token and a Slack app token:
Follow this link and sign in with your Slack account.
Create a new app From scratch or select an existing app.
Please note that the following instructions support apps created From scratch.
For apps created From an app manifest, please follow the Slack docs here.
Go to Basic Information under Settings.
Under App-Level Tokens, click on Generate Token and Scopes.
Name the token socket and add the connections:write scope.
Copy and save the xapp-... token - you’ll need it to publish the chatbot.
Go to Socket Mode under Settings and toggle the button to Enable Socket Mode.
Go to OAuth & Permissions under Features.
Add the following Bot Token Scopes:
app_mentions:read
channels:history
channels:read
chat:write
groups:history
groups:read (optional)
im:history
im:read
im:write
mpim:read (optional)
users.profile:read
users:read (optional)
In the OAuth Tokens for Your Workspace section, click on Install to Workspace and then Allow.
Copy and save the xoxb-... token - you’ll need it to publish the chatbot.
Go to App Home under Features and click on the checkbox to Allow users to send Slash commands and messages from the messages tab.
Go to Event Subscriptions under Features.
Toggle the button to Enable Events.
Under Subscribe to bot events, click on Add Bot User Event and add app_mention and message.im.
Click on Save Changes.
Now you can use tokens from points 3 and 5 to initialize the Slack handler in MindsDB.
This connection method enables you to chat directly with an app via Slack.
Alternatively, you can connect an app to the Slack channel:
Go to the channel where you want to use the bot.
Right-click on the channel and select View Channel Details.
Method 2: Chatbot responds on a defined Slack channel
Another way to connect to Slack is to use the bot token only. By following the instructions below, you’ll set up the Slack app and integrate it into one of the channels from which you can directly chat with the bot.
Here is how to set up a Slack app and generate a Slack bot token:
Follow this link and sign in with your Slack account.
Create a new app From scratch or select an existing app.
Please note that the following instructions support apps created From scratch.
For apps created From an app manifest, please follow the Slack docs here.
Go to the OAuth & Permissions section.
Under the Scopes section, add the Bot Token Scopes necessary for your application. You can add more later as well.
channels:history
channels:read
chat:write
groups:read
im:read
mpim:read
users:read
Install the bot in your workspace.
Under the OAuth Tokens for Your Workspace section, copy the the Bot User OAuth Token value.
Open your Slack application and add the App/Bot to one of the channels:
Go to the channel where you want to use the bot.
Right-click on the channel and select View Channel Details.
Select Integrations.
Click on Add an App.
Now you can use the token from step 6 to initialize the Slack handler in MindsDB and use the channel name to query and write messages.
To find the channel ID of a conversation, you can use the conversations table:
SELECT*FROM mindsdb_slack.conversationsWHERE name ="<channel-name>";
Please note that if your workspace has more than 1000 conversations, you may need to use the LIMIT clause to retrieve all conversations. More information on this can be found below.
You can also find the channel ID by right-clicking on the conversation in Slack, selecting ‘View conversation details’ or ‘View channel details,’ and copying the channel ID from the bottom of the ‘About’ tab.
Also, you can post messages to the conversation like this:
INSERTINTO mindsdb_slack.messages (channel_id,text)VALUES("<channel-id>","Hey MindsDB, Thanks to you! Now I can respond to my Slack messages through SQL Queries.");
And you can delete messages, but only the ones posted by the bot.