integration-webhooks
它能做什么
这项技能说明如何在无服务器主机上处理来自聊天和邮件集成的传入消息。webhook 先保存工作并立即回复,而单独的运行负责耗时的智能体工作。适合添加消息集成的开发者。
适用场景
- ✓当你要添加 Slack 或 WhatsApp 等新的消息集成的时候。
- ✓当 webhook 的消息被丢弃或被重复回复的时候。
- ✓当智能体的回复时间超过平台的响应时限的时候。
技能链接
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/integration-webhooks/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能把我们的应用连接到 Slack,让频道中的问题得到回答,而不会超时吗?”
每周 5 个新技能,1 分钟读完。
工作原理
webhook 将传入消息存入数据库,并立即返回成功响应。之后由单独的运行处理该消息,数据库仍是唯一的事实来源。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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 |
|---|
常见问题
为什么不在 webhook 中运行智能体?
技能说明,消息平台期望快速回复,而智能体运行可能需要长得多的时间。
重复消息怎么办?
先保存每个事件,有助于防止被重试的事件触发第二次运行。
什么是自触发请求?
它是应用发送给自己的后续 HTTP 请求,使耗时工作在一次新的执行中运行。
详情
作者的原始描述
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
热度
- GitHub 星标
- 7.6k
- 排名
- #13164
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …