-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
62 lines (50 loc) · 1.51 KB
/
index.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
56
57
58
59
60
61
62
import https from 'https';
import dotenv from 'dotenv';
import { log } from '@moncici/log'
//SELL https://open.feishu.cn/open-apis/bot/v2/hook/79bfd342-***-***
//BUY https://open.feishu.cn/open-apis/bot/v2/hook/e7b3931f-******c
dotenv.config();
const BUY_ACCESS_TOKEN = process.env.BUY_ACCESS_TOKEN;
const SELL_ACCESS_TOKEN = process.env.SELL_ACCESS_TOKEN;
export function notify(direction, msg) {
let ACCESS_TOKEN = direction == 'BUY' ? BUY_ACCESS_TOKEN : SELL_ACCESS_TOKEN;
doNotify(ACCESS_TOKEN, `${direction} ${msg}`);
}
export function doNotify(accessToken, msg) {
const message = {
msg_type: 'text',
content: {
text: `${msg}`,
},
};
const options = {
hostname: 'open.feishu.cn',
path: `/open-apis/bot/v2/hook/${accessToken}`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const jsonData = JSON.parse(data);
if (jsonData.msg === 'success') {
log('消息发送成功');
} else {
// console.error('消息发送失败', jsonData.errmsg);
log('消息发送失败', jsonData.msg);
}
});
});
req.on('error', (error) => {
log(error);
});
req.write(JSON.stringify(message));
req.end();
}
// notify('SELL', " nice pirce")
// notify('BUY', " nice pirce")