跳转到内容

Events Providers 概览

Events Providers 让你的数字员工能够响应消息之外的外部触发。它们负责处理:

  • 来自外部服务的 Webhook
  • 定时任务(timers/cron)
  • 邮件通知
  • 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>,
}
greentic.demo.yaml
providers:
events-webhook:
pack: "providers/events/events-webhook.gtpack"
events-timer:
pack: "providers/events/events-timer.gtpack"
flows/on_event.ygtc
name: handle_event
version: "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: process

事件通过 NATS 流转:

Subject用途
greentic.events.{env}.{tenant}.{type}事件通知
greentic.events.{env}.{tenant}.{type}.result事件处理结果
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_tracking
nodes:
- 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