Slack¶
The SlackConnector integrates Machina with Slack using the Bolt SDK in Socket Mode — no public URL or ingress required.
Prerequisites¶
- Create a Slack App at api.slack.com/apps
- Enable Socket Mode in the app settings
- Generate an App-Level Token (
xapp-…) withconnections:writescope - Install the app to your workspace and note the Bot User OAuth Token (
xoxb-…) - Add the following Bot Token Scopes:
chat:write,channels:read,channels:history
Installation¶
Configuration¶
Capabilities¶
| Capability | Method | Description |
|---|---|---|
send_message |
send_message(channel, text) |
Send a message to a channel or DM |
receive_message |
listen(handler) |
Receive messages via Socket Mode |
Usage with Agent¶
from machina import Agent
from machina.connectors import Slack
agent = Agent(
llm="openai:gpt-4o",
connectors=[Slack(bot_token="xoxb-...", app_token="xapp-...")],
)
await agent.start()
Known Limitations¶
- Slash commands and interactive messages (buttons, modals) are not yet exposed as agent tools.
- Thread replies are sent as top-level messages (threading support planned).
- File uploads are not supported yet.
API Reference¶
SlackConnector ¶
SlackConnector(*, bot_token: str = '', app_token: str = '', allowed_channel_ids: list[str] | None = None)
Connector for Slack via the Bolt SDK (Socket Mode).
Receives messages from technicians in Slack channels and sends responses back. Socket Mode uses a WebSocket connection so no public URL or ingress is required — ideal for on-premise plants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bot_token
|
str
|
Slack Bot User OAuth Token ( |
''
|
app_token
|
str
|
Slack App-Level Token ( |
''
|
allowed_channel_ids
|
list[str] | None
|
Optional whitelist of channel IDs that may interact. |
None
|
Example
send_message
async
¶
Send a message to a Slack channel or DM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
Slack channel ID (e.g. |
required |
text
|
str
|
Message text to send. |
required |
Raises:
| Type | Description |
|---|---|
ConnectorError
|
If not connected or the Slack API call fails. |
listen
async
¶
Start listening for incoming Slack messages via Socket Mode.
This is a blocking call that maintains the WebSocket connection until cancelled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
MessageHandler
|
Async callback that receives an :class: |
required |