Documentation Index
Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
Use this file to discover all available pages before exploring further.
Build a Slack bot with tools, memory, and slash commands.
Create the Slack app
- Go to api.slack.com/apps and click Create New App
- Enable Socket Mode and generate an App-Level Token (
xapp-)
- Add bot scopes:
chat:write, app_mentions:read, channels:history, im:history
- Subscribe to events:
message.im, app_mention
- Install the app and copy the Bot Token (
xoxb-)
Create the agent
import asyncio
import os
from definable.agent import Agent
from definable.agent.interface import SlackInterface
from definable.memory import Memory, SQLiteStore
from definable.tool.decorator import tool
@tool
def search_docs(query: str) -> str:
"""Search documentation for an answer."""
return f"Found results for: {query}"
agent = Agent(
model="gpt-4o",
instructions="You are a helpful Slack assistant.",
tools=[search_docs],
memory=Memory(store=SQLiteStore("./slack_memory.db")),
)
interface = SlackInterface(
agent=agent,
bot_token=os.environ["SLACK_BOT_TOKEN"],
app_token=os.environ["SLACK_APP_TOKEN"],
slash_commands={
"/ask": "Ask the AI assistant a question",
},
done_reaction="white_check_mark",
)
asyncio.run(interface.serve_forever())
Install dependencies
pip install 'definable[slack]'
Set environment variables
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_APP_TOKEN="xapp-..."
export OPENAI_API_KEY="sk-..."
Run
Mention the bot in a channel or send a DM. Use /ask for slash commands.
Production Deployment
Switch to HTTP Events API mode for production:
interface = SlackInterface(
agent=agent,
bot_token=os.environ["SLACK_BOT_TOKEN"],
signing_secret=os.environ["SLACK_SIGNING_SECRET"],
mode="http",
)
See Slack reference for all configuration options including Block Kit interactions, modals, and shortcuts.