Pipedream + Server酱:工作流触发事件推送到微信
效果:Pipedream 工作流被触发时,自动将事件数据推送到微信
前置条件
- 获取 Server酱 SendKey(30 秒获取教程)
- 拥有 Pipedream 账号及一个已创建的工作流
配置步骤
-
在 Pipedream 的环境变量/Secrets 设置中,添加一个变量,名称设为
SERVERCHAN_SENDKEY,值为你的 SendKey。不要将 SendKey 硬编码在代码中。 -
在你的 Pipedream 工作流中,按需选择触发器,然后添加一个 Node.js 代码步骤。
-
在代码步骤中粘贴以下代码,使用
fetch向 Server酱 API 发送 POST 请求:
export default defineComponent({
async run({ steps, $ }) {
const sendKey = process.env.SERVERCHAN_SENDKEY;
// 从前序步骤提取数据拼 title/desp
const title = steps.trigger.event.body?.subject || "Pipedream 触发通知";
const desp = `触发事件数据:\n\n${JSON.stringify(steps.trigger.event, null, 2)}`;
await fetch(`https://sctapi.ftqq.com/${sendKey}.send`, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ title, desp }),
});
},
})
- 部署并测试工作流。Server酱 支持推送到微信服务号/企业微信/钉钉/飞书等多个通道,详见 /getting-started/channels/。
完整示例
以下是一个包含错误处理与返回值校验的完整 Node.js 代码步骤示例,将前序步骤的具体数据拼接为 Markdown 正文:
export default defineComponent({
async run({ steps, $ }) {
const sendKey = process.env.SERVERCHAN_SENDKEY;
const event = steps.trigger.event;
const title = `新事件:${event.body?.name || event.type}`;
const desp = `### 事件详情\n\n- 触发时间:${event.ts}\n- 数据内容:${event.body?.message || '无'}`;
const resp = await fetch(`https://sctapi.ftqq.com/${sendKey}.send`, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ title, desp }),
});
const result = await resp.json();
if (result.code !== 0) {
throw new Error(`推送失败: ${result.message}`);
}
return result;
},
})
如果你的 SendKey 以 sctp 开头,API 端点需改为 https://你的UID.push.ft07.com/send/${sendKey}.send,其中 UID 取自 sctp 后的数字。
常见问题
Server酱的发送额度是多少? 免费用户每天可发送 5 条,每分钟上限 50 条。订阅会员目前特价最低 3 元/月,一天最多可发 1000 条(价格详情)。
工作流执行成功但微信没收到消息?
请先检查 Pipedream 代码步骤的运行日志,确认 HTTP 请求返回的 code 是否为 0。如果返回成功但未收到,请参考常见问题与排查。
如何控制消息推送频率? 可以在 Pipedream 工作流的触发器中设置过滤条件,或在代码步骤中加入节流逻辑,避免触发 Server酱 的每分钟 50 条限制。
相关集成
- /integrations/python/ —— Python 脚本推送
- /integrations/qinglong/ —— 青龙面板任务通知
- /integrations/uptime-kuma/ —— Uptime Kuma 宕机告警