Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)7.6k · #13164

integration-webhooks

Skill này làm gì

Skill này giải thích cách xử lý tin nhắn đến từ các tích hợp chat và email trên máy chủ serverless. Webhook lưu công việc, trả lời ngay, còn một lần chạy riêng thực hiện phần việc chậm của agent. Skill dành cho lập trình viên thêm tích hợp nhắn tin.

Khi nào nên dùng

  • ✓Khi bạn thêm một tích hợp nhắn tin mới như Slack hoặc WhatsApp.
  • ✓Khi tin nhắn từ webhook bị mất hoặc được trả lời hai lần.
  • ✓Khi câu trả lời của agent mất nhiều thời gian hơn cửa sổ phản hồi của nền tảng.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/integration-webhooks/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/integration-webhooks/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể kết nối ứng dụng của tôi với Slack để các câu hỏi trong kênh được trả lời mà không bị timeout không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Webhook lưu tin nhắn đến vào cơ sở dữ liệu và trả về phản hồi thành công ngay. Một lần chạy riêng sau đó xử lý tin nhắn, và cơ sở dữ liệu vẫn là nguồn sự thật.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Integration Webhooks

Rule

Integration webhooks (Slack, Telegram, WhatsApp, email, Google Docs, etc.) must enqueue work to SQL and return 200 immediately, then process the work in a separate fresh function execution kicked off by a self-fired HTTP POST. SQL is always the source of truth. Long-lived hosts use an in-process retry loop as a best-effort safety net; serverless deployments must use an external durable sweep when recovery cannot depend on a process staying alive.

Do not run agent loops inside the webhook handler itself. Do not rely on fire-and-forget Promises after returning from a serverless handler — they get killed when the function freezes.

Why

Messaging platforms expect a 200 response within a tight window — Slack will retry after 3 seconds, and a retried event triggers duplicate agent runs. At the same time, an agent loop replying to the message can take 30–60+ seconds because it may make multiple LLM calls and tool calls.

Past attempts that don't work cross-host:

  • Fire-and-forget Promise.then(...) after returning — Lambda/Vercel/CF freeze the execution context the moment the response goes out. The promise is silently killed, the user gets no reply, and there's no error in the logs.
  • A platform background function as the queue — host-specific execution is useful as a delivery mechanism, but it cannot replace the SQL row or atomic claim shared by every host.
  • Cloudflare event.waitUntil() — CF Workers only, not portable.
  • Vercel Fluid / after() — Vercel-only, gated behind specific runtimes.
  • A long-lived in-process queue — fine on a single Node box, but on serverless every cold start gets a fresh queue and any pending work is lost.

The only universal answer: persist the work, then trigger a brand new function execution to do it. SQL is the queue, a self-webhook is the trigger, and a recurring job is the safety net.

The Flow

┌──────────┐    1. POST /integrations/:platform/webhook
│ Platform │────────────────────────────────────────────►┌──────────────────┐
└──────────┘                                             │ Webhook handler  │
                                                         │ (function exec 1)│
                                                         └──────────────────┘
                                                                  │
                            2. INSERT INTO integration_pending_tasks
                                 (status='pending', payload=...)
                                                                  │
                            3. dispatch POST /integrations/process-task
                                 — portable self-fire by default
                                 — acknowledged background handoff when enabled
                                                                  │
                            4. return 200 to platform ◄───────────┘

                                                         ┌──────────────────┐
                          5. POST arrives at processor   │ Processor        │
                             (separate fresh function)   │ (function exec 2)│
                                                         └──────────────────┘
                                                                  │
                            6. claimPendingTask(id) → status='processing'
                            7. runAgentLoop(...) — full timeout budget here
                            8. adapter.sendResponse(...) back to platform
                            9. markTaskCompleted(id)


                          ┌──────────────────────────────────────────────┐
                          │  Recovery sweep (every 60s) — safety net    │
                          │  Re-fires processor for tasks stuck in       │
                          │  'pending' or 'processing' beyond timeout.   │
                          │  Caps retries at 3 then marks 'failed'.      │
                          └──────────────────────────────────────────────┘

The webhook handler does as little as possible. The fresh function execution that handles _process-task gets its own full timeout budget for the agent loop.

Key Files

File Purpose
Câu hỏi thường gặp

Vì sao không chạy agent ngay trong webhook?

Skill nói các nền tảng nhắn tin mong đợi phản hồi nhanh, còn một lần chạy agent có thể mất lâu hơn nhiều.

Còn tin nhắn trùng lặp thì sao?

Lưu từng sự kiện trước giúp ngăn một sự kiện được thử lại kích hoạt thêm một lần chạy.

Yêu cầu tự kích hoạt là gì?

Đó là một yêu cầu HTTP theo dõi mà ứng dụng gửi cho chính nó, để công việc chậm chạy trong một lần thực thi mới.

Chi tiết

Mô tả gốc của tác giả

Cross-platform pattern for handling messaging integration webhooks (Slack, Telegram, WhatsApp, email, etc.) on serverless hosts. Use when adding a new integration adapter, debugging dropped messages, or wiring long-running agent work into a webhook handler.

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13164
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự