From d24c35089c11f86878e47f855bd5b6a4ef7e340e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 21 Jan 2023 00:45:21 +0300 Subject: durov: use webhook --- vnext/server/durov.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'vnext/server/durov.js') diff --git a/vnext/server/durov.js b/vnext/server/durov.js index acd89158..df33f743 100644 --- a/vnext/server/durov.js +++ b/vnext/server/durov.js @@ -7,13 +7,23 @@ import config from 'config'; import { formatQuote, formatTitle } from './common/MessageUtils'; import { format } from '../src/utils/embed'; -const sender = new TelegramBot(config.get('service.durov.token'), { polling: true }); +const bot_token = config.get('service.durov.token'); + +const sender = new TelegramBot(bot_token); const demouser = config.get('service.durov.demouser'); +sender.setWebHook(`${config.get('service.baseURL')}/api/${bot_token}`).then(() => { + log('Webhook is set'); +}).catch(console.log); sender.on('message', msg => { log(`MESSAGE: ${JSON.stringify(msg)}`); }); +export const webhook = (req, res) => { + sender.processUpdate(JSON.parse(req.body)); + res.sendStatus(200); +}; + /** * @param {import('../src/api').Message} msg * @param {string[]} subscribers -- cgit v1.2.3