trading_agent.channels.telegram_requests
¶
The desks' questions and plans on Telegram, answered with buttons.
Each question becomes one message with a button per option. A single-choice question is settled by one press; a multiple-choice one ticks options and is settled with Done. "Other…" and a plan's "Keep planning" ask the user to type a reply, and the chat's next message is taken as that reply instead of going to the desk. Once every question of a request is settled, the answers go to the desk through the same responder the web page uses.
When a request is answered anywhere, on the web page or in another chat, its Telegram messages lose their buttons and say how it was settled.
Typical usage example:
requests = TelegramRequests(api, pairing, store, responder) await requests.show(request) await requests.press(chat, button)
TelegramRequests
¶
Shows requests in the paired chats, and turns button presses and typed replies into answers.
Each request's progress is kept in memory while it is open: the answers chosen so far, which questions are settled, and which messages hold its buttons. After a restart, the request is shown again when it is next published.
Creates the handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
TelegramApi
|
The connection to Telegram. |
required |
pairing
|
PairingStore
|
The paired chats. |
required |
store
|
UserRequestStore
|
Where requests are kept. |
required |
responder
|
UserRequestResponder
|
Records the answers and tells the desks. |
required |
Source code in src/trading_agent/channels/telegram_requests.py
show
async
¶
Sends a request to every paired chat, with its buttons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
UserRequest
|
The request. |
required |
Source code in src/trading_agent/channels/telegram_requests.py
wants_text
¶
Says whether the chat's next message is a typed reply to a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chat_id
|
int
|
The chat. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True after "Other…" or "Keep planning" was pressed in that chat. |
Source code in src/trading_agent/channels/telegram_requests.py
receive_text
async
¶
Takes a typed reply as the "Other" answer or as plan feedback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chat_id
|
int
|
The chat. |
required |
text
|
str
|
The reply. |
required |
Source code in src/trading_agent/channels/telegram_requests.py
press
async
¶
Handles a press on one of a request's buttons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
button
|
IncomingButton
|
The press. |
required |
Source code in src/trading_agent/channels/telegram_requests.py
close
async
¶
Removes a request's buttons once it is answered anywhere, saying how it was settled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
The user_response event's payload. |
required |