@bytesurging/notify
v0.1.0
Published
Server-side notify helpers for Feishu / Lark / WeCom webhooks
Readme
@bytesurging/notify
服务端 / CI 通知库:向群机器人发 文本或卡片。当前渠道:
| 渠道 | 语法糖 | 底层 API | Host |
|------|--------|----------|------|
| 飞书 | notify.feishu() | sendFeishu | open.feishu.cn |
| Lark | notify.lark() | sendLark | open.larksuite.com |
| 企业微信 | notify.wecom() | sendWecom | qyapi.weixin.qq.com |
个人微信无开放群 webhook;「微信」指企业微信(别名
wx)。
安装
npm i @bytesurging/notifyNode >=18。支持 import / require。
服务端:文本 & 卡片
import { notify } from "@bytesurging/notify";
const bot = notify.feishu({
id: process.env.FEISHU_ID!,
secret: process.env.FEISHU_SECRET!,
});
// 文本
await bot.text("deploy ok");
// 卡片(飞书 → interactive;企微 → template_card)
await bot.card({
title: "发布完成",
subtitle: "maganl-basic-server-prod",
content: "生产环境已更新",
color: "green",
emphasis: { title: "1.2.3", subtitle: "版本" },
fields: [
{ label: "执行人", value: "alex" },
{ label: "环境", value: "prod" },
],
links: [{ title: "健康检查", url: "https://api.maganl.com/v1/health" }],
url: "https://api.maganl.com/v1/health",
});
await notify.lark({ id, secret }).card({ title: "Done", content: "ok" });
await notify.wecom({ key }).card({ title: "Done", content: "ok" });
// 统一入口
await notify.send({
channel: "feishu",
id,
secret,
card: { title: "发布完成", emphasis: { title: "1.2.3" } },
});原生完整 payload 仍可用 bot.send(raw) / --message。
GitHub Actions
兼容 lusun 的 --message,也可用 --card / --text:
- name: Feishu Notify
env:
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
FEISHU_ID: ${{ secrets.FEISHU_ID }}
FEISHU_SECRET: ${{ secrets.FEISHU_SECRET }}
run: |
npx --yes @bytesurging/notify feishu \
--id "$FEISHU_ID" \
--secret "$FEISHU_SECRET" \
--card "{\"title\":\"发布完成\",\"subtitle\":\"maganl-basic-server-prod\",\"color\":\"green\",\"emphasis\":{\"title\":\"${PACKAGE_VERSION}\",\"subtitle\":\"版本\"},\"fields\":[{\"label\":\"执行人\",\"value\":\"${GITHUB_ACTOR}\"}],\"links\":[{\"title\":\"健康检查\",\"url\":\"https://api.maganl.com/v1/health\"}],\"url\":\"https://api.maganl.com/v1/health\"}"卡片字段(统一语法糖)
| 字段 | 说明 |
|------|------|
| title | 标题(必填) |
| subtitle | 副标题 |
| content | 正文(飞书按 markdown) |
| color | 飞书 header 颜色(green / red / blue…) |
| emphasis | 强调区,如版本号 { title, subtitle? } |
| fields | 键值行 [{ label, value }] |
| links | 按钮/跳转 [{ title, url }] |
| url | 整卡点击跳转 |
映射:
- 飞书 / Lark →
msg_type: interactive - 企微 →
msgtype: template_card(text_notice)
兼容 lusun-scripts
import { sendFeishu, feishu } from "@bytesurging/notify";
await sendFeishu({
id, // 或 feishuId
secret, // 或 feishuSecret
message: '{"msg_type":"text","content":{"text":"ok"}}',
});环境变量
| 渠道 | 变量 |
|------|------|
| 飞书 | FEISHU_ID, FEISHU_SECRET |
| Lark | LARK_ID, LARK_SECRET |
| 企微 | WECOM_KEY(或 WECHAT_KEY), WECOM_SECRET(可选) |
