Skip to content

feat: migrate to Chat SDK for multi-platform adapter support#13

Open
farzanshibu wants to merge 3 commits into
raroque:mainfrom
farzanshibu:feat/chat-sdk-integration
Open

feat: migrate to Chat SDK for multi-platform adapter support#13
farzanshibu wants to merge 3 commits into
raroque:mainfrom
farzanshibu:feat/chat-sdk-integration

Conversation

@farzanshibu
Copy link
Copy Markdown

@farzanshibu farzanshibu commented Apr 27, 2026

Closes #14

Summary

  • Replace custom server/sendblue.ts with chat-adapter-sendblue and @chat-adapter/telegram unified under Chat SDK
  • Add server/bot.ts with env-driven adapter registry — new platforms (Slack, WhatsApp, Discord, etc.) are one registerIfConfigured() call
  • Refactor webhook bridge in server/index.ts to forward all request headers and add debug logging ([webhook:name] incoming POST body=...)
  • Add scripts/telegram-webhook.mjs for auto-registration of Telegram webhook on dev boot
  • Update README with "Adding more chat platforms" section — step-by-step Slack example, full adapter table linking to chat-sdk.dev/adapters

Test plan

  • npm run dev boots with both sendblue and telegram adapters registered
  • Inbound iMessage → [webhook:sendblue] incoming POST log → [turn ...] log → reply sent
  • Inbound Telegram message → same turn flow
  • Adding a third adapter (e.g. Slack) requires only env vars + one registerIfConfigured() block
  • SENDBLUE_AUTO_WEBHOOK=false disables Sendblue webhook auto-registration

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 27, 2026 21:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the project’s chat/webhook integration to the Chat SDK so multiple chat platforms (Sendblue iMessage/SMS/RCS, Telegram, and future adapters like Slack) can share a unified bot + webhook mounting approach.

Changes:

  • Replace the custom Sendblue router with a Chat SDK Chat instance and env-driven adapter registration (server/bot.ts), plus updated ack-sending integration.
  • Refactor server/index.ts webhook handling to mount all registered adapter webhooks and bridge Express requests to Web API Request/Response.
  • Add Telegram webhook auto-registration script and wire it into npm run dev, plus documentation/env updates for adding new platforms.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
