This release is a pre-release and may not be stable for production use.
agent-framework-hosting-telegram
Telegram Bot API-shaped helpers for app-owned Agent Framework hosting.
This is an alpha, helper-only package: it converts between Telegram's
Update JSON shape and Agent Framework run values in both directions. It
does not provide a bot client, a hosting/channel registry, or a
long-running service. Your app remains fully responsible for:
- Fetching updates -- long polling (
getUpdates) or registering a webhook -- and for verifying webhook authenticity (e.g. Telegram's secret token header, or an IP allowlist). - The Bot API client -- issuing the actual HTTP calls (
sendMessage,sendPhoto,editMessageText,answerCallbackQuery,getFile, ...) with whatever HTTP library you prefer. - Rate limits and retries -- Telegram enforces per-chat and global rate
limits; back off and retry on
429/5xxyourself. - Command dispatch --
telegram_command(...)only parses and normalizes a leading/command; your app decides what each command does. - Sessions/storage -- pair these helpers with
agent-framework-hosting'sAgentStateand core'sSessionStoreorFileSessionStoreto persistAgentSessions across turns.
Helpers
telegram_chat_id(update)-- the chat id an update belongs to.telegram_session_id(update, bot_id=...)-- a bot-scopedAgentStatesession id. Private chats usetelegram:<bot_id>:<user_id>; other chats usetelegram:<bot_id>:<chat_id>.telegram_command(update)-- a leading slash command, with/name@bot argsnormalized to/name args. ReturnsNoneif there is none.telegram_callback_query_id(update)-- a callback query's id, so you can callanswerCallbackQueryyourself.telegram_media_file_id(update_or_message)-- the(file_id, mime_type)of inbound media (largest photo size, document, voice, audio, or video).telegram_to_run(update, *, resolve_file_url=None, stream=False)-- convert amessage,edited_message, orcallback_queryupdate intoAgent.runarguments. Provideresolve_file_url(typically backed bygetFile) to turn inbound media into content; without it (or when it returnsNone), text/caption is preserved and media is otherwise dropped. Media-only input with no resolvable URL raisesValueError.telegram_from_run(result, *, chat_id, parse_mode=None)-- render a finished run as oneTelegramOperation(sendPhotowhen the response has an image, otherwisesendMessage, falling back to"(no response)").telegram_from_streaming_run(stream, *, chat_id, message_id, initial_text=None, parse_mode=None)-- render a streaming run aseditMessageTextoperations with the cumulative text so far, followed by any images in the final response assendPhotooperations. Pass the app-created placeholder text asinitial_textso an identical first edit is omitted. Image-only responses first emitdeleteMessagefor the placeholder.
TelegramOperation is a minimal TypedDict of {"method": str, "payload": dict}
-- your app is responsible for actually calling the Bot API with it.
from agent_framework_hosting import AgentState
from agent_framework_hosting_telegram import (
telegram_chat_id,
telegram_from_run,
telegram_session_id,
telegram_to_run,
)
state = AgentState(agent)
async def handle_update(update: dict) -> None:
chat_id = telegram_chat_id(update)
if chat_id is None:
return # Not a chat update this bot handles.
session_id = telegram_session_id(update, bot_id=bot.id)
session = await state.get_or_create_session(session_id)
run = await telegram_to_run(update, resolve_file_url=resolve_telegram_file_url)
result = await (await state.get_target()).run(run["messages"], session=session, options=run["options"])
await state.set_session(session_id, session) # type: ignore[arg-type]
operation = telegram_from_run(result, chat_id=chat_id)
await call_bot_api(operation["method"], operation["payload"]) # Your HTTP client.
The base execution-state helpers live in
agent-framework-hosting.
Metadata
Release files for agent-framework-hosting-telegram 1.0.0a260730
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| agent_framework_hosting_telegram-1.0.0a260730.tar.gz | 11.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agent_framework_hosting_telegram-1.0.0a260730-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.1 kB
Release files / agent_framework_hosting_telegram-1.0.0a260730.tar.gz
| Download URL | agent_framework_hosting_telegram-1.0.0a260730.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17c34d9cf60d2efc4a007a42cf760a656ee1e26ffe7fee2e423c80dbe1ee2864
|
|
BLAKE2b-256 checksum How to use checksums |
245fe190d86b5bb3a5cee1fe6649cdc6134c24cdf6d03e9cd5d85f7fd387d1e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / agent_framework_hosting_telegram-1.0.0a260730-py3-none-any.whl
| Download URL | agent_framework_hosting_telegram-1.0.0a260730-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc3f2cc116c6ba33aded47af6740f7c09d7ac491eddd2b00911730cb81b28309
|
|
BLAKE2b-256 checksum How to use checksums |
b22aac5da077d98d9cb10b5397c8466e0c7d876c86c9032e11069b2a75340daa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for agent-framework-hosting-telegram 1.0.0a260730
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.