Events Providers 概览
Events Providers 让你的数字员工能够响应消息之外的外部触发。它们负责处理:
- 来自外部服务的 Webhook
- 定时任务(timers/cron)
- 邮件通知
- SMS 通知
可用 Providers
Section titled “可用 Providers” Webhook 接收来自外部服务的 HTTP webhook
Timer 使用 cron 表达式调度任务
Email (SendGrid) 通过 SendGrid 发送事务型邮件
SMS (Twilio) 通过 Twilio 发送 SMS 消息
External Service / Timer │ ▼ HTTP / Schedule┌─────────────────────────────────────────┐│ Events Ingress ││ (Process incoming event) │└─────────────────────────────────────────┘ │ ▼ Normalized Event┌─────────────────────────────────────────┐│ NATS Bus ││ greentic.events.{env}.{tenant}.{type}│└─────────────────────────────────────────┘ │ ▼┌─────────────────────────────────────────┐│ Flow Executor ││ (Process with event flows) │└─────────────────────────────────────────┘所有事件都会被归一化为统一格式:
pub struct Event { pub id: String, pub event_type: String, pub source: String, pub timestamp: u64, pub payload: Value, pub metadata: Option<Value>,}在 Bundle 中
Section titled “在 Bundle 中”providers: events-webhook: pack: "providers/events/events-webhook.gtpack"
events-timer: pack: "providers/events/events-timer.gtpack"Event Flows
Section titled “Event Flows”name: handle_eventversion: "1.0"
nodes: - id: process type: script config: script: | // Process the event let payload = event.payload; process_payload(payload) next: respond
triggers: - type: event event_type: "order.created" target: processNATS Subjects
Section titled “NATS Subjects”事件通过 NATS 流转:
| Subject | 用途 |
|---|---|
greentic.events.{env}.{tenant}.{type} | 事件通知 |
greentic.events.{env}.{tenant}.{type}.result | 事件处理结果 |
事件驱动通知
Section titled “事件驱动通知”nodes: - id: on_order type: branch config: conditions: - expression: "event.event_type == 'order.created'" next: send_confirmation - expression: "event.event_type == 'order.shipped'" next: send_trackingnodes: - id: daily_report type: http config: method: GET url: "https://api.example.com/reports/daily" next: send_email
triggers: - type: timer cron: "0 9 * * *" # 9 AM daily target: daily_report