Add a Generic Webhook / HTTP Adapter for Arbitrary Chat Platforms

Đang mở
#96 1 bình luận 18 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@roboeve đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #1033 của @roboeve — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu từ cấu hình Chat được đề xuất và entry point createGenericAdapter, sau đó xem xét cách SDK hiện biểu diễn các sự kiện gửi đến và gửi phản hồi. Xác định phạm vi của adapter xoay quanh việc ánh xạ payload của webhook, xác minh và lọc tùy chọn, cùng hành vi HTTP gửi đi do nhà phát triển cung cấp; được xem là hoàn thành khi một adapter generic được tài liệu hóa có thể hỗ trợ các nền tảng bất kỳ có khả năng HTTP mà không cần parsing dành riêng cho nền tảng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement
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

Ngôn ngữ chính
TypeScript
Star
2.5k
Fork
355
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
42

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel/chat

Tất cả issue của vercel/chat

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.