Telegram: un topic per sessione, streaming, pulsanti e impostazioni

- Menu comandi (setMyCommands, chat private): /sessioni /nuova /stato /stop
  /impostazioni /aiuto; /usa rimosso.
- Un topic per sessione (createForumTopic in chat privata), nome
  "<cartella> · <modello>", rinominato al cambio di modello e "(chiusa)" alla
  chiusura; mappa salvata in AKODE_HOME/telegram-topics.json. Senza topic:
  prefisso [cartella · modello] e scelta della sessione con pulsanti.
- /sessioni con Apri (link al topic), Stato e Stop; il messaggio si aggiorna
  modificandolo.
- Streaming con sendMessageDraft (can_stop, al massimo 1/s, stop = interrompe
  il turno), messaggio finale con piede "ctx · t/s · durata".
- Approvazioni con pulsanti colorati, poi un pulsante disattivato con l'esito.
- Piano come elenco modificato; reazioni ricevuto/fatto configurabili.
- /impostazioni con interruttori Sì/No salvati in [telegram]
  (streaming, reactions nuovi).
- Messaggi modificati: un comando modificato riparte, il testo no.
- Pulsanti con token opachi lato server; allowlist anche sui pulsanti.
- Nessuna emoji nei testi in uscita (test dedicato).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-12 11:12:01 +01:00
parent 466ed04fba
commit 2b8d77593d
17 changed files with 2643 additions and 449 deletions

View File

@@ -1,5 +1,6 @@
---
source: tui/src/telegram_panel_tests.rs
assertion_line: 47
expression: "render(&panel, width, 16)"
---
Telegram esc chiudi
@@ -8,13 +9,13 @@ expression: "render(&panel, width, 16)"
Stato attivo · connesso
Chat 123456789
Notifiche approvazioni · fine turno · errori · loop
Opzioni streaming sì · reazioni sì
Topic non attivi: @BotFather › il bot › Bot Settings › Threaded Mode
› Cambia il token del bot
Abbina una chat
Disattiva
Rimuovi il token
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
↑↓ scegli · invio conferma · esc chiudi

View File

@@ -1,6 +1,6 @@
---
source: tui/src/telegram_panel_tests.rs
assertion_line: 46
assertion_line: 47
expression: "render(&panel, width, 16)"
---
Telegram esc chiudi
@@ -9,13 +9,13 @@ expression: "render(&panel, width, 16)"
Stato attivo · connesso
Chat 123456789
Notifiche approvazioni · fine turno · errori · loop
Opzioni streaming sì · reazioni sì
Topic non attivi: @BotFather › il bot › Bot Settings › Threaded Mode
› Cambia il token del bot
Abbina una chat
Disattiva
Rimuovi il token
────────────────────────────────────────────────────────────────────────────
↑↓ scegli · invio conferma · esc chiudi

View File

@@ -1,5 +1,6 @@
---
source: tui/src/telegram_panel_tests.rs
assertion_line: 55
expression: "render(&panel, width, 16)"
---
Telegram esc chiudi
@@ -8,13 +9,13 @@ expression: "render(&panel, width, 16)"
Stato disattivato
Chat nessuna abbinata
Notifiche approvazioni · fine turno · errori · loop
Opzioni streaming sì · reazioni sì
Topic da verificare (si vede col bot attivo)
› Imposta il token del bot
Abbina una chat
Attiva
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
↑↓ scegli · invio conferma · esc chiudi

View File

@@ -1,6 +1,6 @@
---
source: tui/src/telegram_panel_tests.rs
assertion_line: 54
assertion_line: 55
expression: "render(&panel, width, 16)"
---
Telegram esc chiudi
@@ -9,13 +9,13 @@ expression: "render(&panel, width, 16)"
Stato disattivato
Chat nessuna abbinata
Notifiche approvazioni · fine turno · errori · loop
Opzioni streaming sì · reazioni sì
Topic da verificare (si vede col bot attivo)
› Imposta il token del bot
Abbina una chat
Attiva
────────────────────────────────────────────────────────────────────────────
↑↓ scegli · invio conferma · esc chiudi

View File

@@ -72,6 +72,8 @@ pub(crate) struct TelegramStatus {
pub(crate) has_token: bool,
pub(crate) bot_name: Option<String>,
pub(crate) connected: bool,
/// Topics in private chats, as the bridge last saw them (`None`: not checked yet).
pub(crate) topics: Option<bool>,
}
impl TelegramStatus {
@@ -82,6 +84,7 @@ impl TelegramStatus {
let connected = settings.enabled && has_token && PollLock::try_acquire(codex_home).is_none();
Self {
bot_name: settings::load_bot_name(codex_home),
topics: settings::load_bot_topics(codex_home),
settings,
has_token,
connected,
@@ -412,6 +415,25 @@ impl TelegramPanel {
Span::from(levels.join(" · "))
},
));
lines.push(field(
"Opzioni",
Span::from(format!(
"streaming {} · reazioni {}",
if status.settings.streaming { "sì" } else { "no" },
if status.settings.reactions { "sì" } else { "no" },
)),
));
lines.push(field(
"Topic",
match status.topics {
Some(true) => Span::from("uno per sessione"),
Some(false) => Span::styled(
"non attivi: @BotFather › il bot › Bot Settings › Threaded Mode",
status_style(StatusTone::Attention),
),
None => "da verificare (si vede col bot attivo)".dim(),
},
));
lines.push(Line::from(""));
for (index, (_, label)) in self.actions().into_iter().enumerate() {
let line = if index == self.selected {

View File

@@ -11,6 +11,7 @@ fn status() -> TelegramStatus {
has_token: true,
bot_name: Some("akode_bot".to_string()),
connected: true,
topics: Some(false),
}
}