-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.16 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
const api = require('./api')
var chat_id = null
var bot_token = null
var message_title = ''
function checkMessage(TOKEN, CHAT, message){
if(TOKEN !== undefined && TOKEN.length > 0 && CHAT !== undefined && CHAT.length > 0 && message !== undefined && Object.keys(message).length > 0){
message_title = message.title || ''
chat_id = CHAT
bot_token = TOKEN
delete message.title
createMsg(message)
}else{
console.error('Added function params!')
}
};
function createMsg(obj){
var message = `${message_title} %0A %0A`
var texts = ``
for (let i = 0; i < Object.keys(obj).length; i++) {
const text = ` - ${Object.keys(obj)[i]}: ${Object.values(obj)[i]} %0A`;
texts += text
}
message += texts
sendMessage(bot_token, chat_id, message)
}
async function sendMessage(TOKEN, CHAT, message){
try{
api.get(`bot${TOKEN}/sendMessage?chat_id=${CHAT}}&text=${message}`)
.then(res => {
console.log('Message successfully send.')
})
.catch(error => {
console.log(error)
})
} catch(error){
console.log(error)
}
}
module.exports = checkMessage