跳转到内容
simail文档v0

接入

轮询事件

用 GET /v0/events 和游标读到每一条事件;不需要公网地址。游标、过滤、保留期和轮询循环。

docs.simail.ai/zh/events

GET /v0/events 是对邮件做出反应的最简单办法:没有公网 URL,不用验签名,agent 离线时也不会漏(事件保留 30 天)。它返回的薄载荷与 webhook 和 WebSocket 相同;见事件类型。

GET/v0/events

需要 event_read。结果限于 key 的作用域:邮箱作用域的 key 只看得到自己邮箱的事件。

查询参数说明
after上一页响应里的游标;第一次调用省略它,从仍保留的最早事件开始
types逗号分隔的事件类型,例如 message.received,thread.locked
inbox_ids逗号分隔的、在你作用域内的邮箱 ID
limit1–200,默认 50
curl -s "https://api.simail.ai/v0/events?types=message.received&limit=100" \
-H "Authorization: Bearer $SIMAIL_API_KEY"
{
"count": 1,
"limit": 100,
"events": [
{ "event_id": "evt_…", "event_type": "message.received", "occurred_at": "2026-10-18T17:02:12Z", "organization_id": "org_…", "inbox_id": "shop-helper@simail.email", "thread_id": "thr_…", "message_id": "msg_…", "data": { "from": "ada@example.com", "labels": ["received", "unread"], "held": false, "classification": "normal", "wake": true } }
]
}

响应里有 count(本页事件数)、limit 和 events。只有后面可能还有事件时才带 next_cursor(满页,或一次长扫描提前停下)。记下它,下次当作 after 传入。没有 next_cursor 的一页表示暂时到头:保留手上已有的游标,稍后再用它轮询。下一次轮询会把你已经见过的尾部事件再返回一遍,所以按 event_id 去重。事件按记录顺序给出。轮询返回每一条事件,包括没有唤醒 agent 的(data.wake: false);如果只要会唤醒的,自己过滤。message.released 的 wake 恒为 true。

  • 游标不透明且有签名。它绑定你的组织和 key 的作用域;换一把 key 或其他作用域会返回 400 validation_error(reason: page_token_invalid)。它不固定过滤条件:两次调用之间可以改 types 或 inbox_ids。
  • 事件保留 30 天。比这更老的游标返回 410 gone:去掉 after 重新开始,并用列出线程来对账。
  • 投递至少一次。按 event_id 去重。
let cursor: string | undefined = await loadCursor();
for (;;) {
const url = new URL("https://api.simail.ai/v0/events");
url.searchParams.set("types", "message.received,thread.locked,thread.unlocked");
url.searchParams.set("limit", "100");
if (cursor) url.searchParams.set("after", cursor);
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.SIMAIL_API_KEY}` } });
if (res.status === 429) { await sleep(Number(res.headers.get("retry-after") ?? 5) * 1000); continue; }
const page = await res.json();
for (const event of page.events) await handle(event); // idempotent on event.event_id
if (page.next_cursor) { cursor = page.next_cursor; await saveCursor(cursor); } // 可能还有:马上再取
else await sleep(5000); // 已追平:保留手上的游标,稍后再轮询
}

先处理事件再保存游标,这样崩溃会重放事件,而不是丢掉它们。

GET/v0/inboxes/{inbox_id}/events

列出一个邮箱的 label.added / label.removed 记录(最近 50 条,最新在前,没有参数、没有游标)。需要 event_read。要分页的领域事件,用 GET /v0/events 加 inbox_ids。

MCP 工具 list_events 接受同样的 after、types、inbox_ids 和 limit。