Developing apps with AI features
Slack offers a unique messaging experience for apps using AI features, including a side-by-side window within the Slack client, an app launch point accessible from the top bar in Slack, special loading states, suggested prompts, and app threads. Slack does not provide an LLM; rather, it gives you the tools and interface to best integrate an LLM of your choice for use in Slack.
For details on the end user experience of apps using platform AI features, check out these Help Center articles: Understand AI apps in Slack and Manage app agents and assistants.
Get started with Agentforce in Slack
Ready to start exploring Agentforce with Slack? First things first: you need to set up your orgs and connect them to each other.
Create a Salesforce org
There are a few options for the Salesforce end of setup.
- Current Salesforce customers can create a sandbox. There are several types of sandboxes in Salesforce; here is a guide to understanding them.
- Current or future (SKU holders or free) Salesforce customers can set up a scratch org.
- Set up a Trailhead org that is pre-configured with data and Agentforce. These are shorter-lived orgs.
- Set up a Developer Edition org that is pre-configured with Agentforce.
Create a Slack org
The best way to play around with Agentforce without touching any production environment is to set up a sandbox org.
That is without the need for an additional add-on or SKU! A trial, complimentary, or sandbox workspace or an Enterprise organization all support adding an Agent to Slack or installing an agent without any additional enablement.
To create a Slack developer sandbox, join the program here. The developer program is a quick, self-serve way to spin up a Slack Enterprise org when needed. Provisioning a sandbox may require approval from your production Slack admins (if applicable). While you are using a sandbox workspace, there are some basic sandbox limits to be aware of.
Connect Salesforce and Slack orgs
Follow these instructions to connect your Salesforce and Slack instances. You may also want to review this article to Set up and manage Agentforce in Slack.
Next Steps
➡️ Check out the guide for Customizing Agentforce agents with custom Slack actions to set up your preferred Slack actions.
➡️ Explore Agentforce documentation to learn how to create an agent you can deploy to Slack.
Getting started with AI features in Slack apps
Don't have a paid plan? Join the Developer Program and provision a fully-featured sandbox for free.
Create a Slack app
To set up your app for the AI capabilities discussed above, first create an app, then find the Agents & AI Apps feature in the sidebar, and enable it. You will also want to subscribe to the assistant_thread_started
, assistant_thread_context_changed
, and message.im
events.
App flow
The instructions here show the app flow without the use of the Bolt framework. However, using Bolt for Python or Bolt for JavaScript simplifies listening for and responding to these events.
1. Listen for the assistant_thread_started
event
When the user first opens the container, Slack sends the assistant_thread_started
event along with the context
object. The context
object is shown below:
"context": {
"channel_id": "C123ABC456",
"team_id": "T123ABC456",
"enterprise_id": "E123ABC456"
}
Some applications have no use for the context
object. Perhaps your app does, though! If so, first call the conversations.info
method to see if your app has access to the channel, then proceed from there.
The assistant_thread_context_changed
event is sent when a user opens a new channel while the container is open. This can be used to track the active context of a user in Slack.
2. Respond to the assistant_thread_started
event
A user's first impression is a crucial moment. Capitalizing on this first interaction is an opportunity to create a delightful experience.
Your app can call the assistant.threads.setStatus
method if it needs time to generate prompts.
If your app is sending hardcoded prompts (this can be configured in the app settings), it would skip this step and instead call the assistant.threads.setSuggestedPrompts
method to send one or more suggested prompts.
3. Listen for the message.im
event
The user then will type a message or click on a prompt which triggers a message.im
event. The event is the same whether the user clicked the suggested prompt or typed it manually. Users can message your app via the container or through your app's Chat tab.
Your app can respond to the user directly or it can pass back the thread_ts
parameter to continue in the same thread. In most situations, you will want to call the chat.postMessage
method with the thread_ts
parameter.
When your app receives the thread_ts
parameter, you can retrieve the conversation by using thread_ts
as the unique identifier. This is useful if your app stores the long-lived context or the state of a thread.
You can also fetch previous thread messages using the conversations.replies
method and choose which other messages from the conversation to include in the LLM prompt or your app logic.
Once you receive the response from the LLM, use the chat.startStream
method to start a text stream, the chat.appendStream
method to append it, and the chat.stopStream
method to stop it. These allow the user to see the response from the LLM as a text stream, rather than a single block of text sent all at once. This provides closer alignment with expected behavior from other major LLM tools. The Bolt framework, available for Python and JavaScript, makes this process simpler.
Note: @-mentions in channels can happen like they do today — whether you support this or not is up to you. You can engage with the user or ask them to use the container to converse with your app.
4. Respond to the message.im
event
Your app should then call the assistant.threads.setStatus
method to display the status indicator in the container. We recommend doing so immediately for the user's benefit.
Your app can send a message back to the user via the chat.postMessage
method, automatically clearing the status indicator in the Slack client. The status can also be cleared by again calling the assistant.threads.setStatus
method with an empty string in the status
field.
Additional ways to add AI to your app
AI can be infused in your Slack app with any feature—the world is your oyster. Beyond the side-by-side chat experience, any user input can be used as input for an LLM query, and the answer can be posted back in Slack. Take these three examples:
- Ask an LLM a question that was reacted to with a reacji. Learn how to do this in the Events API documentation
- Initiate asking an LLM a question posed in a message from a message shortcut
- Start off an LLM query with a slash command
- Collect structured data in a modal, then use it in a query to an LLM
Remember to enable the Agents & AI Apps feature toggle to gain access to the assistant:write
scope, which is required for calling assistant-related methods like assistant.threads.setStatus
.
Tips and tricks
Block Kit and interactivity
Provide interactive Block Kit elements, such as drop-down menus and buttons, to allow your app to interact with the user. Block Kit is not required, however; you can forgo interactivity and message the user via plain text and Slack markdown.
When updating longer messages sent to a user, only call the chat.update
method once every 3 seconds with new content, otherwise your calls may hit the rate limit.
You can also set a section block element's expand
property to true
to allow your app to post long messages without the user needing to click 'see more' to see the full text of the message.
Slash commands
Slash commands are not supported in the split view container because all messages in the container or in conversation with the app take place in message threads. Slash commands do not work in threads in general. They do work in messages.
Sending notifications
When your app has the Agents & AI Apps feature toggled on, every DM with the user is a thread.
When sending a notification to a user outside of an existing thread:
- Use the
chat.postMessage
method as normal, but look for thets
parameter in the response. - Call the
assistant.threads.setTitle
method, sending the newts
parameter as thethread_ts
parameter to set the title of the thread. This allows a user to see the new notification with a titled thread when they view the app's DM.
When a user navigates to your app, two tabs are available. The History tab is all of the past threads (in which the user has sent a message) — this is where they will see new notifications. The Chat tab is the last active thread between the user and your app.
Slack has the Activity side rail tab to show new activity in a workspace. This area is optimized for users to quickly see and respond to notifications from your app.
Data retention
Do not store any Slack data you obtain. Instead, store metadata and pull in data in real time if needed.
Members only
Workspace guests are not permitted to access apps with the Agents & AI Apps feature enabled.
Next steps
✨ Get started with an agent template in Bolt for Python or Bolt for JavaScript.
✨ Explore distributed apps using AI in the Slack Marketplace.
✨ Build an AI-fueled Code Assistant app using Bolt for JavaScript with this tutorial.
✨ Make your app the best it can be with our Best practices for AI-enabled apps.