-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataas.js
51 lines (40 loc) · 1.46 KB
/
cataas.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
const TelegaBot = require('telega-bot');
const bot = new TelegaBot('BOT ID!');
bot.start();
const API1 = 'https://cataas.com/cat';
const API2 = 'https://cataas.com/cat/gif';
// Log every text message
bot.on('text', function (msg) {
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
});
// On command "cataas" or "cataasgif"
bot.on(['/cataas', '/cataasgif'], function (msg) {
let promise;
let id = msg.chat.id;
let cmd = msg.text.split(' ')[0];
// Photo or gif?
if (cmd == '/cataas') {
promise = bot.sendPhoto(id, API1, {
fileName: 'cataas.jpg',
serverDownload: true
});
} else {
promise = bot.sendDocument(id, API2, {
fileName: 'cataas.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 occurred, try again later.\n${error.description}`);
});
});
bot.on('/start', (msg) => {
return msg.reply.text('Hey, Welcome to the Cataas Telegram Bot, Use /cataas or /cataasgif for pics and gifs!', { asReply: true });
});
bot.on('/help', (msg) => {
return msg.reply.text('Hey, Welcome to the Cataas Telegram Bot Help page,\nUse /cataas to get a cat image\nUse /cataasgif to get a cat gif', { asReply: true });
});