forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard-bot.js
121 lines (104 loc) · 3.21 KB
/
keyboard-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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.use(Telegraf.log())
bot.command('onetime', ({ reply }) =>
reply('One time keyboard', Markup
.keyboard(['/simple', '/inline', '/pyramid'])
.oneTime()
.resize()
.extra()
)
)
bot.command('custom', ({ reply }) => {
return reply('Custom buttons keyboard', Markup
.keyboard([
['🔍 Search', '😎 Popular'], // Row1 with 2 buttons
['☸ Setting', '📞 Feedback'], // Row2 with 2 buttons
['📢 Ads', '⭐️ Rate us', '👥 Share'] // Row3 with 3 buttons
])
.oneTime()
.resize()
.extra()
)
})
bot.hears('🔍 Search', ctx => ctx.reply('Yay!'))
bot.hears('📢 Ads', ctx => ctx.reply('Free hugs. Call now!'))
bot.command('special', (ctx) => {
return ctx.reply('Special buttons keyboard', Extra.markup((markup) => {
return markup.resize()
.keyboard([
markup.contactRequestButton('Send contact'),
markup.locationRequestButton('Send location')
])
}))
})
bot.command('pyramid', (ctx) => {
return ctx.reply('Keyboard wrap', Extra.markup(
Markup.keyboard(['one', 'two', 'three', 'four', 'five', 'six'], {
wrap: (btn, index, currentRow) => currentRow.length >= (index + 1) / 2
})
))
})
bot.command('simple', (ctx) => {
return ctx.replyWithHTML('<b>Coke</b> or <i>Pepsi?</i>', Extra.markup(
Markup.keyboard(['Coke', 'Pepsi'])
))
})
bot.command('inline', (ctx) => {
return ctx.reply('<b>Coke</b> or <i>Pepsi?</i>', Extra.HTML().markup((m) =>
m.inlineKeyboard([
m.callbackButton('Coke', 'Coke'),
m.callbackButton('Pepsi', 'Pepsi')
])))
})
bot.command('random', (ctx) => {
return ctx.reply('random example',
Markup.inlineKeyboard([
Markup.callbackButton('Coke', 'Coke'),
Markup.callbackButton('Dr Pepper', 'Dr Pepper', Math.random() > 0.5),
Markup.callbackButton('Pepsi', 'Pepsi')
]).extra()
)
})
bot.command('caption', (ctx) => {
return ctx.replyWithPhoto({ url: 'https://picsum.photos/200/300/?random' },
Extra.load({ caption: 'Caption' })
.markdown()
.markup((m) =>
m.inlineKeyboard([
m.callbackButton('Plain', 'plain'),
m.callbackButton('Italic', 'italic')
])
)
)
})
bot.hears(/\/wrap (\d+)/, (ctx) => {
return ctx.reply('Keyboard wrap', Extra.markup(
Markup.keyboard(['one', 'two', 'three', 'four', 'five', 'six'], {
columns: parseInt(ctx.match[1])
})
))
})
bot.action('Dr Pepper', (ctx, next) => {
return ctx.reply('👍').then(() => next())
})
bot.action('plain', async (ctx) => {
await ctx.answerCbQuery()
await ctx.editMessageCaption('Caption', Markup.inlineKeyboard([
Markup.callbackButton('Plain', 'plain'),
Markup.callbackButton('Italic', 'italic')
]))
})
bot.action('italic', async (ctx) => {
await ctx.answerCbQuery()
await ctx.editMessageCaption('_Caption_', Extra.markdown().markup(Markup.inlineKeyboard([
Markup.callbackButton('Plain', 'plain'),
Markup.callbackButton('* Italic *', 'italic')
])))
})
bot.action(/.+/, (ctx) => {
return ctx.answerCbQuery(`Oh, ${ctx.match[0]}! Great choice`)
})
bot.launch()