GH-50: feat(sdk/integrations/telegram): add ChatBridge listener + adapter#53
Merged
Conversation
Implements core.ChatCapable (Adapter) and core.ChatBridge (bridge) for the Telegram connector. - bridge.go: long-poll Start loop; maps message/command/callback Updates to core.MessageEvent; sanitizes inbound Text in the live path before HandleMessage; enforces AllowedIDs allow-list; Send (with inline keyboard for Buttons), Edit, Ack (AnswerCallback). - adapter.go: Adapter with Name()="telegram", NewChatBridge factory; three compile-time interface assertions. - Tests cover message/command/callback routing, invisible-Unicode sanitization guard, AllowedIDs enforcement, Send/Edit/Ack, and Start context cancellation.
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.
Summary
Automated PR created by Pilot for task GH-50.
Closes #50
Changes
GitHub Issue #50: feat(sdk/integrations/telegram): add ChatBridge listener + adapter
Context
Second half of the Telegram reference port — depends on the client/data issue.
Implement the
ChatBridgelistener + the net-new adapter, conforming to thesdk/corechat contract (chat.go, v0.18.0 — read.agent/system/chat-bridge-design.md).Source from
/tmp/pilot-src/internal/adapters/telegram/handler.go. This is thereference that proves the contract, so follow it precisely.
Implementation
Add to
sdk/integrations/telegram/:bridge.go(thecore.ChatBridgeimpl),adapter.go(net-newcore.ChatCapable), + tests. Transformations:github.com/qf-studio/pilot/...import; inject*slog.Logger.adapter.go:AdapterwithName() "telegram"+NewChatBridge(core.ChatDeps) core.ChatBridge. Add compile-time assertions:var _ core.Adapter = (*Adapter)(nil),var _ core.ChatCapable = (*Adapter)(nil),var _ core.ChatBridge = (*bridge)(nil).bridge.goimplementscore.ChatBridge:Start(ctx)— the long-poll loop (GetUpdates); for eachUpdate, map to acore.MessageEventand calldeps.Handler.HandleMessage:Action:"message",Text(sanitized in place beforeemit via the client/data
sanitizehelper — CRITICAL, the feat(sdk/integrations/github): port client, types, converter, notifier, webhook #28-class rulefor chat),
ChannelID = chat id (string),Sender = Identity{UserID: from id}./→Action:"command",Command+Args(split);do NOT execute it.
Action:"callback",CallbackID,Data.AllowedIDsallow-list; ignore others.Send(ctx, OutboundMessage) (MessageRef, error)—SendMessage, orSendMessageWithKeyboardrenderingOutboundMessage.Buttonsas an inlinekeyboard. Return
MessageRef{ChannelID, MessageID}.Edit(ctx, ref, text)—EditMessage.Ack(ctx, callbackID)—AnswerCallback(Telegram requires answering callbacks).sdk/testutilfakes only; include a guard that inboundTextwithinvisible-Unicode smuggling is sanitized before the handler sees it.
⛔ Touch ONLY
sdk/integrations/telegram/. Do not modifysdk/core/or other connectors.Acceptance
bridge.go,adapter.go(+ tests) exist; the 3 compile-timecoreassertions present;Name()returns"telegram".Startmaps message/command/callback Updates tocore.MessageEvent; inboundTextis sanitized in the live loop beforeHandleMessage(grep shows the call-site).Send/Edit/Ackmap to SendMessage(+keyboard)/EditMessage/AnswerCallback;Buttonsrender as inline keyboard.grep -rn "qf-studio/pilot" sdk/nothing; no command EXECUTION (commands emitAction:"command").go build ./...,go vet ./...,go test -race ./sdk/integrations/telegram/...,gofmt -l sdk/all clean.