Documentation
¶
Overview ¶
Package gateway connects Antares to messaging platforms. Every platform shares the same session store, memory, and tool surface.
Index ¶
- Constants
- func BindingAdmits(b *config.Binding, isDirect bool, userID string, roles []string) bool
- func ClearDiscordCommands(ctx context.Context, token, appID string) error
- func ClearTelegramCommands(ctx context.Context, token string) error
- func GatewaySessionKey(cfg *config.Config, msg InboundMessage) string
- func HasBindings(bindings []config.Binding, platform string) bool
- func RegisterDiscordCommands(ctx context.Context, token, appID string) error
- func ResolveBinding(bindings []config.Binding, platform, guildID, channelID string) *config.Binding
- func SetTelegramCommands(ctx context.Context, token string) error
- type Adapter
- type Discord
- type DiscordChannel
- type DiscordGuild
- type DiscordRole
- type Feishu
- type Handler
- type Identity
- type InboundMessage
- type Manager
- func (m *Manager) Deliver(ctx context.Context, target, text string) error
- func (m *Manager) Reconcile(cfg *config.Config) error
- func (m *Manager) SetConfig(cfg *config.Config)
- func (m *Manager) Start(ctx context.Context)
- func (m *Manager) Status() map[string]bool
- func (m *Manager) Stop(name string)
- func (m *Manager) StopAll()
- func (m *Manager) Sync(platform string) error
- type Matrix
- type Reply
- type Signal
- type Slack
- type Telegram
- type WhatsApp
Constants ¶
const DefaultIntents = (1 << 9) | (1 << 15) | (1 << 12)
DefaultIntents covers guild messages, message content, and direct messages.
Variables ¶
This section is empty.
Functions ¶
func BindingAdmits ¶
BindingAdmits reports whether a binding admits a sender, combining its per-user and per-role allow lists:
- both lists empty → admit (the binding sets no per-sender limit).
- user in AllowedUsers → admit (an explicit user always wins).
- a guild message whose sender holds a role in AllowedRoles → admit.
- otherwise → deny.
Roles only apply to guild (non-direct) messages; a DM has no server roles, so in a DM only the user list is consulted. This means a DM restricted purely by role (roles set, user list empty) admits the paired owner rather than locking them out.
func ClearDiscordCommands ¶
ClearDiscordCommands removes every registered global slash command.
func ClearTelegramCommands ¶
ClearTelegramCommands empties the command menu via deleteMyCommands.
func GatewaySessionKey ¶ added in v0.4.0
func GatewaySessionKey(cfg *config.Config, msg InboundMessage) string
GatewaySessionKey maps an inbound message to the KV key that holds its persistent session id. In a group channel with group_sessions_per_user set (the default), the sender's user id is folded in so each person gets their own conversation rather than sharing one channel-wide thread; a DM is already 1:1 so its key stays per-channel. Every place that reads, writes, or clears a gateway session must use this so a per-user session and its /new both target the same key.
func HasBindings ¶
HasBindings reports whether a platform has any binding configured at all (enabled or not). When true and ResolveBinding returns nil for a GROUP channel, the channel is unregistered and the bot should stay silent. Direct messages are never gated this way — the caller lets DMs through regardless.
func RegisterDiscordCommands ¶
RegisterDiscordCommands publishes the gateway command set as global slash commands. Global commands can take up to an hour to propagate on Discord's side the first time; re-registering the same set is cheap and idempotent.
func ResolveBinding ¶
ResolveBinding picks the most specific enabled binding for a message on a platform, given its guild (server) and channel ids. Specificity order:
guild + channel > channel only > guild only > platform only
It returns nil when no binding matches. A nil result from a platform that has NO bindings at all means "use the default agent"; a nil result from a platform that DOES have bindings means "ignore this channel" — the caller distinguishes the two with HasBindings.
Types ¶
type Adapter ¶
type Adapter interface {
Name() string
// Start blocks until ctx is cancelled or the connection fails fatally.
Start(ctx context.Context) error
// Send delivers a message; it returns the platform message id.
Send(ctx context.Context, r Reply) (string, error)
// Connected reports the live connection state for the dashboard.
Connected() bool
}
Adapter is one platform connection.
type Discord ¶
type Discord struct {
// contains filtered or unexported fields
}
Discord connects to the bot gateway over WebSocket and replies over REST.
func NewDiscord ¶
NewDiscord builds the Discord adapter.
type DiscordChannel ¶
type DiscordChannel struct {
ID string `json:"id"`
Name string `json:"name"`
Type int `json:"type"`
ParentID string `json:"parent_id,omitempty"`
}
DiscordChannel is a channel within a guild. Type 0 is a text channel, 5 an announcement channel — the ones a bot can post to and worth binding.
func ListDiscordChannels ¶
func ListDiscordChannels(ctx context.Context, token, guildID string) ([]DiscordChannel, error)
ListDiscordChannels returns the text and announcement channels of a guild.
type DiscordGuild ¶
type DiscordGuild struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
}
DiscordGuild is a server the bot belongs to.
func ListDiscordGuilds ¶
func ListDiscordGuilds(ctx context.Context, token string) ([]DiscordGuild, error)
ListDiscordGuilds returns the servers the bot is a member of.
type DiscordRole ¶
DiscordRole is a server role the bot can gate access by.
func ListDiscordRoles ¶
func ListDiscordRoles(ctx context.Context, token, guildID string) ([]DiscordRole, error)
ListDiscordRoles returns a guild's roles (excluding @everyone), so the UI can offer them as an access allow-list.
type Feishu ¶
type Feishu struct {
// contains filtered or unexported fields
}
Feishu (Lark) receives events by webhook and sends with a tenant token. The adapter runs its own listener and refreshes the tenant token as needed. It handles plaintext (unencrypted) event delivery.
type Handler ¶
Handler processes an inbound message and streams partial replies. The returned string is the final text.
type Identity ¶
Identity is what a platform reports about the bot behind a token.
func VerifyToken ¶
VerifyToken asks the platform whether a bot token is real before Antares stores it. Saving an unverified token means the failure surfaces later, in a background reconnect loop, where nobody is watching.
type InboundMessage ¶
type InboundMessage struct {
Platform string
ChannelID string
// GuildID is the server a channel belongs to (Discord). Empty for platforms
// without a server concept (Telegram) and for direct messages.
GuildID string
UserID string
UserName string
// DisplayName is the friendliest name for the sender — a Discord server
// nickname, else the account display name, else the username. Empty falls
// back to UserName. Shown to the agent so it can address the person.
DisplayName string
// Roles are the sender's server-role ids (Discord guild members). Used to
// gate a server binding by role. Empty in DMs and on platforms without roles.
Roles []string
Text string
// IsDirect marks a 1:1 chat, where the agent replies without being addressed.
IsDirect bool
// MessageID lets adapters edit their own reply while streaming.
MessageID string
}
InboundMessage is one message received from a platform.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager supervises the enabled adapters.
func NewManager ¶
NewManager builds a gateway manager.
func (*Manager) Reconcile ¶ added in v0.4.0
Reconcile publishes the new configuration and restarts only the adapters whose per-platform settings (or the master Gateway.Enabled switch) actually changed since the last successful apply. Untouched settings like bindings just take effect on the next message because the inbound handler re-reads the live config.
The diff is against applied-state, not the previously published config, so a retry after a stubborn stop still sees the platform as dirty rather than silently agreeing with the freshly-published pointer. If some platforms fail to reconcile within the bounded stop wait, Reconcile returns their combined error and leaves them tracked for the next attempt; the platforms that did reconcile stay reconciled.
A nil baseCtx means Start has not been called yet: publish the config and let a later Start pick it up. Returning an error here would leave the dashboard reporting a failed save for a manager that simply is not up yet.
func (*Manager) SetConfig ¶
SetConfig swaps in a reloaded configuration. Reload replaces the whole config pointer, so without this the manager would keep reading the values it was built with and Sync would reconcile against a stale file. It is kept as a plain setter for callers that only need the pointer refreshed; Reconcile is the entry point that also brings running adapters into line.
func (*Manager) Stop ¶
Stop shuts down one platform. Held under opMu so a manual Stop cannot race a concurrent Reconcile or Sync onto the same slot. After a successful Stop the platform is treated as unapplied, so the next Reconcile against a config that wants it live will restart it — a manual Stop is a temporary override, not a permanent disable.
func (*Manager) StopAll ¶
func (m *Manager) StopAll()
StopAll shuts down every platform. Fully resets the applied bookkeeping, so a subsequent Start or Reconcile treats every platform as freshly unconfigured.
func (*Manager) Sync ¶
Sync brings one platform in line with the current configuration: it stops a running adapter and starts a fresh one when the platform should be live. Without this, saving a token or flipping a switch in the dashboard only took effect after restarting the process, which is a poor thing to ask of someone who just pasted a token. Sync serializes with Reconcile and StopAll through opMu so two lifecycle ops cannot both try to install a replacement into the same slot.
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
Matrix connects to a homeserver with an access token and long-polls /sync. Replies are sent with PUT .../send. It needs no public URL.
type Reply ¶
type Reply struct {
ChannelID string
Text string
// ReplyTo threads the response onto the triggering message when supported.
ReplyTo string
// EditID updates a previously sent message instead of posting a new one.
EditID string
}
Reply is what an adapter sends back.
type Signal ¶
type Signal struct {
// contains filtered or unexported fields
}
Signal talks to a signal-cli REST API daemon that the user runs. It polls the receive endpoint and posts to send, so it needs no public URL of its own.
type Slack ¶
type Slack struct {
// contains filtered or unexported fields
}
Slack connects over Socket Mode — an outbound WebSocket opened with an app-level token — so it needs no public URL. Replies go over the Web API with the bot token.
type Telegram ¶
type Telegram struct {
// contains filtered or unexported fields
}
Telegram talks to the Bot API over long polling, so no public domain or webhook is required — it works behind a home NAT.
func NewTelegram ¶
NewTelegram builds the Telegram adapter.
type WhatsApp ¶
type WhatsApp struct {
// contains filtered or unexported fields
}
WhatsApp uses the Meta Cloud API. Inbound messages arrive by webhook, so the adapter runs its own HTTP listener; outbound goes to the Graph API. The user points Meta's webhook at this listener (directly or through a reverse proxy).
func NewWhatsApp ¶
NewWhatsApp builds the WhatsApp adapter.