-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from CheckMateSG/feat/remove-interim-feedback
Remove interim feedback and migrated Telegram handler to pubsub
- Loading branch information
Showing
14 changed files
with
321 additions
and
1,027 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
functions/src/definitions/eventHandlers/checkerHandlerTelegram.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//TODO TONGYING: Implement webhook here! | ||
import * as admin from "firebase-admin" | ||
import * as functions from "firebase-functions" | ||
|
||
import TelegramBot, { Update } from "node-telegram-bot-api" | ||
import { onMessagePublished } from "firebase-functions/v2/pubsub" | ||
|
||
const TOKEN = String(process.env.TELEGRAM_CHECKER_BOT_TOKEN) | ||
const bot = new TelegramBot(TOKEN) | ||
|
||
// More bot handlers can go here... | ||
|
||
// General message handler | ||
bot.on("message", (msg) => { | ||
if (msg.text && !msg.text.startsWith("/")) { | ||
// Ignore commands as they are handled separately | ||
const chatId = msg.chat.id | ||
// Echo the message text back to the same chat | ||
bot.sendMessage(chatId, `You said: ${msg.text}`) | ||
} | ||
}) | ||
|
||
const checkerHandlerTelegram = async function (body: Update) { | ||
bot.processUpdate(body) | ||
return | ||
} | ||
|
||
const onCheckerPublishTelegram = onMessagePublished( | ||
{ | ||
topic: "checkerEvents", | ||
secrets: [ | ||
"TYPESENSE_TOKEN", | ||
"ML_SERVER_TOKEN", | ||
"TELEGRAM_REPORT_BOT_TOKEN", | ||
"TELEGRAM_CHECKER_BOT_TOKEN", | ||
], | ||
}, | ||
async (event) => { | ||
if ( | ||
event.data.message.json && | ||
event.data.message.attributes.source === "telegram" | ||
) { | ||
functions.logger.log(`Processing ${event.data.message.messageId}`) | ||
await checkerHandlerTelegram(event.data.message.json) | ||
} else { | ||
if (!event.data.message.json) { | ||
functions.logger.warn( | ||
`Unknown message type for messageId ${event.data.message.messageId})` | ||
) | ||
} | ||
} | ||
} | ||
) | ||
|
||
export { onCheckerPublishTelegram } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.