Skip to content

Add a Generic Webhook / HTTP Adapter for Arbitrary Chat Platforms #96

@mitdave95

Description

@mitdave95

Problem Statement

Many popular or emerging messaging channels do not yet have dedicated adapters in the SDK. Like -

  1. WhatsApp (via open-source HTTP bridges such as WAHA or Beeper)
  2. Meta Ray-Ban smart glasses (which surface conversations through Meta/WhatsApp channels)
  3. Telegram (via its webhook-capable Bot API)
  4. Matrix / Element
  5. Various self-hosted, enterprise, or niche messengers
  6. 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:

  1. How incoming HTTP payloads are parsed and mapped to Chat SDK events (e.g., extracting message text, sender ID, channel/thread info)
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions