Connect Slack
Connect a Slack workspace and your agent can read channels and post messages there. You talk to the agent in Custodian (the chat link, the Flow Builder or the SDK), and it uses Slack as a tool:
You: "Summarize today's messages in #support and post the summary to #team-leads."
Agent: reads #support → writes the summary → posts it to #team-leads
| Tool | What it does |
|---|---|
slack_list_channels | Lists the channels the bot can see. |
slack_read | Reads recent messages in a channel, or the replies in a thread. |
slack_send | Posts a message to a channel. |
slack_reply | Replies in a thread. |
slack is shorthand for all four. Messages appear in Slack as your bot, not as you.
The agent works from Custodian to Slack. It doesn't reply when people @mention or DM the bot inside Slack.
1. Create a Slack app
You need your own Slack app in the workspace. It takes about five minutes.
- Go to api.slack.com/apps and click Create New App.
- Choose Paste a manifest (not a template), and pick your workspace.
- Choose JSON, replace everything in the editor with the manifest below, then click Next → Create.
{
"display_information": { "name": "Custodian Bot" },
"features": {
"bot_user": { "display_name": "Custodian Bot", "always_online": false }
},
"oauth_config": {
"scopes": {
"bot": ["channels:read", "channels:history", "chat:write", "groups:read", "groups:history"]
}
},
"settings": {
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}
You can change the name. Keep token_rotation_enabled set to false: with rotation on,
Slack's tokens expire after 12 hours and the agent stops working.
| Scope | Lets the agent |
|---|---|
channels:read | List public channels. |
channels:history | Read messages in public channels. |
chat:write | Post messages and thread replies. |
groups:read, groups:history | Do the same in private channels. Optional: remove them if the agent should only see public channels. |
2. Install it and copy the bot token
- In your app's settings, open OAuth & Permissions and click Install to Workspace, then Allow.
- Copy the Bot User OAuth Token. It starts with
xoxb-.
Use the bot token, not a user token (xoxp-) or an app-level token (xapp-). Custodian
rejects anything that doesn't start with xoxb-.
3. Invite the bot to your channels
The bot can only read and post in channels it has joined. In each channel the agent should use, either:
- type
/invite @Custodian Bot, or - click the channel name → Agents & apps (or Integrations) → Add apps.
4. Find a channel ID (optional)
You can set a default channel that the agent uses when you don't name one. It must be
a channel ID, not a name: click the channel name, and the ID is at the bottom of the
About tab. It looks like C0123ABCD.
Don't use the App ID from your app's settings page. It starts with A, and channel
IDs start with C.
5. Connect it in Custodian
- Dashboard
- Python
- TypeScript
- In the Flow Builder, drag Slack onto an agent.
- Open the agent's settings, paste the bot token, and optionally the default channel ID.
- Click Connect Slack. Custodian checks the token with Slack and shows Connected to your workspace.
- Deploy.
Put the token in your .env (or export it):
CUSTODIAN_SLACK_BOT_TOKEN=xoxb-...
CUSTODIAN_SLACK_DEFAULT_CHANNEL=C0123ABCD # optional
from custodian_labs import Custodian
agent = Custodian(
name="Slack Assistant",
model="gpt-6-luna",
system_prompt=(
"You help my team on Slack. Summarize channels clearly. "
"Show me a draft and wait for my OK before posting."
),
)
agent.with_slack_credential() # or with_slack_credential("xoxb-...", "C0123ABCD")
agent.with_slack_tools() # adds slack_list_channels, slack_read, slack_send, slack_reply
app = agent.deploy(share_mode="private")
print(app.chat("Summarize today's messages in #support.").response)
import { Custodian } from "@custodianlabs/sdk";
const agent = new Custodian({
model: "gpt-6-luna",
systemPrompt: "You help my team on Slack. Show me a draft and wait for my OK before posting.",
})
.withSlackCredential() // reads CUSTODIAN_SLACK_BOT_TOKEN / CUSTODIAN_SLACK_DEFAULT_CHANNEL
.withSlackTools();
const app = await agent.deploy({ shareMode: "private" });
const reply = await app.chat("Summarize today's messages in #support.");
console.log(reply?.response);
In browsers and edge runtimes there are no environment variables, so pass the values
directly: withSlackCredential({ botToken: "xoxb-...", defaultChannelId: "C0123ABCD" }).
In a squad, connect Slack only on the agent that needs it.
Keep it safe
- The token is stored encrypted and never returned by the API. Only a masked form such
as
xoxb-…1a2bis shown. - Exported flows never include the token. Reconnect Slack after importing a flow.
- Deploy with
privateorpasswordsharing. With apubliclink, anyone who has it can ask the agent to read or post in your workspace. - Ask for a draft before posting. Put it in the system prompt, as in the examples above.
- Keep the token out of code and git. Use an environment variable or the dashboard.
- If a token leaks, revoke it in your app's OAuth & Permissions page and reinstall the app to get a new one.
Troubleshooting
When something goes wrong, the agent tells you what to fix. Common messages:
| Message | What to do |
|---|---|
| The Slack bot token is invalid | Copy the Bot User OAuth Token again. If you reinstalled the app, the token may have changed. |
| The Slack bot is not a member of this channel | Invite the bot to the channel (step 3). |
The Slack app is missing the <scope> scope | Add the scope under OAuth & Permissions, then click Reinstall to Workspace. |
| Channel not found | Check the spelling, or use the channel ID. The bot must be able to see the channel. |
| No channel given and no default channel is configured | Name a channel in your message, or set a default channel ID (step 4). |
| Slack rate limit reached | Wait the number of seconds shown and try again. |
| Slack is not connected for this custodian | Connect Slack on this agent (step 5). |
| Private channels aren't listed | Add groups:read and groups:history, reinstall, and invite the bot to the private channel. |
See also: Built-in tools · Custodians & Tools