forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.js
79 lines (58 loc) · 1.89 KB
/
keyboard.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
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
// On commands
bot.on(['/start', '/back'], msg => {
let replyMarkup = bot.keyboard([
['/buttons', '/inlineKeyboard'],
['/start', '/hide']
], {resize: true});
return bot.sendMessage(msg.from.id, 'Keyboard example.', {replyMarkup});
});
// Buttons
bot.on('/buttons', msg => {
let replyMarkup = bot.keyboard([
[bot.button('contact', 'Your contact'), bot.button('location', 'Your location')],
['/back', '/hide']
], {resize: true});
return bot.sendMessage(msg.from.id, 'Button example.', {replyMarkup});
});
// Hide keyboard
bot.on('/hide', msg => {
return bot.sendMessage(
msg.from.id, 'Hide keyboard example. Type /back to show.', {replyMarkup: 'hide'}
);
});
// On location on contact message
bot.on(['location', 'contact'], (msg, self) => {
return bot.sendMessage(msg.from.id, `Thank you for ${ self.type }.`);
});
// Inline buttons
bot.on('/inlineKeyboard', msg => {
let replyMarkup = bot.inlineKeyboard([
[
bot.inlineButton('callback', {callback: 'this_is_data'}),
bot.inlineButton('inline', {inline: 'some query'})
], [
bot.inlineButton('url', {url: 'https://telegram.org'})
]
]);
return bot.sendMessage(msg.from.id, 'Inline keyboard example.', {replyMarkup});
});
// Inline button callback
bot.on('callbackQuery', msg => {
// User message alert
return bot.answerCallbackQuery(msg.id, `Inline button callback: ${ msg.data }`, true);
});
// Inline query
bot.on('inlineQuery', msg => {
const query = msg.query;
const answers = bot.answerList(msg.id);
answers.addArticle({
id: 'query',
title: 'Inline Query',
description: `Your query: ${ query }`,
message_text: 'Click!'
});
return bot.answerQuery(answers);
});
bot.start();