mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 15:06:41 +07:00
#5 added webhook probe
This commit is contained in:
parent
1fe3d35540
commit
6344f6dc5a
4 changed files with 35 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
|||
import { TelegramService } from "../../service/telegram";
|
||||
import axios from "axios";
|
||||
import logger from "../../service/logger";
|
||||
|
||||
export class TelegramApi {
|
||||
constructor(private telegram: TelegramService) {}
|
||||
|
@ -16,4 +18,25 @@ export class TelegramApi {
|
|||
"CAACAgIAAxkBAAIB6F82KSeJBEFer895bb7mFI7_GzYoAAISAAOwODIrOXeFNb5v4aEaBA"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes webhook url and falls back to polling mode on error
|
||||
*/
|
||||
public probe = async () => {
|
||||
if (!this.telegram.webhook.enabled || !this.telegram.webhook.url) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await axios.get(this.telegram.webhook.url);
|
||||
logger.info(
|
||||
`probing telegram webhook at ${this.telegram.webhook.url} succeeded`
|
||||
);
|
||||
} catch (e) {
|
||||
logger.warn(
|
||||
`probing telegram webhook at ${this.telegram.webhook.url} failed, falling back to polling mode`
|
||||
);
|
||||
await this.telegram.bot.launch();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue