Files
hereconnect/services/tg-bot/old/setup/setupWebHook.ts
T
ti 7df04c0103
Deploy app frontend / app frontend (push) Failing after 54s
Deploy service couchdb / service couchdb (push) Successful in 38s
Deploy db-migrations / db-migrations (push) Failing after 50s
Deploy service message-delivery-method-web-push / service message-delivery-method-web-push (push) Failing after 1m27s
Deploy service tg-bot / service tg-bot (push) Failing after 44s
add ci for tg bot
2024-12-12 17:45:01 +02:00

24 lines
1.0 KiB
TypeScript

import { setupWebhookDesignDocument } from "./setupWebhookDesignDocument";
import { TG_BOT_DB_NAME, tgBotDesignDocumentsDb } from "dbs";
import { bot } from "old_bot";
const PUBLIC_API_URL = process.env.PUBLIC_API_URL;
if (!PUBLIC_API_URL) {
throw new Error("Необходимо указать PUBLIC_API_URL в переменных окружения.");
}
export const setupWebHook = async () => {
const designDocument = await setupWebhookDesignDocument();
const update: keyof typeof designDocument.updates = "saveUpdate";
const webhookUrl = `${process.env.PUBLIC_API_URL}/${TG_BOT_DB_NAME}/${designDocument._id}/_update/${update}`;
if (designDocument.constants.telegram_webhook_url !== webhookUrl) {
await bot.api.setWebhook(webhookUrl, {
secret_token: designDocument.constants.telegram_secret_token,
});
designDocument.constants.telegram_webhook_url = webhookUrl;
const { rev } = await tgBotDesignDocumentsDb.put(designDocument);
designDocument._rev = rev;
}
return designDocument;
};