Applies #642 commit 2 (migration 0019 chat_bridge_approvals, SHA-256 one-time nonce buttons, atomic UseChatBridgeApproval, group filtering) and quotes ChatType and UserName in refusal logs to prevent log injection. Co-authored-by: shiv <shivkumarbammidi@gmail.com> Co-authored-by: krad <222954346+dar1k0@users.noreply.github.com>
9.6 KiB
Chat Bot (Inbound Chat Bridge)
The chat bot lets an operator talk to ARTEX from a chat app instead of the web UI. Telegram is the first transport. This page covers connecting a bot, who may use it, the task commands, the main-agent conversation and remote approvals (issue #5).
Outbound notifications (pushing findings to a chat) are a separate feature under System → Notifications and keep working without the bot.
Setup
- Create a bot with @BotFather and copy its token. Give ARTEX a bot of its own: Telegram allows one consumer per token, so a token already used by another poller or by a webhook fails with a conflict error.
- Open System → Chat bot, paste the token, switch the bot on and save. Test connection asks Telegram which bot the token belongs to; it sends no message. The status card shows Online and the bot's username once it is polling.
- With the allowlist still empty the bot serves no chat. From each chat you want to use (a private chat or a group), send the bot any message: it answers once with a refusal that names the chat ID.
- Add those chat IDs to Allowed chat IDs and save. The change applies at once.
- For a group, also add the user ID of each person who may give the bot commands to Allowed user IDs. A member who is not listed gets a refusal naming their user ID. The list belongs to the bot, not to one group: a listed user can use the bot in every allowed group.
- Send
/helpto see the commands./whoamishows the chat ID and your user ID. - Send
/tasks, then/task <id>to pick the task this chat works on.
Commands
| Command | What it does |
|---|---|
/tasks |
The ten most recent tasks (pinned first) with status and finding counts |
/task <id> |
Select the task this chat works on. Without an id, show the selected task |
/pause [id] |
Pause the task, as the pause button in the web UI does |
/resume [id] |
Resume the task. It may be queued if the concurrency limit is reached |
/findings [id] |
Finding counts and the ten most severe findings: title, severity and status |
/whoami |
The chat ID and your user ID |
/help |
The command list |
[id] defaults to the selected task. Each chat keeps its own selection, stored in the database, so
it survives a restart and two chats can work on different tasks. The selection is a convenience,
not a limit: like an administrator in the web UI, an allowed user can name any task, for example
/pause 12.
Any message that is not a command goes to the main agent of the selected task. It is the same conversation as the task's web chat: the message shows up there, the agent works as it would for a web message, and when the turn ends the chat is told that it answered, with a link (see Text excerpts below for relaying the answer itself). While the agent is still answering, a new message is refused; send it again after the answer arrives. Pausing the task stops the turn in progress, and the chat is told so.
Replies link back to ARTEX when Link-back URL is set under System → Notifications.
Approvals
When an interception rule or the target gate asks for a human decision on a task, the request is
sent to every chat that selected the task with /task, with Allow and Block buttons. A
press decides the request exactly as the buttons in ARTEX do, and the approval records name the
chat user as the approver (telegram:<user id>). The message is then edited to show the outcome
and the buttons are removed.
- The message shows the task, the tool, the agent, the target address for a target request and the risk score. The request itself and the rule's reason are free-form, so they are shown only with Send text excerpts on, filtered.
- The buttons work once, only in the chat and on the message they were sent with, and expire after 30 minutes. If the request is decided in ARTEX or elsewhere first, or the buttons expire, the message is edited and the buttons are removed. After that, decide in ARTEX.
- In a group, only allowed users can press; anyone else gets a notice with their user ID. A group with no allowed users gets no approval requests.
- Requests are looked for every few seconds while the bot is on.
Text excerpts
Send text excerpts is off by default. Off, everything the bot sends is fixed wording, titles,
statuses, counts and links: a main-agent answer is announced with a link, and an unnamed task is
listed as (unnamed) rather than by its description. On, the bot also relays the answer and shows
the description of unnamed tasks, filtered as described below. Turn it on only if the chat may
receive what agents write about the target.
Security model
- Only allowlisted chats are served. A chat that is not listed gets one refusal line, naming its chat ID, and is then ignored. The bot remembers up to 1024 refused chats, across saves of the same bot; past that it starts over, so a chat may be refused one more time but a new chat always learns its ID. An empty allowlist serves no chat at all; that is the state a new bot starts in while you collect chat IDs.
- In a group, only allowed users give commands. The sender must also be in Allowed user IDs, and a group with no allowed users serves nobody. A member who is not listed gets one refusal naming their user ID. A private chat is its own user and needs no entry.
- An allowed group is a shared audience. The user list decides who can give commands, not who reads the replies. Every member of an allowed group sees everything the bot sends there (task lists, findings, approval requests), including members added later and, depending on the group's history setting, earlier messages too. Allow a group only if every member may see that.
- Summaries and links only by default. Replies carry task and finding titles, statuses and
counts, never finding evidence or summaries. Free-form text goes out only with Send text
excerpts on, and then through a filter: code is dropped (fenced and indented blocks, where agents
put requests, responses and tool output), the task's stored credentials are masked, and so are
common secret shapes (credentials in URLs, authorization and cookie headers, bearer tokens, JWTs,
well-known API key formats,
curl -u, session cookies andpassword=…-style pairs, quoted values included). The text is cut to 1500 characters, and the full answer stays in ARTEX. A filter cannot know every shape a credential takes, which is why excerpts are opt-in. - One-time approval buttons. Each approval message carries a random nonce in its button data. Only the SHA-256 of the nonce is stored, so reading the database does not give a working button. A press is checked against the chat, the message, the expiry and whether the nonce was used, and the nonce is spent in the same database statement, so a replayed or forwarded press, a second press, or a press racing a decision in ARTEX cannot act twice. Presses go through the same access rules as messages.
- Late answers are re-checked. An answer is dropped if, while the agent worked, the bridge was switched off, the chat was removed from the allowlist or, in a group, the user who asked was removed from the user list.
- No inbound port. The bot uses long polling (
getUpdates) over outbound HTTPS. - The token is a secret. It is encrypted at rest with
keys/secret.keylike other stored secrets, shown masked in the UI and API, and never written to logs or error messages (errors keep only the scheme and host of the API address). Changing the API address requires entering the token again, so a stored token is never sent to a new host. The API address must usehttps: the token travels in the URL path, and the replies are the updates the bot acts on. Plainhttpis accepted only withARTEX_NOTIFY_ALLOW_LOCAL=1, for a local test server. - Same network guard as notifications. Calls refuse loopback and link-local addresses (including
cloud metadata) unless
ARTEX_NOTIFY_ALLOW_LOCAL=1, and never follow a cross-host redirect. - No replays. The update cursor is committed before a batch is acted on, so a crash loses a batch rather than running it twice. Messages older than two minutes when they reach ARTEX (for example a backlog queued while ARTEX was down) are dropped and logged instead of executed.
- Message text is not logged. Logs (tag
[tgbot]) record the chat, the sender and the decision, plus which user paused, resumed or messaged which task.
Configuration changes
Saving the form takes effect immediately, without a restart: a poll in progress is interrupted and the new configuration is read. A new token clears the update cursor, because Telegram update IDs are per bot. A batch fetched under a configuration that was replaced during the poll is dropped.
API
All routes require the administrator JWT.
| Method | Path | Purpose |
|---|---|---|
GET |
/api/chat-bridges |
Every transport with its masked configuration, allowlist and live status |
PUT |
/api/chat-bridges/{kind} |
Save enabled, config, allowed_chats, allowed_users and share_text; omitted fields keep their stored value |
POST |
/api/chat-bridges/{kind}/test |
Check the stored token and return the bot identity |
config follows the notification channel convention: a masked value sent back unchanged keeps the
stored secret, and an empty string clears a field. Telegram's fields are bot_token and the
optional base_url (an https address of a self-hosted Bot API server). The live status.state
is off, connecting, online or error, with last_error when it fails.