forked from gropox/telegolos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegram.js
68 lines (50 loc) · 1.52 KB
/
telegram.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
const m = require("./messages");
var TeleBot = require("telebot");
const ga = require("golos-addons");
const global = ga.global;
const CONFIG = global.CONFIG;
const log = global.getLogger("telegram");
let bot = null;
function buildMenuKbd() {
return bot.inlineKeyboard([
[bot.inlineButton(m.telegolos.transferMenu(), { callback: m.telegolos.transferMenu() })],
]);
}
module.exports.buildMenuKbd = buildMenuKbd;
async function send(chat_id, msg, kbd) {
let opts = { parse: "Markdown" };
log.debug("msg", msg);
log.debug("kbd", kbd);
if (kbd) {
opts.markup = kbd;
}
return bot.sendMessage(chat_id, msg, opts)
}
async function defaultMsgHandler(msg) {
}
module.exports.send = send;
module.exports.sendConfirm = (chat_id, msg) => {
let kbd = bot.inlineKeyboard([
[bot.inlineButton(m.telegolos.yes(), { callback: m.telegolos.yes() }), bot.inlineButton(m.telegolos.no(), { callback: m.telegolos.no() })],
]);
send(chat_id, msg, kbd);
}
module.exports.init = function (onMsg, onCallback) {
bot = new TeleBot({
token: CONFIG.token,
polling: {
interval: 1000, // Optional. How often check updates (in ms).
timeout: 60,
limit: 100, //updates
retryTimeout: 5000
},
usePlugins: ['commandButton']
});
bot.on('text', onMsg);
// Button callback
bot.on('callbackQuery', (msg) => {
onCallback(msg);
bot.answerCallbackQuery(msg.id);
});
bot.connect();
}