diff options
author | Vitaly Takmazov | 2023-03-07 13:04:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-03-07 13:04:37 +0300 |
commit | 5d31fffc321717afb6c0cbb0f5dab9bd8f844eda (patch) | |
tree | 3bd96dc3ec6bb5e63a8442992c04f6c96ec35cff /vnext/server/durov.js | |
parent | b4ce703820264a7ed16b5b3efee973aadc43335d (diff) |
Conditional modules initialization
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)); |