forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpoll-bot.js
More file actions
31 lines (25 loc) · 782 Bytes
/
poll-bot.js
File metadata and controls
31 lines (25 loc) · 782 Bytes
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
const Telegraf = require('telegraf')
const { Extra, Markup } = Telegraf
const keyboard = Markup.keyboard([
Markup.pollRequestButton('Create poll', 'regular'),
Markup.pollRequestButton('Create quiz', 'quiz')
])
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.on('poll', (ctx) => console.log('Poll update', ctx.poll))
bot.on('poll_answer', (ctx) => console.log('Poll answer', ctx.pollAnswer))
bot.start((ctx) => ctx.reply('supported commands: /poll /quiz', Extra.markup(keyboard)))
bot.command('poll', (ctx) =>
ctx.replyWithPoll(
'Your favorite math constant',
['x', 'e', 'π', 'φ', 'γ'],
{ is_anonymous: false }
)
)
bot.command('quiz', (ctx) =>
ctx.replyWithQuiz(
'2b|!2b',
['True', 'False'],
{ correct_option_id: 0 }
)
)
bot.launch()