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
3 changes: 2 additions & 1 deletion crates/axe-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,8 @@ pub struct Telegram {
/// A "thinking" status in the owner's private chats: while a woken bot
/// has not yet answered, it also streams a `sendRichMessageDraft` with a
/// `<tg-thinking>` block (Bot API 10.1), shown as an animated status
/// line. Off (the default): `typing` only, as before.
/// line, and the server sets no 👀 ack reaction in any chat. Off (the
/// default): `typing` and the reaction, as before.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub thinking_status: bool,
}
Expand Down
15 changes: 9 additions & 6 deletions crates/axe-telegram/src/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const THINKING_DRAFT: i64 = 1;
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…";
/// Reaction set on every accepted owner message.
/// Reaction set on every accepted owner message, unless `[telegram]
/// thinking_status` is on.
pub const ACK_EMOJI: &str = "👀";
/// About one message per second per chat.
const SEND_INTERVAL: Duration = Duration::from_secs(1);
Expand Down Expand Up @@ -1520,18 +1521,20 @@ impl Gateway {
},
)?;
if !dup {
// Acknowledge: the owner sees the message arrived.
if !edit {
// Acknowledge: the owner sees the message arrived. With
// `[telegram] thinking_status` the status line replaces the
// emoji, in every chat (emoji reactions are for real replies).
if !edit && !b.thinking {
let r = b.api.call(
"setMessageReaction",
&json!({"chat_id":chat,"message_id":tg_id,"reaction":[{"type":"emoji","emoji":ACK_EMOJI}]}),
);
if let Err(e) = r {
eprintln!("telegram: bot {}: ack #{msg}: {e}", b.name());
}
if voice {
voice_ack(b, store, chat, m["message_thread_id"].as_i64(), tg_id, msg);
}
}
if !edit && voice {
voice_ack(b, store, chat, m["message_thread_id"].as_i64(), tg_id, msg);
}
b.accepted(store, chat, m["message_thread_id"].as_i64());
}
Expand Down
34 changes: 34 additions & 0 deletions crates/axe/tests/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,13 @@ fn thinking_status_off_sends_typing_only() {
}
assert!(rig.stub.calls("sendRichMessageDraft").is_empty());
assert!(rig.stub.calls("sendMessageDraft").is_empty());
// The 👀 ack, as today.
let acks = rig.stub.calls("setMessageReaction");
assert_eq!(acks.len(), 1);
assert_eq!(
acks[0].params,
json!({"chat_id": OWNER, "message_id": 50, "reaction": [{"type":"emoji","emoji":"👀"}]})
);
}

#[test]
Expand Down Expand Up @@ -1045,6 +1052,8 @@ fn thinking_status_on_streams_a_thinking_draft_until_the_bot_replies() {
.any(|c| c.params["chat_id"] == GROUP)
});
assert!(drafts().iter().all(|c| c.params["chat_id"] == OWNER));
// The status line replaces the 👀 ack, in every chat (task 2535).
assert!(rig.stub.calls("setMessageReaction").is_empty());
bot::finish(
&conn,
run,
Expand All @@ -1057,6 +1066,31 @@ fn thinking_status_on_streams_a_thinking_draft_until_the_bot_replies() {
.unwrap();
}

#[test]
fn thinking_status_on_adds_no_ack_even_when_the_draft_fails() {
let rig = Rig::with("thinking_status = true");
rig.send_faults("sendRichMessageDraft", &[SendFault::Status(400)]);
rig.stub.push(text_msg(30, 50, OWNER, OWNER, "hello"));
rig.stub.wait_confirmed(30);
wait_for("typing", 20, || {
!rig.stub.calls("sendChatAction").is_empty()
});
wait_for("failed draft", 20, || {
!rig.stub.calls("sendRichMessageDraft").is_empty()
});
// A group message too: no draft there, and no emoji either.
rig.stub
.push(text_msg(31, 51, OWNER, GROUP, "in the group"));
rig.stub.wait_confirmed(31);
wait_for("group typing", 20, || {
rig.stub
.calls("sendChatAction")
.iter()
.any(|c| c.params["chat_id"] == GROUP)
});
assert!(rig.stub.calls("setMessageReaction").is_empty());
}

#[test]
fn unauthorized_group_membership_makes_the_bot_leave() {
let rig = Rig::new();
Expand Down
4 changes: 3 additions & 1 deletion docs/design/bots.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ and schedules stay in that bot's `/status`, so the two never repeat.
`<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`);
Telegram clears the draft then, or after 30 s. The server adds it, so the
model writes no markup.
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
left for the bot's real replies.

### Board

Expand Down
14 changes: 8 additions & 6 deletions docs/user/primitives/bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ Links to the web portal in Telegram (command replies, goal and task links
on the board pin, a form's task) appear only with `[telegram] web_login` on;
off, the default, none do. Blob links and sealed form buttons are not portal
links. One gate: `Gateway::new` in `crates/axe-telegram/src/telegram.rs`.
While a bot works on the owner's message, 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…", until the bot's next message there. Groups get `typing`
only, and a client without draft support shows `typing` only. See
`TgBot::accepted` and `typing_loop` 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…",
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
`crates/axe-telegram/src/telegram.rs`.

The bot protocol (runs, wakes, memory, authority, Telegram) is built in;
bundles in the [store](store.md) only add opinions.
Expand Down
3 changes: 2 additions & 1 deletion docs/user/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Opt-in `[telegram]` switches, all off by default: `web_login` (the `/web`
command and every portal link in Telegram) and `thinking_status` (an
animated "Working…" status line in the owner's private chat while a woken
bot has not answered yet, made with `sendRichMessageDraft`, Bot API 10.1;
see [bots](../primitives/bot.md)).
it replaces the server's 👀 ack reaction, which is then never added; see
[bots](../primitives/bot.md)).
`crates/axe-core/src/config.rs` defines every table, default and check;
`axe config` validates and prints the resolved file, including the built-in
agents.
Expand Down
Loading