-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtelegram.js
More file actions
29 lines (25 loc) · 830 Bytes
/
telegram.js
File metadata and controls
29 lines (25 loc) · 830 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
'use strict';
const TelegramBot = require('node-telegram-bot-api');
const { logger, MessageError, getConfig, startApp } = require('./common.js');
const config = getConfig('./telegram_conf.json', './config.json');
// Telegram
const bot = new TelegramBot(config.telegram.token, {
polling: true,
});
bot.onText(/\/whois/, (msg) => {
if (config.telegram.whoisCommand) {
const chatId = msg.chat.id;
bot.sendMessage(chatId, `chatId = ${chatId}`).catch((err) => {
logger.error(`whois Error: `, err);
});
}
});
const app = startApp({
config,
sendMessage: (target, message) => bot.sendMessage(target, message).catch((err) => {
let d = err.response || {};
d = d.body || {};
d = d.description || '';
throw new MessageError(d, err.code);
}),
});