-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
36 lines (30 loc) · 753 Bytes
/
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
const TelegramBot = require("node-telegram-bot-api");
class BOT {
constructor(tokne, charID, aduioHandler = () => {}) {
this.tokne = tokne;
this.charID = charID;
this.aduioHandler = aduioHandler;
this.bot = new TelegramBot(tokne, {
polling: true
});
this.bot.on("message", msg => {
const { voice } = msg;
if (voice) {
this.aduioHandler(voice.file_id, this.tokne);
}
});
}
sendPhotoToUser(photoData, caption) {
this.bot.sendPhoto(this.charID, photoData, {
caption
});
}
sendTextToUser(msg) {
this.bot.sendMessage(this.charID, msg);
}
registerRoute(route, handlerCb) {
this.bot.onText(route, handlerCb);
return this;
}
}
module.exports.BOT = BOT;