-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
79 lines (68 loc) · 2.21 KB
/
app.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
const TelegramBot = require('node-telegram-bot-api');
const request = require('request');
// replace the value below with the Telegram token you receive from @BotFather
const token = '765967396:AAHp8wOEmBhyl4wQo1pA2L-1jFy8Ws0tpCo';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
// Matches "/echo [whatever]"
bot.onText(/\/curse/, (msg, match) => {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message
const chatId = msg.chat.id;
// const resp = match[1]; // the captured "whatever"
// send back the matched "whatever" to the chat
bot.sendMessage(chatId, 'Какая валюта вас интересует', {
reply_markup: {
inline_keyboard: [
[
{
text: '€ - EUR',
callback_data: 'EUR'
},
{
text: '$ - USD',
callback_data: 'USD'
},
{
text: '₽ - RUR',
callback_data: 'RUR'
},
{
text: '₿ - BTC',
callback_data: 'BTC'
}
]
]
}
});
});
bot.on('callback_query', query => {
const id = query.message.chat.id;
request('https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5', function (err, response, body) {
const data = JSON.parse(body);
const result = data.filter(item => item.ccy === query.data)[0];
const flag = {
'EUR': '🇪🇺',
'USD': '🇺🇸',
'RUR': '🇷🇺',
'UAH': '🇺🇦',
'BTC': '₿'
};
let md = `
*${flag[result.ccy]} ${result.ccy} 💱 ${result.base_ccy} ${flag[result.base_ccy]}*
Buy: _${result.buy}_
Sale: _${result.sale}_
`;
bot.sendMessage(id, md, {parse_mode: 'Markdown'});
});
});
// // Listen for any kind of message. There are different kinds of
// // messages.
// bot.on('message', (msg) => {
// const chatId = msg.chat.id;
// // send a message to the chat acknowledging receipt of their message
// bot.sendMessage(chatId, 'Received your message');
// });
//https://github.com/yagop/node-telegram-bot-api
//https://api.privatbank.ua/#p24/exchange