Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

NotificationService

通知管理服务,负责列出已启用的通知渠道和手动发送测试通知。系统事件(订单支付、开通完成、工单分配等)自动广播到所有启用的通知渠道。

RPC 列表

RPC描述权限
ListNotifiers列出所有通知渠道(含支持的事件类型)admin
SendNotification手动发送测试通知admin

ListNotifiers

描述

列出所有已启用的 Notifier 类型插件接口实例,含健康状态和支持的事件类型。

Request — EmptyRequest

无字段。

Response — ListNotifiersResponse

字段类型编号描述
notifiersrepeated NotifierInfo1通知渠道列表

NotifierInfo

字段类型编号描述
channel_idstring1接口实例 ID(UUID)
channel_namestring2渠道显示名称
supported_eventsrepeated string3支持的事件类型列表(如 ["order_paid","order_provisioned"]
is_healthybool4是否健康

示例

grpcurl -plaintext -H "authorization: Bearer <token>" \
  -d '{}' \
  localhost:50051 rustbill.notification.NotificationService/ListNotifiers
const resp = await api.listNotifiers({});
// resp.notifiers → [{ channel_id, channel_name, supported_events, is_healthy }]

SendNotification

描述

手动发送测试通知到指定渠道或全部渠道。选择部分渠道时在其他客户端注册的回调等。

系统事件通知由服务端自动广播,无需手动调用此 RPC。

Request — SendNotificationRequest

字段类型编号必填描述
event_typestring1事件类型(如 "order_paid", "test"
titlestring2通知标题
bodystring3通知正文
recipientstring4接收者(如邮箱地址,为空时使用渠道默认接收者)
metadatamap<string,string>5附加元数据
channel_idsrepeated string6目标渠道 ID 列表(空=全部渠道)

Response — SendNotificationResponse

字段类型编号描述
resultsrepeated NotificationResult1各渠道发送结果

NotificationResult

字段类型编号描述
channel_idstring1渠道 ID
successbool2是否发送成功
error_messagestring3错误信息(失败时)

错误码

错误说明
InvalidArgumentevent_type 或 title 为空
PermissionDenied非 admin 用户

示例

grpcurl -plaintext -H "authorization: Bearer <token>" \
  -d '{"event_type":"test","title":"测试通知","body":"这是一条测试消息","recipient":"[email protected]","metadata":{},"channel_ids":[]}' \
  localhost:50051 rustbill.notification.NotificationService/SendNotification
const resp = await api.sendNotification({
  event_type: "test",
  title: "测试通知",
  body: "这是一条测试消息",
  recipient: "[email protected]",
  metadata: {},
  channel_ids: []
});
// resp.results → [{ channel_id, success, error_message }]

系统事件通知

以下事件会触发系统自动广播通知到所有已启用的通知渠道:

事件类型触发时机接收者
order_paid订单支付成功客户邮箱 + 管理员通知邮箱
order_provisioned资源开通完成客户邮箱
order_cancelled订单取消(含退款)客户邮箱
ticket_assigned工单分配处理人新旧处理人
ticket_replied工单有新的公开回复工单创建者