-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (59 loc) · 1.99 KB
/
Copy pathindex.js
File metadata and controls
72 lines (59 loc) · 1.99 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
60
61
62
63
64
65
66
67
68
69
70
71
72
const dotenv = require('dotenv');
dotenv.config({ path: `./config.env` });
const { Telegraf } = require('telegraf');
const WAValidator = require('wallet-address-validator');
const botView = require('./view/botView');
const { crypto } = require('./helpers');
const {
getTrx,
currentUser,
currentAddress,
currentUserAndAddress,
confirmedTrx,
} = require('./model/model');
let bot = new Telegraf(process.env.BOT_TOKEN);
if (process.env.NODE_ENV === 'production') {
const API_TOKEN = process.env.API_TOKEN || '';
const PORT = process.env.PORT || 3000;
const URL = process.env.URL || 'https://your-heroku-app.herokuapp.com';
// bot = new Telegraf(API_TOKEN);
bot.telegram.setWebhook(`${URL}/bot${API_TOKEN}`);
bot.startWebhook(`/bot${API_TOKEN}`, null, PORT);
}
let address;
bot.start(botView.startHandler);
// bot.command("help", botView.helpHandler);
bot.on('sticker', botView.stickerHandler);
bot.command('checkbtcstatus', (ctx) => {
ctx.reply(botView.replyMessage());
bot.on('text', async (textCtx) => {
address = textCtx.update.message.text;
const firstName = textCtx.update.message.from.first_name;
const lastName = textCtx.update.message.from.last_name;
let replyName = '';
if (firstName || lastName) {
replyName = `${firstName ? firstName : ''}${
lastName ? ` ${lastName}` : ''
}`;
}
const valid = WAValidator.validate(`${address}`, `${crypto}`);
if (!valid)
return textCtx.reply(
`${botView.replyInvalidAddress()}\n\n${botView.replyMessage()} `
);
await getTrx(address);
const confirmedTrxs = confirmedTrx();
const unconfirmedTRX = currentUserAndAddress(
textCtx.update.message.from.username,
address
);
// currentUser = textCtx.update;
textCtx.reply(
botView.replyTrxStatusText(replyName, unconfirmedTRX, confirmedTrxs),
botView.replyTrxStatusInline()
);
// console.log(ctx.update.message.text);
});
});
bot.launch();
console.log('Bot connected Successfully');