Skip to content
Merged
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
23 changes: 12 additions & 11 deletions crates/axe-telegram/src/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ const TYPING_REFRESH: Duration = Duration::from_secs(4);
/// `[telegram] thinking_status`: the `sendRichMessageDraft` id of the
/// status line (non-zero; one per chat, so a change of text is animated).
const THINKING_DRAFT: i64 = 1;
/// The status line from an accepted owner message until its run starts.
pub const THINKING_WAKING: &str = "Waking up…";
/// The status line while the woken run is live and has not answered.
pub const THINKING_WORKING: &str = "Working…";
/// The status line (rich HTML) from an accepted owner message until its run
/// starts: a plain loading line, no words (owner msg #6879).
pub const THINKING_WAKING: &str = "…";
/// The status line (rich HTML) while the woken run is live and has not
/// answered: a `<tg-thinking>` block, drawn with a shimmer.
pub const THINKING_WORKING: &str = "<tg-thinking>Working…</tg-thinking>";
/// Reaction set on every accepted owner message, unless `[telegram]
/// thinking_status` is on.
pub const ACK_EMOJI: &str = "👀";
Expand Down Expand Up @@ -3121,10 +3123,9 @@ impl Gateway {
}
}

/// The `sendRichMessageDraft` parameters of the status line `text` (plain
/// text, escaped here) in `chat`.
pub fn thinking_draft(chat: i64, text: &str) -> Value {
let html = format!("<tg-thinking>{}</tg-thinking>", html_escape(text));
/// The `sendRichMessageDraft` parameters of the status line `html`
/// ([`THINKING_WAKING`] or [`THINKING_WORKING`]) in `chat`.
pub fn thinking_draft(chat: i64, html: &str) -> Value {
json!({"chat_id": chat, "draft_id": THINKING_DRAFT, "rich_message": {"html": html}})
}

Expand Down Expand Up @@ -3970,9 +3971,9 @@ impl TgBot {

/// The status line: a `sendRichMessageDraft` (private chats only, a
/// 30-second preview Telegram clears when the bot sends a message) of
/// one `<tg-thinking>` block, best effort. `text` is plain (no markup).
fn thinking(&self, chat: i64, thread: Option<i64>, text: &str) {
let mut p = thinking_draft(chat, text);
/// `html`, best effort.
fn thinking(&self, chat: i64, thread: Option<i64>, html: &str) {
let mut p = thinking_draft(chat, html);
if let Some(t) = thread {
p["message_thread_id"] = json!(t);
}
Expand Down
13 changes: 6 additions & 7 deletions crates/axe/tests/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,22 +1010,21 @@ fn thinking_status_off_sends_typing_only() {
fn thinking_status_on_streams_a_thinking_draft_until_the_bot_replies() {
let rig = Rig::with("thinking_status = true");
let drafts = || rig.stub.calls("sendRichMessageDraft");
let draft = |text: &str| {
json!({"chat_id": OWNER, "draft_id": 1,
"rich_message": {"html": format!("<tg-thinking>{text}</tg-thinking>")}})
};
// Accepted: typing as before, plus the waking status line.
let draft =
|html: &str| json!({"chat_id": OWNER, "draft_id": 1, "rich_message": {"html": html}});
// Accepted: typing as before, plus the waking status line: a plain
// loading line, no words (owner msg #6879).
rig.stub.push(text_msg(30, 50, OWNER, OWNER, "hello"));
rig.stub.wait_confirmed(30);
wait_for("waking draft", 20, || drafts().len() == 1);
assert_eq!(drafts()[0].params, draft("Waking up…"));
assert_eq!(drafts()[0].params, draft("…"));
assert_eq!(rig.stub.calls("sendChatAction").len(), 1);

// The live run: each typing refresh also streams the working line.
let (conn, run) = start_run(&rig);
wait_for("working drafts", 30, || drafts().len() >= 3);
for c in &drafts()[1..] {
assert_eq!(c.params, draft("Working…"));
assert_eq!(c.params, draft("<tg-thinking>Working…</tg-thinking>"));
}
for c in rig.stub.calls("sendChatAction") {
assert_eq!(c.params, json!({"chat_id": OWNER, "action": "typing"}));
Expand Down
6 changes: 3 additions & 3 deletions docs/design/bots.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ and schedules stay in that bot's `/status`, so the two never repeat.
`/web` replies in the owner's private chat with a one-time web login link, only with `[telegram] web_login = true` (off by default, for Telegram-only installs; `Gateway::web_reply` in `telegram.rs`, the key in `config.rs`). The same key gates every other portal link Telegram shows (view links, board goal and task links, a form's task): `Gateway::new` drops the public URL when it is off.
`[telegram] thinking_status = true` (off by default, task 2528, store doc
`harvis/research/20261203-telegram-rich-entities.md`) adds a status line next to
`typing`. In a private chat it is a `sendRichMessageDraft` with one
`<tg-thinking>` block, "Waking up…" on accept and "Working…" on each typing
refresh. It stops once the bot sends to that chat (`TgBot::awaits_reply`);
`typing`. In a private chat it is a `sendRichMessageDraft` (one draft id, so
changes animate): plain "…" on accept (no words, owner msg #6879) and a
`<tg-thinking>Working…</tg-thinking>` block on each typing refresh. It stops once the bot sends to that chat (`TgBot::awaits_reply`);
Telegram clears the draft then, or after 30 s. The server adds it, so the
model writes no markup. With the flag on the server sets no 👀 ack reaction
in any chat (task 2535): the status line is the ack, and emoji reactions are
Expand Down
3 changes: 2 additions & 1 deletion docs/user/primitives/bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ links. One gate: `Gateway::new` in `crates/axe-telegram/src/telegram.rs`.
The server acknowledges each accepted owner message with a 👀 reaction, and
while a bot works on it the chat shows Telegram's `typing` status. With
`[telegram] thinking_status = true` (off by default), the owner's private
chat also shows an animated status line, "Waking up…" and then "Working…",
chat also shows an animated status line: a plain "…" until the bot's run
starts, then a shimmering "Working…",
until the bot's next message there, and the server adds no 👀 reaction in
any chat. Groups get `typing` only, and a client without draft support shows
`typing` only. See `TgBot::accepted` and `typing_loop` in
Expand Down
Loading