Mosaic CLI 文档 EN

Channels

Channels 模块:一步一步教程

用于把消息稳定投递到终端或外部渠道。先跑 terminal,再接入 Slack/Telegram。

步骤 1:查看支持的通道类型

mosaic --project-state channels capabilities
mosaic --project-state channels resolve --channel terminal local

步骤 2:添加 terminal 通道(无需凭证)

mosaic --project-state channels add --name local-terminal --kind terminal
mosaic --project-state channels list
mosaic --project-state channels status

步骤 3:验证投递链路

mosaic --project-state channels test <channel_id>
mosaic --project-state channels send <channel_id> --text "channels tutorial ok"
mosaic --project-state channels logs --channel <channel_id> --tail 20
mosaic --project-state channels logs --channel <channel_id> --tail 20 --summary

步骤 4:添加 Slack Webhook 通道

mosaic --project-state channels add \
  --name team-slack \
  --kind slack_webhook \
  --endpoint https://hooks.slack.com/services/XXX/YYY/ZZZ \
  --token-env MOSAIC_SLACK_BEARER

mosaic --project-state channels test <slack_channel_id>

token 只从环境变量读取,endpoint 固化在 channel 配置中。

步骤 5:添加 Telegram Bot 通道

export MOSAIC_TELEGRAM_BOT_TOKEN=<your_bot_token>

mosaic --project-state channels add \
  --name team-telegram \
  --kind telegram_bot \
  --chat-id <chat_id> \
  --token-env MOSAIC_TELEGRAM_BOT_TOKEN

mosaic --project-state channels test <telegram_channel_id>
mosaic --project-state channels send <telegram_channel_id> --text "telegram send ok"

步骤 6:更新默认模板与凭证引用

mosaic --project-state channels update <channel_id> --name ops-primary
mosaic --project-state channels update <channel_id> --default-title "Mosaic Alert"
mosaic --project-state channels login <channel_id> --token-env MOSAIC_NEW_TOKEN
mosaic --project-state channels rotate-token-env --all --to MOSAIC_NEW_TOKEN

步骤 7:导出与导入 channel 注册表

mosaic --project-state channels export --out channels-backup.json
mosaic --project-state channels import --file channels-backup.json --dry-run
mosaic --project-state channels import --file channels-backup.json --replace

步骤 8:下线与清理

mosaic --project-state channels logout <channel_id>
mosaic --project-state channels remove <channel_id>

运维验收清单

  • channels test 在主通道上成功。
  • channels send 事件日志无持续错误。
  • channels status 显示健康通道统计。
  • channels logs --summary 显示成功/失败分布符合预期。
  • channels logs 可追踪完整投递过程。