teff.channels.telegram¶
teff.channels.telegram
¶
Telegram channel: run a workflow from Telegram messages.
A thin Bot API adapter over the shared :class:~teff.assistant.Assistant,
with two transport modes:
polling— the bot loops overgetUpdates(default, no public server needed).webhook— the bot registers asetWebhookURL and FastAPI receives Telegram's POSTs; ideal behind TLS (mode: webhook+url).
Each Telegram chat is a durable session: session_id = chat_id, so a
multi-turn workflow pauses on an interrupt, asks the operator a question
in-chat, and resumes when they answer. The checkpoint owner is the
sender's Telegram user id, so each user's conversations are isolated. The
transport is plain httpx (already a core dependency), so no extra
package is required.
channels: block::
channels:
telegram:
token_env: TELEGRAM_BOT_TOKEN
mode: polling # polling | webhook
url: https://bot.example.com/api/telegram # for webhook mode
Classes:
| Name | Description |
|---|---|
TelegramChannel |
A Telegram Bot API adapter over a shared |
TelegramChannel
¶
A Telegram Bot API adapter over a shared Assistant.
Methods:
| Name | Description |
|---|---|
handle_update |
Process one Telegram update: run a turn and reply in-chat. |
run |
Long-poll for updates forever (or a single pass with |
send_message |
Send a plain text reply (interrupt prompts included). |
session_id_for |
Telegram chats map one-to-one to durable sessions. |
set_webhook |
Point Telegram at |
Source code in teff/channels/telegram.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
handle_update
async
¶
handle_update(update)
Process one Telegram update: run a turn and reply in-chat.
The checkpoint owner is the sender's Telegram user id
(message.from.id), so every user's sessions are isolated.
Source code in teff/channels/telegram.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
run
async
¶
run(*, once=False)
Long-poll for updates forever (or a single pass with once).
Source code in teff/channels/telegram.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
send_message
async
¶
send_message(chat_id, text)
Send a plain text reply (interrupt prompts included).
Source code in teff/channels/telegram.py
73 74 75 | |
session_id_for
¶
session_id_for(chat_id)
Telegram chats map one-to-one to durable sessions.
Source code in teff/channels/telegram.py
60 61 62 | |
set_webhook
async
¶
set_webhook(url)
Point Telegram at url (call once, then serve the POSTs).
Source code in teff/channels/telegram.py
119 120 121 | |