Skip to main content

Slack

Host agents as Slack applications
Use the Slack interface to serve Agents via Slack. It mounts webhook routes on a FastAPI app and sends responses back to Slack channels and direct messages.

Setup

Required environment variables:
  • SLACK_SIGNING_SECRET (for request signature validation)
  • SLACK_TOKEN (Bot User OAuth Token, required by SlackTools for sending messages)
  • Optional: SLACK_VERIFICATION_TOKEN

Example Usage

Create an agent, expose it with the SlackInterface interface, and serve via InterfaceManager:
import os
from upsonic import Agent
from upsonic.interfaces import InterfaceManager, SlackInterface

# Create an agent
agent = Agent(
    model="openai/gpt-4o-mini",  # Ensure OPENAI_API_KEY is set
    name="SlackBot"
)

# Create Slack interface
slack = SlackInterface(
    agent=agent,
    reply_to_mentions_only=True,  # Only reply to @mentions and DMs
    name="Slack"
)

# Create and start the interface manager
manager = InterfaceManager(interfaces=[slack])

if __name__ == "__main__":
    manager.serve(host="0.0.0.0", port=8000, reload=False)

Core Components

  • SlackInterface (interface): Wraps an Upsonic Agent for Slack via FastAPI.
  • InterfaceManager.serve: Serves the FastAPI app using Uvicorn.

SlackInterface Interface

Main entry point for Upsonic Slack applications.

Initialization Parameters

ParameterTypeDefaultDescription
agentAgentRequiredUpsonic Agent instance.
signing_secretOptional[str]NoneSlack signing secret (or set SLACK_SIGNING_SECRET).
verification_tokenOptional[str]NoneSlack verification token (or set SLACK_VERIFICATION_TOKEN).
namestr"Slack"Interface name.
reply_to_mentions_onlyboolTrueWhether to only reply to @mentions and DMs.

Key Method

MethodParametersReturn TypeDescription
attach_routesNoneAPIRouterReturns the FastAPI router and attaches endpoints.

Endpoints

Mounted under the /slack prefix:

POST /slack/events

  • Receives Slack events and messages.
  • Validates signature (X-Slack-Signature and X-Slack-Request-Timestamp).
  • Handles URL verification challenge for webhook setup.
  • Processes app_mention and message events via the agent.
  • Sends replies in threads or directly in channels/DMs.
  • Responses: 200 {"status": "ok"} for events, 200 {"challenge": "..."} for URL verification, 400 missing headers, 403 invalid signature, 500 errors.

GET /slack/health

  • Health/status of the interface.