Files
ARTEX/db/migrations/0015_chat_bridges.sql
T
shivandkrad b6ec42f15a fix(chatbridge): address review notes on the bridge core
- Require https for base_url. The bot token travels in the URL path and
  the responses are the updates the bridge acts on, so plain http is
  accepted only with ARTEX_NOTIFY_ALLOW_LOCAL=1, for a local test server.
- Cut replies by UTF-16 code units, which is how Telegram counts its 4096
  limit, so emoji-heavy text is no longer rejected. A cut never splits a
  character.
- Cap a server-sent retry_after at the backoff ceiling (1 minute).
- Pause one second after an empty poll, so a self-hosted Bot API that
  ignores the long-poll timeout cannot spin the loop.
- When the refused-chat memory is full, start over instead of muting
  every new chat, which also muted the operator's own chat. Saving the
  configuration of the same bot keeps the memory.
- Fix two stale comments that said an empty allowlist keeps the bridge
  off (migration 0015 is unreleased, so editing its comment is safe).

Co-authored-by: krad <222954346+dar1k0@users.noreply.github.com>
2026-11-26 22:24:28 +05:30

27 lines
1.3 KiB
SQL

-- Inbound chat bridges (issue #5): an operator drives ARTEX from a chat app.
-- One row per transport kind ('telegram' first). Global configuration: not
-- part of a task archive.
--
-- config is sealed at rest by db/secrets.go (it holds the bot token) and
-- masked in API responses. allowed_chats is the allowlist of chat ids, a JSON
-- array of strings. Only listed chats are served; an empty list serves none
-- and only tells each chat its ID. poll_offset is the transport's update
-- cursor, committed before an update is acted on so a restart never replays
-- a command.
--
-- config_version grows on every save. The poller writes its cursor only for
-- the version it read, so a cursor of the old bot can never land on a row
-- whose token was just replaced. updated_at is the time of the last save,
-- set by SaveChatBridge rather than a trigger, so cursor writes leave it alone.
CREATE TABLE IF NOT EXISTS chat_bridges (
id BIGSERIAL PRIMARY KEY,
kind TEXT NOT NULL UNIQUE,
enabled BOOLEAN NOT NULL DEFAULT false,
config JSONB NOT NULL DEFAULT '{}'::jsonb,
allowed_chats JSONB NOT NULL DEFAULT '[]'::jsonb,
poll_offset BIGINT NOT NULL DEFAULT 0,
config_version BIGINT NOT NULL DEFAULT 1,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);