-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
37 lines (31 loc) · 888 Bytes
/
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
const http = require('http');
const axios = require('axios');
const localconf = require('./local.js');
exports.helloBot = (req, res) => {
function sendMessage(options) {
const token = localconf.telegramToken;
const url = `https://api.telegram.org/bot${token}/sendMessage`;
axios.post(url, {
chat_id: options.chatId,
text: options.greetings
})
.then(function (response) {
res.send({ status: 'OK'});
})
.catch(function (error) {
res.sendStatus(500);
});
}
const callToken = req.path;
if ( callToken !== localconf.webhookToken ) {
const message = req.body.message;
console.log(JSON.stringify(req.body));
const options = {
greetings: `Hello ${message.from.first_name} ${message.from.last_name}!`,
chatId: message.chat.id
};
sendMessage(options);
} else {
res.sendStatus(403);
}
};