-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 942 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 942 Bytes
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
const TelegramBot = require('node-telegram-bot-api');
const schedule = require('./schedule-to-calendar')
var fs = require('fs');
const drive = require('./google-drive');
const TOKEN_PATH = 'data/telegram-token.json';
const bot = new TelegramBot(JSON.parse(fs.readFileSync(TOKEN_PATH)).token, {
polling: true,
});
bot.onText(/^(?!\/schedule).*$/, (msg) => {
bot.sendMessage(msg.chat.id, 'Запрос /schedule номер_группы или /schedule ФИО_преподавателя');
});
bot.onText(/\/schedule (.+)/, async function (msg, match) {
const name = match[1].trim()
try {
const path = await schedule.getSchedule(name);
const text = 'Расписание для ' + name;
drive.sendMessage(path, (url) => bot.sendMessage(msg.chat.id, text, {
reply_markup: JSON.stringify({
inline_keyboard: [[{ text: 'Скачать', url: url }]]
})
}));
} catch(err) {
bot.sendMessage(msg.chat.id, err);
}
});