egg-dingtalk-robot-plugin
v0.2.1
Published
Egg.js DingTalk Robot
Downloads
4
Readme
egg-dingtalk-robot-plugin
Install
$ npm i egg-dingtalk-robot-plugin --save
Usage
// {app_root}/config/plugin.js
exports.dingtalkRobot = {
enable: true,
package: 'egg-dingtalk-robot-plugin',
};
Configuration
// {app_root}/config/config.default.js
exports.dingtalkRobot = {
// multiple robots
robots: {
demoRobot: {
baseUrl: 'https://oapi.dingtalk.com/robot/send',
// 机器人的accessToken
accessToken: 'accessToken',
// 使用签名验证时需要用到的secret
secret: 'secret',
},
}
};
// {app_root}/app/router.js
app.get('/send', async funtion() {
// 消息类型参考钉钉文档:https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
const data = {
"msgtype": "markdown",
"markdown": {
"title":"杭州天气",
"text": "#### 杭州天气 @150XXXXXXXX \n> 9度,西北风1级,空气良89,相对温度73%\n> ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n> ###### 10点20分发布 [天气](https://www.dingtalk.com) \n"
},
"at": {
"atMobiles": [
"150XXXXXXXX"
],
"isAtAll": false
}
}
this.body = await this.app.dingtalkRobot.get('demoRobot').send(data)
})