Component Libraries •
Project Templates
Docs •
Install •
Tutorials •
Developer Guides •
Contribute •
Blog •
Discord
Xircuits Component Library to interface with Slack! Create Slack Bots in seconds.
This library provides a simple way to create and manage custom Slack components bots in your workspace. In this README, you'll find the steps to set up a Slack application and start using the xai-slack library.
Before you begin, you will need the following:
- A Slack workspace.
- Python3.9+.
- Xircuits.
Initializes a Slack WebClient using a provided bot token or environment variable. The created client is added to the context for further use by other components.
Monitors Slack messages for image attachments and triggers a specified component when such a message is detected. Downloads and processes the attached image.
Creates a Slack Bolt App
instance for managing Slack events and interactions. The app is added to the context for other components to utilize.
Starts a Socket Mode connection for the Slack app. Can run the connection on a separate thread if required.
Listens for Slack messages or app mentions and triggers a specified event-handling component. Supports filtering based on app mentions.
Sends a predefined response to messages containing a specified trigger text. Can reply in threads if enabled.
Replies with multiple images to a message containing a specified trigger. Supports optional titles for the images.
Extracts an image from a Slack thread based on a file name mentioned in curly braces and applies a mask (e.g., top, bottom, left, right) if specified.
Detects specific triggers in Slack messages or replies and executes corresponding branches. Optionally filters mentions, tags, and triggers from the text.
Sends a message to a specific server and channel in Slack.
We have provided several example workflows to help you get started with the xai-slack component library. Give them a try and see how you can create custom Slack components for your workspace.
Check out the msg_trigger.xircuits
workflow. This example listens for keywords in conversations and responds when a trigger message is detected.
Explore the image_prediction.xircuits
workflow. In this example, the bot watches for attached images in conversations and responds with the predicted class when a trigger message is detected.
Take a look at the slack_openai.xircuits
workflow. This example leverages components from the OpenAI Component Library. The bot enables each Slack thread to have unique and contextual image creation and editing using the OpenAI models.
These examples are designed to help you understand how to use the xai-slack component library effectively in your Slack workspace. Enjoy creating and customizing your components!
To use this component library, ensure that you have an existing Xircuits setup. You can then install the Slack library using the component library interface, or through the CLI using:
xircuits install slack
You can also do it manually by cloning and installing it.
# base Xircuits directory
git clone https://github.com/XpressAI/xai-slack xai_components/xai_slack
pip install -r xai_components/xai_slack/requirements.txt
- Go to the Slack API page and click "Create New App."
- Choose "From scratch" and provide a name for your app (e.g., "Xai-Slack Bot").
- Select the workspace where you want the app to be developed.
- Click "Create App."
-
Navigate to the OAuth & Permissions on the left sidebar and scroll down to the Bot Token Scopes section. Click Add an OAuth Scope.
-
add the following scopes to your app:
app_mentions:read
(To read app mentions)channels:history
(To read messages in public channels)groups:history
(To read messages in private groups)files:read
(To read file information)chat:write
(To send messages in channels)- Note: this scopes are to enable all the components. For selective components usage you can check the required scopes and events subscriptions stated each component documentation.
-
Scroll up to the top of the OAuth & Permissions page and click Install App to Workspace. You’ll be led through Slack’s OAuth UI, where you should allow your app to be installed to your development workspace.
-
Once you authorize the installation, you’ll land on the OAuth & Permissions page and see a Bot User OAuth Access Token save the generated
xoxb-
token to be used asSLACK_BOT_TOKEN
later. -
Then head over to Basic Information and scroll down under the App Token section and click Generate Token and Scopes to generate an app-level token. Add the
connections:write
scope to this token and save the generatedxapp
token to be used asSLACK_APP_TOKEN
later. -
Navigate to Socket Mode on the left side menu and toggle to enable.
-
In your Slack app settings, navigate to "Event Subscriptions" on the left side menu and toggle to enable, scroll down and click Subscribe to bot events.
-
subscribe your app to the following events:
app_mention
file_shared
message.channels
message.im
- Note: this Subscriptions are to enable all the components. For selective components usage you can check the required scopes and events subscriptions stated each component documentation.
-
Create a
.env
file and add bothSLACK_APP_TOKEN
andSLACK_BOT_TOKEN
, or you can provide these values directly to the components later on.
- Log in to your Slack workspace using the web, desktop, or mobile app.
- Invite the bot to a channel by sending /invite @YourBotName (replace "YourBotName" with the actual name of your bot) as a message in the channel.
Now that your Slack app is set up and configured, you can begin using the xai-slack component library to build custom components for your workspace. Please follow the documentation and examples provided in the library to learn how to create, customize, and manage Slack components using xai-slack.