forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKittyBot.js
More file actions
73 lines (55 loc) · 1.69 KB
/
KittyBot.js
File metadata and controls
73 lines (55 loc) · 1.69 KB
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
/*
KittyBot
Shows random Kitty pictures and gifs.
*/
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
// Great API for this bot
const API = 'https://thecatapi.com/api/images/get?format=src&type=';
// Command keyboard
const replyMarkup = bot.keyboard([
['/kitty', '/kittygif']
], {resize: true, once: false});
// Log every text message
bot.on('text', function (msg) {
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
});
// On command "start" or "help"
bot.on(['/start', '/help'], function (msg) {
return bot.sendMessage(msg.chat.id,
'😺 Use commands: /kitty, /kittygif and /about', {replyMarkup}
);
});
// On command "about"
bot.on('/about', function (msg) {
let text = '😽 This bot is powered by TeleBot library ' +
'https://github.com/kosmodrey/telebot Go check the source code!';
return bot.sendMessage(msg.chat.id, text);
});
// On command "kitty" or "kittygif"
bot.on(['/kitty', '/kittygif'], function (msg) {
let promise;
let id = msg.chat.id;
let cmd = msg.text.split(' ')[0];
// Photo or gif?
if (cmd == '/kitty') {
promise = bot.sendPhoto(id, API + 'jpg', {
fileName: 'kitty.jpg',
serverDownload: true
});
} else {
promise = bot.sendDocument(id, API + 'gif#', {
fileName: 'kitty.gif',
serverDownload: true
});
}
// Send "uploading photo" action
bot.sendAction(id, 'upload_photo');
return promise.catch(error => {
console.log('[error]', error);
// Send an error
bot.sendMessage(id, `😿 An error ${ error } occurred, try again.`);
});
});
// Start getting updates
bot.start();