跳转到内容

Messaging Providers 概览

Greentic 通过 Messaging Providers 支持多个消息平台。每个 provider 都是一个 WASM component pack,负责处理:

  • Ingress - 从平台接收消息
  • Egress - 向平台发送消息
  • Operations - 平台特定功能(按钮、卡片、线程)
External Platform (Slack/Teams/Telegram)
▼ Webhook
┌─────────────────────────────────────────┐
│ Ingress Component │
│ (Parse platform-specific format) │
└─────────────────────────────────────────┘
▼ Normalized Message
┌─────────────────────────────────────────┐
│ NATS Bus │
│ greentic.messaging.ingress.{tenant}... │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ Flow Executor │
│ (Process with your flows) │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ NATS Bus │
│ greentic.messaging.egress.{tenant}... │
└─────────────────────────────────────────┘
▼ Platform-specific format
┌─────────────────────────────────────────┐
│ Egress Component │
│ (Format for platform API) │
└─────────────────────────────────────────┘
▼ API Call
External Platform

所有 provider 都会将消息归一化为统一格式:

pub struct NormalizedMessage {
pub id: String,
pub channel_id: String,
pub sender_id: String,
pub sender_name: Option<String>,
pub content: String,
pub timestamp: u64,
pub reply_to: Option<String>,
pub attachments: Vec<Attachment>,
pub metadata: Option<Value>,
}

这使你的 flows 无需修改就能在任意消息平台上运行。

greentic.demo.yaml
providers:
messaging-telegram:
pack: "providers/messaging/messaging-telegram.gtpack"
setup_flow: "setup_default"
verify_flow: "verify_webhooks"
messaging-slack:
pack: "providers/messaging/messaging-slack.gtpack"
setup_flow: "setup_default"
answers.json
{
"messaging-telegram": {
"enabled": true,
"public_base_url": "https://example.ngrok-free.app",
"bot_token": "123456789:ABCdefGHI..."
},
"messaging-slack": {
"enabled": true,
"public_base_url": "https://example.ngrok-free.app",
"bot_token": "xoxb-xxx-xxx",
"slack_app_id": "A07XXX"
}
}

消息会通过带有租户作用域的 NATS subject 流转:

Subject方向
greentic.messaging.ingress.{env}.{tenant}.{team}.{channel}入站
greentic.messaging.egress.{env}.{tenant}.{team}.{channel}出站

所有 provider 都支持基础文本消息:

- id: reply
type: reply
config:
message: "Hello! How can I help?"

大多数 provider 支持富内容:

- id: send_card
type: adaptive-card
config:
card: "cards/welcome.json"

交互元素(依 provider 而定):

- id: ask_choice
type: reply
config:
message: "What would you like to do?"
buttons:
- label: "Get Help"
action: "help"
- label: "Contact Support"
action: "support"

文件与媒体支持:

- id: send_file
type: reply
config:
message: "Here's your report"
attachments:
- type: file
url: "https://example.com/report.pdf"
name: "report.pdf"

编写可跨渠道运行的 flows:

flows/on_message.ygtc
name: universal_handler
version: "1.0"
nodes:
- id: greet
type: reply
config:
# Works on any platform
message: "Hello! I'm your assistant."
next: ask_intent
- id: ask_intent
type: reply
config:
message: "How can I help you today?"
# Buttons render differently per platform
buttons:
- label: "Get Started"
action: "start"
- label: "Help"
action: "help"
triggers:
- type: message
pattern: "hello|hi"
target: greet
功能SlackTeamsTelegramWhatsAppWebChatWebexEmail
Text
Rich Cards部分支持
Buttons
Files
Threads
Reactions

选择一个 provider 开始:

  • Telegram - 设置最简单,适合测试
  • Slack - 功能完整的工作区集成
  • WebChat - 嵌入到你的网站