forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard-bot.js
46 lines (43 loc) · 1.25 KB
/
wizard-bot.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
const Telegraf = require('telegraf')
const Composer = require('telegraf/composer')
const session = require('telegraf/session')
const Stage = require('telegraf/stage')
const Markup = require('telegraf/markup')
const WizardScene = require('telegraf/scenes/wizard')
const stepHandler = new Composer()
stepHandler.action('next', (ctx) => {
ctx.reply('Step 2. Via inline button')
return ctx.wizard.next()
})
stepHandler.command('next', (ctx) => {
ctx.reply('Step 2. Via command')
return ctx.wizard.next()
})
stepHandler.use((ctx) => ctx.replyWithMarkdown('Press `Next` button or type /next'))
const superWizard = new WizardScene('super-wizard',
(ctx) => {
ctx.reply('Step 1', Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Markup.callbackButton('➡️ Next', 'next')
]).extra())
return ctx.wizard.next()
},
stepHandler,
(ctx) => {
ctx.reply('Step 3')
return ctx.wizard.next()
},
(ctx) => {
ctx.reply('Step 4')
return ctx.wizard.next()
},
(ctx) => {
ctx.reply('Done')
return ctx.scene.leave()
}
)
const bot = new Telegraf(process.env.BOT_TOKEN)
const stage = new Stage([superWizard], { default: 'super-wizard' })
bot.use(session())
bot.use(stage.middleware())
bot.launch()