-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathtelegram.js
More file actions
35 lines (30 loc) · 972 Bytes
/
telegram.js
File metadata and controls
35 lines (30 loc) · 972 Bytes
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
'use strict'
const axios = require('axios')
let apiKey
let channelId
function setup(options = global.CONFIG) {
const { TELEGRAM_API_KEY, TELEGRAM_CHANNEL_ID } = options || {}
// console.log('TELEGRAM_API_KEY, TELEGRAM_CHANNEL_ID', TELEGRAM_API_KEY, TELEGRAM_CHANNEL_ID)
apiKey = TELEGRAM_API_KEY
channelId = TELEGRAM_CHANNEL_ID
}
async function sendChannelMsg(text) {
try {
return await axios.get('https://api.telegram.org/bot' + apiKey + '/sendMessage?chat_id=' + channelId + '&text=' + text) //NOSONAR { id, date, pts, seq }
} catch (e) {
return { err: e.toString() }
}
}
async function sendChatMsg(chatId, text) {
try {
// console.log('chatId, text', chatId, text)
return await axios.get('https://api.telegram.org/bot' + apiKey + '/sendMessage?chat_id=' + chatId + '&text=' + text) //NOSONAR { id, date, pts, seq }
} catch (e) {
return { err: e.toString() }
}
}
module.exports = {
setup,
sendChannelMsg,
sendChatMsg
}