forked from Kenshin/simpread-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (104 loc) · 2.83 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const axios = require( 'axios' );
/**
* Get now time
*
* @return {string} return now, e.g. 2017年04月03日 11:43:53
*/
function now() {
const date = new Date(),
format = value => value = value < 10 ? '0' + value : value;
return date.getFullYear() + '/' + format( date.getUTCMonth() + 1 ) + '/' + format( date.getUTCDate() );
}
/**
* Get Simpread Unreader Daily
*/
function getDaily() {
const settings = {
method: 'POST',
url: 'https://simpread.ksria.cn/api/service/list',
params: {
token: process.env.SIMPREAD_TOKEN,
id: process.env.SIMPREAD_ID,
filter: 'daily'
}
},
urls = [];
axios( settings ).then( response => {
if ( response && response.data.length > 0 ) {
response.data.forEach( item => {
urls.push( `[${ item.title }](${ item.url })` );
});
if ( process.env.SEND_TYPE == 'telegram' ) sendTelegram( urls );
else if ( process.env.SEND_TYPE == 'feishu' ) sendFeishu( urls );
else {
sendTelegram( urls );
sendFeishu( urls );
}
}
}).catch( error => {
console.error( error );
});
}
/**
* Send Telegram
*
* @param {array} urls
*/
function sendTelegram( urls ) {
const text = `
▎ 简悦 · 每日回顾 ${ now() }
{{urls}}
来自 [简悦](http://simpread.pro/)`,
config = {
url : 'https://api-wrap.simpread.pro/api/service/telegram',
method : 'post',
data : {
chat : process.env.TELEGRAM_CHAT,
token: process.env.TELEGRAM_TOKEN,
text : text.replace( '{{urls}}', urls.join( '\n' ))
}
};
axios( config ).then( response => {
console.log( 'sendTelegram success ', response )
}).catch( error => {
console.log( 'sendTelegram error ', error )
});
}
/**
* Send Feishu
*
* @param {*} urls
*/
function sendFeishu( urls ) {
const body = {
"msg_type": "interactive",
"card": {
"config": {
"wide_screen_mode": true
},
"elements": [
{
"tag": "div",
"text": {
"content": urls.join( '\n' ),
"tag": "lark_md"
}
}],
"header": {
"template": "blue",
"title": {
"content": "简悦 · 每日回顾 " + now(),
"tag": "plain_text"
}
}
}
};
axios.post( process.env.FEISHU_TOKEN, body )
.then( response => {
console.log( 'sendFeishu success ', response )
})
.catch( error => {
console.log( 'sendFeishu error ', error )
})
}
getDaily();