Telegram channel (Bot API) with allowlist authorization + typing indicator#3
Merged
Conversation
Telegram bot channel over the existing async HTTP client. TelegramClient: getUpdates long-poll + sendMessage + sendChatAction. TelegramChat: one poll loop authorizes the sender by from.id against the allowlist (reuses Config::isChatAllowed), demuxes by chat_id, and yields each new authorized chat from accept(); unauthorized / non-DM / non-text updates are silently dropped (rejected id logged for allowlist bootstrap), DMs only. TelegramConversation: receive/send, confirm() via text reply (y/a/no), updateStatus() maps an animated status to the 'typing…' chat action. Adds ConversationInterface::id() so persistence keys a per-chat SQLite file (console -> console.db, telegram -> <chat_id>.db). bin/claw runs the console inline and, for telegram, spawns the poll loop + one Session per chat. Routing/auth and the client are unit-tested via the HTTP fakes; the live network path needs a real bot token. 81 tests, PHPStan level 8, php-cs-fixer — all green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a Telegram bot channel (Bot API over the existing async HTTP client), with authorization modelled on OpenClaw/NanoClaw.
New (
src/Chat/)TelegramClient—getUpdates(long-poll, validatesok),sendMessage,sendChatAction.TelegramChat(gateway) — onepoll()loop pulls updates and, per update: authorize the sender byfrom.idagainst the allowlist (reuses the existingConfig::isChatAllowed), demux bychat_id, queue the text.accept()yields each new authorized chat.TelegramConversation—receive/send;confirm()via text reply (y= once,a= always, else no);updateStatus()maps an animated status to thetyping…chat action.Authorization (the must-have for a public bot)
from.id; unauthorized senders are silently dropped (a reply would confirm the bot to a prober). The rejected id is logged so the owner can bootstrap the allowlist.Wiring
ConversationInterface::id()keys a per-chat SQLite file (console→console.db, telegram →<chat_id>.db).bin/claw: console runs inline; telegram spawns the poll loop + oneSessionper chat.Behaviour & limits
Run it
.env:CLAW_CHANNEL=telegram,TELEGRAM_BOT_TOKEN=…,CLAW_ALLOWED_CHATS=<your id>. Message the bot; if your id isn't listed yet it's logged so you can add it.Tests
tests/Chat/Telegram*Test.php— getUpdates parse / API-error / sendMessage; routing + authorization + demux + group/non-text drop;typingon animated status, silence otherwise.81 tests pass, PHPStan level 8 clean, php-cs-fixer clean.