Skip to content

Conversation

@reidenong
Copy link
Collaborator

This feature introduces reposting to the checkMate message verification process.

Whenever a new message is sent to checkMate, the message is reposted in a separate telegram channel containing other administrators. As the message undergoes checking and the category is updated, any updates are also reposted to this separate channel, and the original repost message is updated. This provides a quick and easy way for administrators to lookup messages and their categories.

Key Code changes

  • repostUtils.ts is a collection of functions that help carry out these reposting functions.
  • sendTelegramMessage.ts has some updates to include new telegram message utils such as methods to update messages, as well as changes to accept the repost bot

Other Requirements

  • in .secret, TELEGRAM_REPOST_BOT_TOKEN is the token for the telegram bot to carry out reposts
  • in .env, TELEGRAM_REPOST_CHANNEL_ID is the channel ID with the bot to send repost messages

…relying on the checkers bot or bigquery

- Feature: Every message and message result will be reposted into a separate tele channel
  with administrators for ease of reference
- To use, you need: Reposter_Bot, Reposting Channel
- Sending messages now updates the original message
@reidenong reidenong added the good first issue Good for newcomers label Jul 24, 2024
@reidenong reidenong requested a review from sarge1989 July 24, 2024 12:26
@reidenong reidenong self-assigned this Jul 24, 2024
Copy link
Collaborator

@sarge1989 sarge1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, before I go into comment, wanted to lay out some nomenclature: when I say "message" in the below it refers to the "Message" object in our database under the Messages collection, and not WhatsApp messages sent in. Individual WhatsApp messages sent in are known as "instances" in our parlance. Remember, one message can have multiple instances, when instances are matched to the message.

with that out of the way...

===

General issue for rectification

I think broadly the issue now is that the repost logic is very tied to instances, when it should be tied to messages (because it's reposting the updates to the message's category, basically).

Also, suggest placing the repost logic at the DB change trigger handlers, rather than the user interaction handlers. I elaborated it in a comment, but broadly the user interaction handlers are more liable to change and refactoring, and in future we will also incorporate more sources than WhatsApp. So moving such logic to the db change triggers instead will in general reduce technical debt going fwd.

}

// Creates a new text message in the repost channel
export async function repostText(messageId: string, instance: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageId should be the ID of the document in the messages collection

}

// Updates a existing repost message with a new category
export async function repostUpdate(id: string, responseText: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should again be messageId based on the document in the messages collection. Ditto for everything else

}

// Update repost channel
await repostUpdate(data.id, category)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed based on earlier feedback? Cos not supposed to have more blasts triggered by replies

token = process.env.TELEGRAM_CHECKER_BOT_TOKEN
} else if (bot === "report") {
token = process.env.TELEGRAM_REPORT_BOT_TOKEN
} else if (bot === "repost") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes to this file look okay

// Repost instance to admin channel
// @ts-ignore
if (instanceUpdateObj.text) {
await repostText(id, instanceUpdateObj)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think best to avoid repostText/repostImage in userHandler, because userHandler will eventually be refactored to take messages from multiple sources, not just whatsapp.

Best to place the repost logic into the existing eventHandlers/onMessageUpdate and create a new eventHandlers/onMessageCreate to listen to DB changes. This will be the best place to put the repost cos it'll be agnostic to wherever the messages come from in the future. Basically we want to place the repost logic with the most fundamental construct, database object creation, rather than at the handling logic which is one step removed and might often change.

instanceText: string
) {
try {
const repostIdRef = db.collection("repostIds").doc(messageId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid creating new collection for this.

Since we're tying repost to messages, put the repostId as a field in the message object itself. Then the text/caption is also easily accessible cos it's already there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants