Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ name, if set, is the default the page shows and the value a reset returns to.
| Model retries | `model_retry_max_attempts` (3), `model_retry_base_delay` (2.0), `model_retry_backoff_cap` (60.0) | Retries a model call that failed with a transient upstream provider error (rate limit, 5xx, timeout, "model stopped before completing"); 0 or 1 attempts disables retries. Delays double from the base with jitter up to the cap. Auth/permission/invalid-request errors fail immediately. |
| Model retries | `model_call_timeout` (120) | Seconds one model call may take, including gaps between streamed chunks, before it fails as a transient error and is retried. The provider SDKs' own silent retries are off, so a dead upstream costs at most `model_retry_max_attempts` × this. 0 means no limit. |
| Telegram | `telegram_bot_token`, `telegram_webhook_url`, `telegram_webhook_secret` | Telegram Bot API token (secret: encrypted at rest, masked in API), public webhook URL for receiving updates, and shared secret for `X-Telegram-Bot-Api-Secret-Token` header validation. Token overrides the `TELEGRAM_BOT_TOKEN` env var when set via the UI. |
| Discord | `discord_bot_token` | Discord bot token (secret: encrypted at rest, masked in API). The bot connects over the Discord Gateway websocket (no public URL needed); enable the Message Content intent on the bot and invite it with the `bot` scope. DMs map to threads like Telegram's; `/new`, `/start`, `/help` work. Overrides the `DISCORD_BOT_TOKEN` env var when set via the UI. |
| Slack | `slack_bot_token`, `slack_app_token`, `slack_signing_secret`, `slack_transport` | Slack bot token (`xoxb-…`, secret) posts and reads DMs; the app-level token (`xapp-…` with `connections:write`) opens Socket Mode, the default transport (no public URL needed). `socket_mode` or `webhook`: webhook mode instead validates Slack request signatures with `slack_signing_secret` at `/api/v1/channels/slack/events`. Create a Slack app with Socket Mode on, bot scopes `chat:write`, `im:history`, `im:read`, and the `message.im` event. DMs map to threads like Telegram's; `/new`, `/start`, `/help` work. |

</details>

Expand Down Expand Up @@ -763,9 +765,10 @@ outbound delivery to external actors), Docker sandboxing for tools, chat platfor
(Slack/Discord/etc.), and multi-node deployment. The actor system, the LangGraph store, and the
tool registry are designed as the seams for adding these later.

Docker sandboxing for tools ([#145](https://github.com/regnull/openbot/issues/145)) and a
Slack/Discord adapter ([#146](https://github.com/regnull/openbot/issues/146)) are open for
contributors.
Telegram, Discord and Slack DM adapters ship today (see "Configuration"). Docker sandboxing for
tools ([#145](https://github.com/regnull/openbot/issues/145)) remains open for contributors; group
channels, threads-as-conversations, and approval cards on chat platforms are the natural next steps
for the channel adapters.

## Contributing

Expand Down
29 changes: 29 additions & 0 deletions backend/openbot/api/discord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Discord channel status endpoint.

OpenBot connects to Discord through the gateway websocket (channels/discord.py),
so there is no inbound webhook to mount; this router only exposes status for
health checks and the settings page.
"""
from __future__ import annotations

import logging

from fastapi import APIRouter, Depends

from openbot.api.deps import get_services
from openbot.services import Services

log = logging.getLogger(__name__)

router = APIRouter(prefix="/channels/discord", tags=["discord"])


@router.get("/status")
async def discord_status(services: Services = Depends(get_services)):
"""Get Discord channel status."""
return {
"configured": services.settings.discord_bot_token is not None,
"transport": "gateway",
"gateway_running": getattr(services, "_discord_gateway", None) is not None
and getattr(services._discord_gateway, "_running", False),
}
93 changes: 93 additions & 0 deletions backend/openbot/api/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""Slack channel Events API endpoint (webhook transport).

Socket Mode (the default transport) needs no endpoint at all; this webhook is
for deployments that prefer Slack's Events API. Bot responses are delivered
asynchronously via the SlackDeliveryListener either way.
"""
from __future__ import annotations

import json
import logging

from fastapi import APIRouter, Depends, HTTPException, Request, Response

from openbot.api.deps import get_services
from openbot.channels.slack import (
deliver_to_slack,
parse_slack_event,
process_slack_message,
validate_slack_signature,
)
from openbot.services import Services

log = logging.getLogger(__name__)

router = APIRouter(prefix="/channels/slack", tags=["slack"])


@router.post("/events")
async def slack_events(request: Request, services: Services = Depends(get_services)):
"""Handle incoming Slack Events API payloads.

Flow:
1. Validate the Slack request signature (if a signing secret is configured).
2. Answer url_verification challenges.
3. For commands (/new, /start, /help): process synchronously and post the
response immediately.
4. For regular messages: post to the thread and return 200. The bot response
is generated asynchronously and delivered by SlackDeliveryListener.
"""
body = await request.body()
secret = services.settings.slack_signing_secret
if secret:
signature = request.headers.get("X-Slack-Signature", "")
timestamp = request.headers.get("X-Slack-Request-Timestamp", "")
if not validate_slack_signature(secret, timestamp, body, signature):
raise HTTPException(403, "Invalid Slack request signature")

try:
payload = json.loads(body)
except (ValueError, UnicodeDecodeError):
raise HTTPException(400, "Invalid JSON")

if payload.get("type") == "url_verification":
return {"challenge": payload.get("challenge", "")}

# Slack retries unacknowledged events; app-level dedup is out of scope for v1.
if payload.get("type") != "event_callback":
return Response(status_code=200)

event = parse_slack_event(payload.get("event") or {})
if event is None:
return Response(status_code=200)
# Only the original post starts a run (see channels/slack.py): an edited or
# replied-to message is re-announced with ts != event_ts.
raw = payload.get("event") or {}
if raw.get("ts") != raw.get("event_ts"):
return Response(status_code=200)

session_factory = services.session_factory

# Process the event — returns a response text for commands, None for messages
async with session_factory() as session:
response_text = await process_slack_message(services, session, event)
await session.commit()

# Commands produce an immediate response; regular messages have None here
if response_text and event.channel_id:
await deliver_to_slack(services, event.channel_id, response_text)

return Response(status_code=200)


@router.get("/status")
async def slack_status(services: Services = Depends(get_services)):
"""Get Slack channel status."""
return {
"configured": services.settings.slack_bot_token is not None,
"transport": services.settings.slack_transport,
"socket_mode": services.settings.slack_app_token is not None,
"signing_secret": services.settings.slack_signing_secret is not None,
"socket_running": getattr(services, "_slack_socket", None) is not None
and getattr(services._slack_socket, "_running", False),
}
Loading