diff --git a/serverless.yml b/serverless.yml index 41546ca..13cba93 100644 --- a/serverless.yml +++ b/serverless.yml @@ -24,6 +24,8 @@ provider: MONGO_PASSWORD: ${self:custom.secrets.provider.environment.MONGO_PASSWORD} MONGO_HOST: ${self:custom.secrets.provider.environment.MONGO_HOST} MONGO_DATABASE: ${self:custom.secrets.provider.environment.MONGO_DATABASE} + USERNAME: ${self:custom.secrets.provider.environment.USERNAME} + PASSWORD: ${self:custom.secrets.provider.environment.PASSWORD} functions: telegramAuthorizer: ${file(./src/functions/telegram_authorizer/function.yml)} diff --git a/src/functions/telegram_send_message/function.yml b/src/functions/telegram_send_message/function.yml index 39c9115..ac8ea0f 100644 --- a/src/functions/telegram_send_message/function.yml +++ b/src/functions/telegram_send_message/function.yml @@ -8,3 +8,4 @@ events: path: /${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}/telegram/send-message method: POST cors: true + authorizer: telegramAuthorizer diff --git a/src/functions/telegram_send_photo/function.yml b/src/functions/telegram_send_photo/function.yml index 017cd21..deb6e7b 100644 --- a/src/functions/telegram_send_photo/function.yml +++ b/src/functions/telegram_send_photo/function.yml @@ -8,3 +8,4 @@ events: path: /${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}/telegram/send-photo method: POST cors: true + authorizer: telegramAuthorizer diff --git a/src/functions/telegram_send_video/function.yml b/src/functions/telegram_send_video/function.yml index 834519f..53d1552 100644 --- a/src/functions/telegram_send_video/function.yml +++ b/src/functions/telegram_send_video/function.yml @@ -8,3 +8,4 @@ events: path: /${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}/telegram/send-video method: POST cors: true + authorizer: telegramAuthorizer diff --git a/src/functions/telegram_set_webhook/function.yml b/src/functions/telegram_set_webhook/function.yml index 81ed28a..c2677df 100644 --- a/src/functions/telegram_set_webhook/function.yml +++ b/src/functions/telegram_set_webhook/function.yml @@ -8,3 +8,4 @@ events: path: /${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}/telegram/set-webhook method: POST cors: true + authorizer: telegramAuthorizer diff --git a/src/lib/services/telegram.ts b/src/lib/services/telegram.ts index 171f278..ac957d7 100644 --- a/src/lib/services/telegram.ts +++ b/src/lib/services/telegram.ts @@ -2,7 +2,7 @@ import axios, { AxiosResponse, AxiosInstance } from "axios"; import { EntityTg, UserTg, FormattingOptionsTg } from "../models"; import { MessageTg } from "../models/telegram"; -const { TELEGRAM_BOT_TOKEN } = process.env; +const { TELEGRAM_BOT_TOKEN, USERNAME, PASSWORD } = process.env; interface SetWebhookResponse { ok: boolean; @@ -157,6 +157,7 @@ export class TelegramService { if (!this.instance) { this.instance = axios.create({ baseURL: `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}`, + auth: { username: `${USERNAME}`, password: `${PASSWORD}` }, }); } }