add ci for tg bot
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
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
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user