skills-lock.json Adds chat-sdk skill source and updates computed hashes for existing skills.
server/sendblue.ts Removes legacy custom Sendblue webhook/router + messaging implementation.
server/interaction-agent.ts Replaces SMS-only ack behavior with a generic onSendAck callback.
server/index.ts Mounts adapter webhooks from webhookPaths and adds an Express↔Web API bridge with logging.
server/bot.ts Introduces Chat SDK bot + adapter registry (Sendblue + Telegram) and unified turn handler.
server/automations.ts Switches automation notifications to posting via Chat SDK (adapter-agnostic).
scripts/telegram-webhook.mjs Adds Telegram webhook registration/clearing helper script.
scripts/dev.mjs Runs both Sendblue + Telegram webhook registration scripts during dev boot.
package-lock.json Adds Chat SDK + adapters and related transitive deps.
README.md Documents “Adding more chat platforms” and lists supported adapters/env vars.
.env.example Adds TELEGRAM_BOT_TOKEN env var documentation.
.agents/skills/*/SKILL.md Updates Convex skill descriptions; adds new chat-sdk skill doc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/index.ts Outdated
Comment thread server/index.ts Outdated
Comment thread scripts/dev.mjs
Comment thread server/index.ts Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR migrates the custom Sendblue integration to the Chat SDK, adding Telegram support and an env-driven adapter registry that makes future platform additions (Slack, Discord, etc.) a one-block change. The webhook bridge, raw-body capture for HMAC verification, and startup orchestration are all well-executed.

Confidence Score: 5/5

Safe to merge; all findings are P2 quality improvements with no blocking bugs on the critical path.

No P0 or P1 issues found. The three P2 comments (iMessage-only system prompt, silent header-array drops, Telegram webhook not auto-registered for stable domains) are quality improvements rather than functional regressions.

server/interaction-agent.ts — system prompt iMessage framing should be generalized now that multiple platforms are supported.

Important Files Changed

Filename Overview
server/bot.ts New file implementing the Chat SDK bot with env-driven adapter registry; event routing correctly scopes onNewMessage to sendblue-only to prevent double-firing on @-mentions.
server/index.ts Webhook bridge now correctly captures raw bytes for HMAC verification; minor issue with array-valued headers being silently dropped during header forwarding.
server/automations.ts Migrated notification delivery to Chat SDK bot.openDM; adds sms:sendblue: prefix normalization for legacy Convex records.
server/interaction-agent.ts Unchanged but now used as the shared handler for all platforms; system prompt still hard-codes iMessage framing and formatting constraints, which are suboptimal for Telegram.
scripts/dev.mjs Dev orchestrator now dynamically builds per-platform webhook lines and auto-registers Telegram webhook for ephemeral ngrok; stable-domain paths skip Telegram registration silently.
scripts/telegram-webhook.mjs New standalone script for Telegram webhook registration and teardown; reads .env.local directly and calls the Bot API correctly.

Sequence Diagram

sequenceDiagram
    participant Platform as iMessage / Telegram
    participant Express as Express (server/index.ts)
    participant Bridge as bridgeWebhook()
    participant ChatSDK as Chat SDK (bot.ts)
    participant Handler as handleTurn()
    participant Agent as interaction-agent.ts
    participant Convex as Convex DB

    Platform->>Express: POST /sendblue/webhook or /telegram/webhook
    Express->>Bridge: rawBody captured via verify()
    Bridge->>ChatSDK: new Request(url, {headers, rawBody})
    ChatSDK->>ChatSDK: verify HMAC signature
    ChatSDK->>Handler: onDirectMessage / onNewMention / onNewMessage
    Handler->>Agent: handleUserMessage({conversationId, content})
    Agent->>Convex: messages.send (user)
    Agent-->>Handler: reply string
    Handler->>ChatSDK: thread.post(reply)
    Handler->>Convex: messages.send (assistant)
    ChatSDK->>Platform: deliver reply
Loading

Reviews (3): Last reviewed commit: "Fix: normalize sms: → sendblue: before c..." | Re-trigger Greptile

Comment thread server/index.ts Outdated
Comment thread server/bot.ts Outdated
Comment thread server/bot.ts
farzanshibu and others added 2 commits April 28, 2026 03:05
Replace custom Sendblue integration with chat-adapter-sendblue and
@chat-adapter/telegram, both unified under Chat SDK. All platforms
share the same handlers, memory, automations, and Composio tools.

- Add server/bot.ts with env-driven adapter registry (registerIfConfigured)
- Delete server/sendblue.ts (replaced by chat-adapter-sendblue)
- Refactor server/index.ts webhook bridge to forward all headers + debug logs
- Add scripts/telegram-webhook.mjs for auto-registration on dev boot
- Update scripts/dev.mjs: auto-register Telegram webhook alongside Sendblue
- Add README section: "Adding more chat platforms" with Slack walkthrough
- Add .agents/skills/chat-sdk/SKILL.md for agent-assisted Chat SDK work

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Capture raw request body via express.json verify callback so HMAC
  signature verification works for Slack, GitHub, Discord, etc.
- Proxy adapter responses faithfully (status + headers + raw bytes)
  instead of forcing JSON — fixes URL verification challenge flows
- Fix double-handler: scope onNewMessage catch-all to sendblue only;
  all other platforms use onDirectMessage to avoid firing twice on @-mentions
- Gate webhook body logging behind DEBUG_WEBHOOKS=true env var to avoid
  PII in production logs
- Surface webhook registration failures explicitly in autoRegisterWebhook
- Update dev banner to list all active platform webhooks dynamically
  instead of hardcoding Sendblue-only messaging

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@farzanshibu farzanshibu force-pushed the feat/chat-sdk-integration branch from bdabdf9 to e82c46b Compare April 27, 2026 21:35
Comment thread server/automations.ts Outdated
@CaideSpries CaideSpries mentioned this pull request May 28, 2026
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: migrate to Chat SDK for multi-platform adapter support

2 participants