1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-24 22:46:41 +07:00

added stubbed webhook availability test

This commit is contained in:
Fedor Katurov 2021-04-27 17:59:17 +07:00
parent 4076b4427d
commit dfae42c197

View file

@ -32,7 +32,9 @@ export class TelegramService {
* Connects to telegram * Connects to telegram
*/ */
public async start() { public async start() {
if (this.webhook.enabled && this.webhook.url) { const isWebhookEnabled = await this.getWebhookAvailable();
if (isWebhookEnabled) {
await this.bot.telegram await this.bot.telegram
.deleteWebhook() .deleteWebhook()
.then(() => this.bot.telegram.setWebhook(this.webhook.url)) .then(() => this.bot.telegram.setWebhook(this.webhook.url))
@ -61,4 +63,13 @@ export class TelegramService {
public async handleUpdate(req: Update, res: Response) { public async handleUpdate(req: Update, res: Response) {
return this.bot.handleUpdate(req, res); return this.bot.handleUpdate(req, res);
} }
/**
* Checks webhook availability
*/
private getWebhookAvailable = async (): Promise<boolean> => {
const isWebhookEnabled = this.webhook.enabled && this.webhook.url;
// TODO: test this.webhook.url with axios instead of 'true'
return isWebhookEnabled && true;
};
} }