diff options
Diffstat (limited to 'vnext/server/durov.js')
-rw-r--r-- | vnext/server/durov.js | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/vnext/server/durov.js b/vnext/server/durov.js index df33f743..e9bbdb9a 100644 --- a/vnext/server/durov.js +++ b/vnext/server/durov.js @@ -7,17 +7,26 @@ import config from 'config'; import { formatQuote, formatTitle } from './common/MessageUtils'; import { format } from '../src/utils/embed'; -const bot_token = config.get('service.durov.token'); +let sender; +let demouser; +let bot_token; +const durov_token_key = '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); +if (config.has(durov_token_key)) { + bot_token = config.get(durov_token_key); + sender = new TelegramBot(bot_token); + 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)}`); + }); +} -sender.on('message', msg => { - log(`MESSAGE: ${JSON.stringify(msg)}`); -}); +export const webhookPath = () => { + return bot_token; +}; export const webhook = (req, res) => { sender.processUpdate(JSON.parse(req.body)); |