Skip to content

GH-50: feat(sdk/integrations/telegram): add ChatBridge listener + adapter#53

Merged
alekspetrov merged 1 commit into
mainfrom
pilot/GH-50
Jun 3, 2026
Merged

GH-50: feat(sdk/integrations/telegram): add ChatBridge listener + adapter#53
alekspetrov merged 1 commit into
mainfrom
pilot/GH-50

Conversation

@alekspetrov

Copy link
Copy Markdown
Contributor

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 ChatBridge listener + the net-new adapter, conforming to the
sdk/core chat 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 the
reference that proves the contract, so follow it precisely.

Implementation

Add to sdk/integrations/telegram/: bridge.go (the core.ChatBridge impl),
adapter.go (net-new core.ChatCapable), + tests. Transformations:

  • Remove every github.com/qf-studio/pilot/... import; inject *slog.Logger.
  • adapter.go: Adapter with Name() "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.go implements core.ChatBridge:
    • Start(ctx) — the long-poll loop (GetUpdates); for each Update, map to a
      core.MessageEvent and call deps.Handler.HandleMessage:
      • plain message → Action:"message", Text (sanitized in place before
        emit
        via the client/data sanitize helper — CRITICAL, the feat(sdk/integrations/github): port client, types, converter, notifier, webhook #28-class rule
        for chat), ChannelID = chat id (string), Sender = Identity{UserID: from id}.
      • text starting with /Action:"command", Command + Args (split);
        do NOT execute it.
      • callback query → Action:"callback", CallbackID, Data.
      • Enforce the AllowedIDs allow-list; ignore others.
    • Send(ctx, OutboundMessage) (MessageRef, error)SendMessage, or
      SendMessageWithKeyboard rendering OutboundMessage.Buttons as an inline
      keyboard. Return MessageRef{ChannelID, MessageID}.
    • Edit(ctx, ref, text)EditMessage.
    • Ack(ctx, callbackID)AnswerCallback (Telegram requires answering callbacks).
  • Tests use sdk/testutil fakes only; include a guard that inbound Text with
    invisible-Unicode smuggling is sanitized before the handler sees it.

⛔ Touch ONLY sdk/integrations/telegram/. Do not modify sdk/core/ or other connectors.

Acceptance

  • bridge.go, adapter.go (+ tests) exist; the 3 compile-time core assertions present; Name() returns "telegram".
  • Start maps message/command/callback Updates to core.MessageEvent; inbound Text is sanitized in the live loop before HandleMessage (grep shows the call-site).
  • Send/Edit/Ack map to SendMessage(+keyboard)/EditMessage/AnswerCallback; Buttons render as inline keyboard.
  • grep -rn "qf-studio/pilot" sdk/ nothing; no command EXECUTION (commands emit Action:"command").
  • go build ./..., go vet ./..., go test -race ./sdk/integrations/telegram/..., gofmt -l sdk/ all clean.

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.
@alekspetrov alekspetrov merged commit c2cca72 into main Jun 3, 2026
3 checks passed
@alekspetrov alekspetrov deleted the pilot/GH-50 branch June 3, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sdk/integrations/telegram): add ChatBridge listener + adapter

1 participant