项目: 写一个企业微信/weixin/robot的周报提醒
每周要提交周报,为了到点提醒,所以做了一个机器人提醒
添加机器人
这个只有群主才有这个权限,可以轻松添加一个机器人。
获取 webhook
其实这里只要一个
key
就可以了。
相关的测试
### post a message
POST https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOU_KEY
Content-Type: application/json
{
"msgtype": "text",
"text": { "content": "hello world" }
}
### picture news
POST https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOU_KEY
Content-Type: application/json
{
"msgtype": "news",
"news": {
"articles": [
{
"title": "写周报啦!",
"description": "别忘记填写本周的周报哦",
"url": "https://demo.abc.cn/pages",
"picurl": "https://tva1.sinaimg.cn/mw690/008vxvgGgy1h8qi9gzpx8j31eu0u0go2.jpg"
}
]
}
}
nodejs
实现
#!/usr/bin/env ndoe
const fetch = require('node-fetch');
const headers = { 'Content-Type': 'application/json' };
const WEEKLY_MSG = {
msgtype: 'news',
news: {
articles: [
{
title: '写周报啦!',
description: '别忘记填写本周的周报哦',
url: 'https://confluence.alo7.cn/pages/viewpage.action?pageId=79864982',
picurl: 'https://tva1.sinaimg.cn/mw690/008vxvgGgy1h8qi9gzpx8j31eu0u0go2.jpg',
},
],
},
};
function main() {
const wecom_key = process.env.WECOM_HOOK_KEY_WEEKLY;
const robotUrl = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${wecom_key}`;
fetch(robotUrl, { method: 'POST', headers, body: JSON.stringify(WEEKLY_MSG) });
}
main();
添加 crontab
任务
30 5 * * 5 "cd /root/xxx/mp-project && node src/app.js" > /dev/null