-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
63 lines (49 loc) · 1.61 KB
/
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
const _ = require('lodash');
const TelegramBot = require('node-telegram-bot-api');
const config = require('./config');
const messageHandler = require('./messageHandler');
const bot = new TelegramBot(config.token, {polling: true});
bot.onText(/\/echo (.+)/, (msg, match) => {
// 'match' is the result of executing the regexp above on the text content
// of the message
const chatId = msg.chat.id;
const resp = match[1]; // the captured "whatever"
bot.sendMessage(chatId, resp);
});
bot.on('photo', (img) => {
const imgid = img.id;
/** criteria from earlier
* garish colours
* too much text
* reverse search images
* text that mentions BBC etc. **/
// do OCR one day
const ocr = messageHandler.ocr(img);
const outgoingMessage = messageHandler(ocr.text);
console.log(`Sending message: ${outgoingMessage}`);
bot.sendMessage(imgid, outgoingMessage);
});
bot.on('video', (v) => {
const vid = v.id;
});
bot.on('audio', (a) => {
const aid = a.id;
});
bot.on('text', (message) => {
console.log(message);
const chatId = message.chat.id;
const outgoingMessages = messageHandler.verify(message);
if (outgoingMessages.length > 0) {
let ms = outgoingMessages[0];
bot.sendMessage(chatId, ms.msg, {reply_to_message_id: ms.msgId})
// .then(bot.sendChatAction(chatId, 'typing'))
// .then(() => new Promise((resolve) => setTimeout(resolve, 0)))
.then(() => {
if (outgoingMessages[1]) {
let ms = outgoingMessages[1];
bot.sendMessage(chatId, ms.msg, {reply_to_message_id: ms.msgId})
}
})
}
});
module.exports = bot;