-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (54 loc) · 1.67 KB
/
app.js
File metadata and controls
59 lines (54 loc) · 1.67 KB
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
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 = '679049668:AAFNpJ_pdsp55MV7-BYJ2KISZrjECbU5ddQ';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
// Matches "/echo [whatever]"
bot.onText(/\/course/, (msg, match) => {
const chatId = msg.chat.id;
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 (error, 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'});
})
})