From dfae42c197eaee1c0c722353cbb0d581e827ee10 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Tue, 27 Apr 2021 17:59:17 +0700 Subject: [PATCH] added stubbed webhook availability test --- src/service/telegram/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/service/telegram/index.ts b/src/service/telegram/index.ts index 2140536..b3f48fe 100644 --- a/src/service/telegram/index.ts +++ b/src/service/telegram/index.ts @@ -32,7 +32,9 @@ export class TelegramService { * Connects to telegram */ public async start() { - if (this.webhook.enabled && this.webhook.url) { + const isWebhookEnabled = await this.getWebhookAvailable(); + + if (isWebhookEnabled) { await this.bot.telegram .deleteWebhook() .then(() => this.bot.telegram.setWebhook(this.webhook.url)) @@ -61,4 +63,13 @@ export class TelegramService { public async handleUpdate(req: Update, res: Response) { return this.bot.handleUpdate(req, res); } + + /** + * Checks webhook availability + */ + private getWebhookAvailable = async (): Promise => { + const isWebhookEnabled = this.webhook.enabled && this.webhook.url; + // TODO: test this.webhook.url with axios instead of 'true' + return isWebhookEnabled && true; + }; }