Skip to content

Commit

Permalink
Merge pull request #28 from MuNuChapterHKN/fix/telegram-topic-notific…
Browse files Browse the repository at this point in the history
…ation

Select to which Telegram group topic the apply notification is sent by setting the TELEGRAM_THREAD_ID environment variable
  • Loading branch information
AlbertoBaroso authored Feb 25, 2024
2 parents 5cd4d94 + ccab610 commit 9fcc196
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pages/api/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { handleError } from "./application";
const token = process.env.TELEGRAM_TOKEN;
const chatId = process.env.TELEGRAM_CHAT_ID;
const filePath = process.env.COUNTER_FILE_PATH ?? "HKN_APPLY_COUNTER.txt";
const threadId = process.env.TELEGRAM_THREAD_ID ?? 1;

export async function shareNewApply(name: string) {
let counter: number | undefined;
Expand All @@ -22,14 +23,13 @@ export async function shareNewApply(name: string) {
}

export async function sendApplyFailedMessage(stage: string, applicant: string) {
const bot = new TelegramBot(token, { polling: false });
const message = `Apply failed ☠️\n\nStage: ${stage}\n Applicant: ${applicant}`;
await bot.sendMessage(chatId, message);
await sendMessage(message);
}

export async function sendMessage(message: string) {
const bot = new TelegramBot(token, { polling: false });
await bot.sendMessage(chatId, message);
await bot.sendMessage(chatId, message, { message_thread_id: threadId });
}

function readCounter(): number {
Expand Down

0 comments on commit 9fcc196

Please sign in to comment.