-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Reposting all new posts in a new channel #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…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
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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
Other Requirements
.secret,TELEGRAM_REPOST_BOT_TOKENis the token for the telegram bot to carry out reposts.env,TELEGRAM_REPOST_CHANNEL_IDis the channel ID with the bot to send repost messages