From b9d659efef44701a542e20e42dab995199dc6b11 Mon Sep 17 00:00:00 2001 From: Igor Kamyshev Date: Fri, 26 Jul 2019 10:50:31 +0300 Subject: [PATCH] fix: add removing webhook before start pooling --- lib/TelegramBot.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/TelegramBot.ts b/lib/TelegramBot.ts index e5feb28..6b59346 100644 --- a/lib/TelegramBot.ts +++ b/lib/TelegramBot.ts @@ -50,19 +50,22 @@ export class TelegramBot { ) } + const url = `${this.sitePublicUrl}/${path}` + this.bot.telegram - .setWebhook(`${this.sitePublicUrl}/${path}`) - .then(() => console.log('Webhook set success')) + .setWebhook(url) + .then(() => console.log(`Webhook set success @ ${url}`)) return this.bot.webhookCallback(`/${path}`) } public startPolling() { - try { - this.bot.startPolling() - } catch (e) { - // okay, never mind - } + this.bot.telegram.deleteWebhook().then( + () => this.bot.startPolling(), + () => { + // okay, never mind + }, + ) } private createHandlers(): Handler[] {