-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
87 lines (76 loc) · 2.18 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
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
80
81
82
83
84
85
86
87
const config = require('./config.json')
const rawRequest = require('./helpers')
const TelegramBot = require('node-telegram-bot-api')
const bot = new TelegramBot(config.token, { polling: true })
let callbackType,
currency = 'eur',
exchange = 'coinmarketcap'
bot.onText(/\/start|help/, message => {
bot.sendMessage(message.chat.id, `
/help - Get the list of all commands\n/btc - Get the current btc price\n/currency - Select the currency in which btc are converted\n/exchanger - Select the exchanger from the list\n/which_exchanger - View the current exchanger
`)
})
bot.onText(/\/which_exchanger/, message => {
bot.sendMessage(message.chat.id, exchange)
})
bot.onText(/\/btc/, message => {
rawRequest(exchange, currency)
.then(result => bot.sendMessage(message.chat.id, result))
.catch(error => bot.sendMessage(message.chat.id, error))
})
bot.onText(/\/exchanger/, message => {
callbackType = 'exchanger'
bot.sendMessage(message.chat.id, "Select exchanger", {
'reply_markup': {
'inline_keyboard': [
[{
'text': 'kraken',
'callback_data': 'kraken'
}],
[{
'text': 'coinmarketcap',
'callback_data': 'coinmarketcap'
}],
[{
'text': 'coinbase',
'callback_data': 'coinbase'
}],
[{
'text': 'bitcoinaverage',
'callback_data': 'bitcoinaverage'
}]
]
}
})
})
bot.onText(/\/currency/, message => {
callbackType = 'currency'
bot.sendMessage(message.chat.id, "Select currency", {
'reply_markup': {
'inline_keyboard': [
[{
'text': 'Euro (EUR)',
'callback_data': 'eur'
}],
[{
'text': 'US Dollar (USD)',
'callback_data': 'usd'
}],
[{
'text': 'Pound (GBP)',
'callback_data': 'gbp'
}],
]
}
})
})
bot.on('callback_query', query => {
if (callbackType === 'exchanger') {
bot.answerCallbackQuery(query.id, { text: 'Exchanger updated!' })
exchange = query.data
}
if (callbackType === 'currency') {
bot.answerCallbackQuery(query.id, { text: 'Currency updated!' })
currency = query.data
}
})