Skip to content
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

Handle Whatsapp threading/replies #1974

Merged
merged 3 commits into from
Mar 9, 2023

Conversation

yousefmansy1
Copy link
Contributor

@yousefmansy1 yousefmansy1 commented Feb 18, 2023

Handle Whatsapp threading/replies, based on commit 6afa93e from #1934
In this change we are updating whatsapp message IDs to include sender JID as this is necessary to reply to a message

image

In this change we are updating whatsapp message IDs to include sender JID as this is necessary to reply to a message
tulir/whatsmeow#88 (comment)
tulir/whatsmeow#148 (comment)

Based on commit 6afa93e from 42wim#1934
    Author: Iiro Laiho <iiro.laiho@iki.fi>
@yousefmansy1
Copy link
Contributor Author

yousefmansy1 commented Feb 22, 2023

Finally figured out the issue.
I was 90% of the way there, you actually also need to add a QuotedMessage to the context info.

Only figured it out by taking a look at the mautrix-whatsapp repo and tracing through what they're doing.
https://github.com/mautrix/whatsapp/blob/e0a9b0e8bb25b70196b78079dca2eeef35d526b6/portal.go#L3719-L3726

Granted the issues I linked actually mentioned this upon looking at it again.
However, they called it out as optional, idk lol.

@yousefmansy1 yousefmansy1 marked this pull request as ready for review February 22, 2023 11:50
Sender JID can have a `:` inside of it, using `/` as a delimiter now.
Added messageID parser + struct.
messages sent with an attachment do not show replies
But at least common `sendMessage` will make repies from whatsapp to an attachement bridge across.

The new message ID format broke message deleting, so we change the messageID into the real id at the beginning of send.
We really do need the extra info for when we reply to a message though.
@yousefmansy1 yousefmansy1 marked this pull request as draft February 24, 2023 09:06
file/Image/audio/replies all work now.
@codeclimate
Copy link

codeclimate bot commented Feb 24, 2023

Code Climate has analyzed commit 264ab84 and detected 7 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 6

View more on Code Climate.

@yousefmansy1 yousefmansy1 marked this pull request as ready for review February 24, 2023 11:17
@yousefmansy1
Copy link
Contributor Author

Replies should work across the board now.
@qaisjp do you think you can take a look?

Or perhaps @ilmaisin since you've made some commits to the whatsappmulti bridge.

(will post screenshots later its late I'm tired lol)

@ilmaisin
Copy link
Contributor

Replies should work across the board now. @qaisjp do you think you can take a look?

Or perhaps @ilmaisin since you've made some commits to the whatsappmulti bridge.

(will post screenshots later its late I'm tired lol)

Should your PR now work in both directions? I can probaly try it this weekend. I have my draft PR running in my instance, but it is rx-only.

@yousefmansy1
Copy link
Contributor Author

Should your PR now work in both directions? I can probaly try it this weekend. I have my draft PR running in my instance, but it is rx-only.

Yes it works in both directions. 👍

@ilmaisin
Copy link
Contributor

ilmaisin commented Mar 5, 2023

If a Telegram user replies to a message orignating in Whatsapp, the reply that is sent back to Whatsapp includes both the "proper" quote as well as a textual quote. This may be a matter of another PR, though.
matterbridge-wa-quote

@yousefmansy1
Copy link
Contributor Author

If a Telegram user replies to a message orignating in Whatsapp, the reply that is sent back to Whatsapp includes both the "proper" quote as well as a textual quote. This may be a matter of another PR, though. matterbridge-wa-quote

I believe this might be unavoidable, as then you have QuoteDisable=false it will append reply information directly into the message text.
The receiving bridges will simply relay whatever is in the message.Text body.

if !b.GetBool("QuoteDisable") {
quote := message.ReplyToMessage.Text
if quote == "" {
quote = message.ReplyToMessage.Caption
}
rmsg.Text = b.handleQuote(rmsg.Text, usernameReply, quote)
}

This would require some more significant rework of how replies work to resolve.

For now you'll just have to use QuoteDisable=true

@42wim 42wim added this to the 1.27.0 milestone Mar 9, 2023
@42wim
Copy link
Owner

42wim commented Mar 9, 2023

Great job @yousefmansy1 !

@42wim 42wim added the whatsapp label Mar 9, 2023
@42wim 42wim merged commit d00dcf3 into 42wim:master Mar 9, 2023
yousefmansy1 added a commit to yousefmansy1/matterbridge that referenced this pull request Mar 10, 2023
* Handle Whatsapp threading/replies.
In this change we are updating whatsapp message IDs to include sender JID as this is necessary to reply to a message
tulir/whatsmeow#88 (comment)
tulir/whatsmeow#148 (comment)

Based on commit 6afa93e from 42wim#1934
    Author: Iiro Laiho <iiro.laiho@iki.fi>

* Fix replies.
Sender JID can have a `:` inside of it, using `/` as a delimiter now.
Added messageID parser + struct.
messages sent with an attachment do not show replies
But at least common `sendMessage` will make repies from whatsapp to an attachement bridge across.

The new message ID format broke message deleting, so we change the messageID into the real id at the beginning of send.
We really do need the extra info for when we reply to a message though.

* Refactored message replies.
file/Image/audio/replies all work now.
@yousefmansy1 yousefmansy1 deleted the whatsappmulti-reply branch March 10, 2023 11:03
yousefmansy1 added a commit to yousefmansy1/matterbridge that referenced this pull request Mar 11, 2023
* Handle Whatsapp threading/replies.
In this change we are updating whatsapp message IDs to include sender JID as this is necessary to reply to a message
tulir/whatsmeow#88 (comment)
tulir/whatsmeow#148 (comment)

Based on commit 6afa93e from 42wim#1934
    Author: Iiro Laiho <iiro.laiho@iki.fi>

* Fix replies.
Sender JID can have a `:` inside of it, using `/` as a delimiter now.
Added messageID parser + struct.
messages sent with an attachment do not show replies
But at least common `sendMessage` will make repies from whatsapp to an attachement bridge across.

The new message ID format broke message deleting, so we change the messageID into the real id at the beginning of send.
We really do need the extra info for when we reply to a message though.

* Refactored message replies.
file/Image/audio/replies all work now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants