-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.js
55 lines (50 loc) · 1.21 KB
/
notify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const axios = require("axios");
const crypto = require("crypto");
const config = require("./config");
async function notify(content) {
if (!config.dingtalk) {
return;
}
let timestamp = (+new Date()).toString();
let signStr = timestamp + "\n" + config.dingtalk.key;
let sign = crypto
.createHmac("sha256", config.dingtalk.key)
.update(signStr)
.digest("base64");
try {
await axios.post(config.dingtalk.url, content, {
params: {
timestamp,
sign,
},
});
} catch (e) {
console.log(e);
}
}
exports.sendStart = function (room) {
notify({
msgtype: "text",
text: {
content: `[录制开始]\n已开始录制${room.uname}的直播间${room.roomId},当前标题为${room.title}。`,
},
});
};
exports.sendEnd = function (room) {
notify({
msgtype: "text",
text: {
content: `[录制结束]\n${room.uname}的直播间${room.roomId},,本次录制已正常结束。`,
},
});
};
exports.sendError = function (room, error) {
notify({
msgtype: "text",
text: {
content: `[录制出错]\n${room.uname}的直播间${
room.roomId
},本次录制出现错误。\n${error.stack || error}`,
},
});
};