Back to Openviking

Channels, Gateway, and Operations

bot/docs/en/concepts/03-channels-and-gateway.md

0.4.105.9 KB
Original Source

Channels, Gateway, and Operations

Channels adapt different chat platforms into unified messages. The Gateway assembles Channels, AgentLoop, HTTP APIs, scheduled tasks, and observability into a long-running service.

Supported Channels

TypeConnectionMain capabilities
feishuFeishu events/long connectionDMs, groups, topics, mention rules, media
slackSocket ModeDM and group policies
telegramBot APIText, media, and audio transcription
discordGatewayText and media
whatsappNode.js WebSocket bridgeWhatsApp message forwarding
dingtalkStream SDKMessage ingestion and replies
qqQQ Bot APIMessage ingestion and replies
emailIMAP + SMTPInbox polling and automatic replies
mochatSocket.IO / Watch APISession watching, mentions, and delayed replies
openapi / bot_apiFastAPIHTTP Chat API and SSE

Interactive CLI sessions use ChatChannel, while one-shot commands use SingleTurnChannel. Both use the same unified message model.

Channel Responsibilities

BaseChannel and platform-specific implementations jointly handle:

  1. starting and stopping connections and reporting runtime status;
  2. enforcing sender policies such as allow_from;
  3. extracting text, images, attachments, and reply metadata;
  4. building SessionKey and InboundMessage;
  5. converting OutboundMessage into a platform-native reply;
  6. displaying processing state or reactions when supported by the platform.

Platform differences remain inside individual Channels, so AgentLoop does not depend on Feishu, Slack, or other platform SDKs.

ChannelManager creates every enabled instance from bot.channels and distinguishes multiple Bots of the same type using type__channel_id. It consumes the MessageBus outbound queue and routes replies back to the originating channel using SessionKey.

Gateway Runtime

vikingbot gateway starts the following components in one asyncio process:

text
FastAPI / Uvicorn
  + OpenAPIChannel
  + Configured chat Channels
  + MessageBus
  + AgentLoop
  + CronService
  + HeartbeatService

The default listen address is 127.0.0.1:18790. If gateway.host is not localhost, bot.gateway.token is required or the Gateway refuses to start.

Bot HTTP API

The Bot API is available under /bot/v1:

MethodPathPurpose
GET/bot/v1/healthBot health status
POST/bot/v1/chatSynchronous chat
POST/bot/v1/chat/streamSSE streaming chat
POST/bot/v1/chat/channelCall a specific Bot Channel
POST/bot/v1/chat/channel/streamStream a call to a specific Bot Channel
POST/bot/v1/feedbackSubmit user feedback
GET/POST/bot/v1/sessionsList or create API Sessions
GET/DELETE/bot/v1/sessions/{id}Retrieve or delete an API Session

ChatRequest supports a session ID, additional context, reply control, request-level disabled tools, and a channel ID. ChatResponse returns a response ID, final text, intermediate events, relevant memories, and token usage.

SSE emits reasoning, content delta, tool call, tool result, iteration, and final response events.

OpenViking API Proxy

When an OpenViking Server is configured, the Gateway also provides:

PathPurpose
/healthAggregate Gateway and OpenViking upstream status
/api/v1/{path}Proxy OpenViking APIs

The proxy removes hop-by-hop headers, forwards validated identity headers, and preserves the upstream response status. See OpenViking Integration for the complete connection and identity flow.

Access Control

The Gateway enforces several security boundaries:

  1. non-local listeners require X-Gateway-Token;
  2. loopback requests may use the local development boundary;
  3. an OpenViking API Key is checked through upstream /health to validate identity and the effective auth mode;
  4. only a trusted OpenViking Server proxy may supply openviking_connection;
  5. API Sessions are isolated by combining the authenticated principal scope with the external session ID.

Ordinary request fields such as user_id, account ID, or connection data cannot prove an OpenViking identity by themselves.

Feedback and Outcome Evaluation

Every final reply receives a response_id. Clients may submit thumbs up, thumbs down, or a numeric rating, along with an optional reason and text. The Gateway stores the feedback, calculates feedback delay, and emits a feedback_submitted event.

When the user continues the conversation, Outcome Evaluator can infer whether the previous reply succeeded from subsequent behavior and emit a response_outcome_evaluated event. vikingbot feedback-stats aggregates local Sessions to report feedback coverage, ratings, outcome status, tool usage, and latency.

Langfuse and Logging

With bot.langfuse.enabled=true, model calls, token usage, latency, tool events, and outcome metadata are sent to Langfuse. A Langfuse initialization failure does not block the main Bot flow.

Runtime logs use Loguru. Gateway's --verbose flag enables more detailed logs. Analytics-only events are separated from normal replies and are not accidentally sent to chat platforms.

Implementation Locations

AreaPath
Channel base and managementvikingbot/channels/base.py, manager.py
Platform adaptersvikingbot/channels/*.py
Gateway/OpenAPIvikingbot/channels/openapi.py
API modelsvikingbot/channels/openapi_models.py
Runtime assemblyvikingbot/cli/commands.py
Feedback and outcomesvikingbot/observability/
Langfusevikingbot/integrations/langfuse.py