-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
39 lines (31 loc) · 1.05 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
const { Telegraf, Markup } = require('telegraf');
const p2p = require('./bot.js');
var config = require('./config.json');
const bot = new Telegraf(config.Telegram.token);
if (config.Telegram.token === undefined) {
throw new Error('BOT_TOKEN must be provided!')
}
bot.use(Telegraf.log())
bot.command('/start', async (ctx) => {
return await ctx.reply('Привет! Это бот для поиска выгодных сделок', Markup
.keyboard([
['Start', 'Stop'],
['help']
])
.oneTime()
.resize()
)
})
bot.hears('Start', ctx => {
p2p.start();
ctx.telegram.sendMessage(Number(config.Telegram.chatId), "Bot is start");
} )
bot.hears('Stop', ctx => {p2p.stop()} )
let sendMessage = function(message) {
bot.telegram.sendMessage( Number(config.Telegram.chatId), message);
}
bot.launch();
module.exports.sendMessage = sendMessage;
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))