diff options
Diffstat (limited to 'vnext/server/durov.js')
-rw-r--r-- | vnext/server/durov.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vnext/server/durov.js b/vnext/server/durov.js new file mode 100644 index 00000000..0f70133d --- /dev/null +++ b/vnext/server/durov.js @@ -0,0 +1,33 @@ +import TelegramBot from 'node-telegram-bot-api'; +import debug from 'debug'; +var log = debug('durov'); +import config from 'config'; + + +import { formatMessage, formatQuote, formatTitle } from './common/MessageUtils'; +import { format } from '../src/utils/embed'; + +const sender = new TelegramBot(config.get('service.durov.token'), { polling: true }); +const demouser = config.get('service.durov.demouser'); + +sender.on('message', msg => { + log(`MESSAGE: ${JSON.stringify(msg)}`); +}); + +/** + * @param {import('../src/api').Message} msg + * @param {string[]} subscribers + */ +export const sendTelegramNotification = (msg, subscribers) => { + log(`Telegram event: ${JSON.stringify(msg)}, ${subscribers} ${subscribers.length}`); + if (!msg.service) { + if (subscribers && subscribers.includes(demouser)) { + const message = `${formatTitle(msg)}\n${formatQuote(msg)}\n${format(msg.body, msg.uid, false)}`; + log(message); + sender.sendMessage(demouser, message, { + parse_mode: 'HTML', + disable_web_page_preview: true + }).then(log).catch(log); + } + } +}; |