-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (36 loc) · 1.07 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
require('dotenv').config();
const { Telegraf } = require('telegraf');
const { message } = require('telegraf/filters');
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.command('quit', async (ctx) => {
// Explicit usage
await ctx.telegram.leaveChat(ctx.message.chat.id);
// Using context shortcut
await ctx.leaveChat();
});
bot.on(message('text'), async (ctx) => {
// Explicit usage
await ctx.telegram.sendMessage(
ctx.message.chat.id,
`Hello ${ctx.state.role}`
);
// Using context shortcut
await ctx.reply(`Hello ${ctx.state.role}`);
});
bot.on('callback_query', async (ctx) => {
// Explicit usage
await ctx.telegram.answerCbQuery(ctx.callbackQuery.id);
// Using context shortcut
await ctx.answerCbQuery();
});
bot.on('inline_query', async (ctx) => {
const result = [];
// Explicit usage
await ctx.telegram.answerInlineQuery(ctx.inlineQuery.id, result);
// Using context shortcut
await ctx.answerInlineQuery(result);
});
bot.launch();
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));