Fix webhook ip

This commit is contained in:
2022-03-14 20:35:23 +03:00
parent 5e472c590f
commit 3d828ec976
2 changed files with 6 additions and 2 deletions

View File

@@ -110,12 +110,15 @@ export default class BotsManager {
static async _setWebhook(bot: Telegraf, state: BotState): Promise<boolean> { static async _setWebhook(bot: Telegraf, state: BotState): Promise<boolean> {
const dockerIps = (await dockerIpTools.getContainerIp()).split(" "); const dockerIps = (await dockerIpTools.getContainerIp()).split(" ");
const filteredIp = dockerIps.filter((ip) => ip.startsWith(env.NETWORK_IP_PREFIX));
for (const dockerIp of dockerIps) { const ips = filteredIp.length !== 0 ? filteredIp : dockerIps;
for (const ip of ips) {
try { try {
await bot.telegram.setWebhook( await bot.telegram.setWebhook(
`${env.WEBHOOK_BASE_URL}:${env.WEBHOOK_PORT}/${state.id}/${bot.telegram.token}`, { `${env.WEBHOOK_BASE_URL}:${env.WEBHOOK_PORT}/${state.id}/${bot.telegram.token}`, {
ip_address: dockerIp, ip_address: ip,
} }
); );
return true; return true;

View File

@@ -18,4 +18,5 @@ export default cleanEnv(process.env, {
DOWNLOADER_API_KEY: str(), DOWNLOADER_API_KEY: str(),
USER_SETTINGS_URL: str(), USER_SETTINGS_URL: str(),
USER_SETTINGS_API_KEY: str(), USER_SETTINGS_API_KEY: str(),
NETWORK_IP_PREFIX: str(),
}); });