This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 1.44 KB
/
index.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
const Telebot = require('telebot');
require('dotenv').config();
const bot = new Telebot({
token: process.env.TELEGRAM_TOKEN,
polling: { // Optional. Use polling.
interval: 1000, // Optional. How often check updates (in ms).
timeout: 0, // Optional. Update polling timeout (0 - short polling).
limit: 100, // Optional. Limits the number of updates to be retrieved.
retryTimeout: 5000, // Optional. Reconnecting timeout (in ms).
},
webhook: (process.env.PORT != null ? { // When running in localhost, webhooks are disabled
port: process.env.PORT || 8443,
host: process.env.HOST,
url: process.env.URL
} : null)
})
//
compileMessage = require("./messages");
bot.on("/start", (msg, props) => {
let m = compileMessage({type: "hello"})
return bot.sendMessage(msg.chat.id, m.message, {replyMarkup: m.inlineKeyboard, notification: false});
});
bot.on("callbackQuery", (msg, props) => {
// Multiple message types but it deletes the original message
if (msg.data == "hello" || msg.data == "tellme" || msg.data == "courses" || /^course\.([a-z0-9]+)(\[[a-z]+\])?$/.test(msg.data) || msg.data == "calendar") {
let m = compileMessage({type: msg.data});
bot.deleteMessage(msg.message.chat.id, msg.message.message_id).catch(e => console.error(e));
return bot.sendMessage(msg.message.chat.id, m.message, {replyMarkup: m.inlineKeyboard, parseMode: "Markdown", webPreview: false, notification: false})
}
})
bot.start();