-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
Many popular or emerging messaging channels do not yet have dedicated adapters in the SDK. Like -
- WhatsApp (via open-source HTTP bridges such as WAHA or Beeper)
- Meta Ray-Ban smart glasses (which surface conversations through Meta/WhatsApp channels)
- Telegram (via its webhook-capable Bot API)
- Matrix / Element
- Various self-hosted, enterprise, or niche messengers
- Any future or custom platform that supports inbound HTTP webhooks and can receive responses via HTTP POST
Without a generic mechanism, supporting these platforms requires either waiting for official adapter packages or forking/maintaining custom platform-specific integrations — which undermines the "write once, run anywhere" value proposition of the SDK.
Proposed Solution
Introduce a built-in generic webhook / HTTP adapter (or a lightweight "raw HTTP" adapter) in the core Chat SDK or as a first-party package (e.g., @chat-adapter/webhook or @chat-adapter/generic).
This adapter would allow developers to connect the same bot logic to any HTTP-capable platform by defining:
- How incoming HTTP payloads are parsed and mapped to Chat SDK events (e.g., extracting message text, sender ID, channel/thread info)
- How outgoing Chat SDK responses are transformed and sent back (e.g., via HTTP POST, specific JSON shape, headers, etc.)
Alternatives Considered
No response
Use Case
import { Chat } from "chat";
import { createGenericAdapter } from "@chat-adapter/generic"; // or built-in
const bot = new Chat({
userName: "mybot",
adapters: {
custom: createGenericAdapter({
// Core webhook handling
path: "/webhook/my-platform", // Vercel / server route
verification: {
secret: process.env.WEBHOOK_SECRET, // optional HMAC / token check
},
// Required mappings (examples)
incoming: {
getText: (payload) => payload?.message?.text || payload?.body,
getSenderId: (payload) => payload?.from?.id || payload?.sender,
getChannelId: (payload) => payload?.thread?.id || payload?.chatId,
// Optional: getMessageId, isFromBot, etc.
},
outgoing: async (channelId, content, options) => {
// Developer provides the send logic (fetch/axios/etc.)
await fetch("https://api.platform.com/messages", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.PLATFORM_TOKEN}` },
body: JSON.stringify({
chat_id: channelId,
text: content.text,
// ... platform-specific fields
}),
});
},
// Optional extras
platformName: "WhatsApp", // for logs/metrics
shouldHandle: (req) => req.headers["user-agent"]?.includes("WhatsApp"), // filter
}),
},
// ... other config (state, model, etc.)
});Priority
Nice to have
Contribution
- I am willing to help implement this feature
Additional Context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request