mautrix / discord

A Matrix-Discord puppeting bridge
https://go.mau.fi/mautrix-discord
GNU Affero General Public License v3.0
240 stars 22 forks source link

Webhook reply embeds sometimes don't show up on Discord #131

Closed mat-1 closed 6 months ago

mat-1 commented 6 months ago

When a user from Matrix replies to a message, sometimes the reply embed doesn't show up on Discord if it's webhook-relayed. This only happens when it's sent as a webhook (i.e. not for users that are bridged with a Discord user token) and seems to happen regardless of whether the author of the message they're replying to is a puppet. This happens on all Matrix clients. I haven't been able to reliably reproduce this issue, but it feels like it happens more in channels that are more active.

tulir commented 6 months ago

Logs of the reply failing to be added are probably necessary

mat-1 commented 6 months ago

Here's the logs around the time the reply is sent

Jan 06 01:10:27 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:27 DBG Starting handling of transaction content={"pdu":0,"unstable_edu":1,"unstable_to_device":0} transaction_id=6089248
Jan 06 01:10:27 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:27 DBG Finished dispatching events from transaction transaction_id=6089248
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Starting handling of transaction content={"pdu":1,"unstable_edu":0,"unstable_to_device":0} transaction_id=6089249
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Finished dispatching events from transaction transaction_id=6089249
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Decrypting received event event_id=$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54 session_id=4iNWk/manTs/6qiXvBbfdGS0nXjnwHHQF059w+4ZG68
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Sent message checkpoint message_checkpoint={"event_id":"$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54","event_type":"m.room.encrypted","reported_by":"BRIDGE","retry_num":0,"room_id":"!hkZjzTsUGyPV321F:matdoes.dev","status":"SUCCESS","step":"BRIDGE","timestamp":1704503428763}
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Ratchet safety data changed (ratchet state didn't change) action="decrypt megolm event" component=crypto event_id=$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54 lost_indices=[] max_messages=100 missed_indices=[] new_ratchet_index=3 next_new_index=3 prev_ratchet_index=0 sender=@mat:nope.chat sender_key=DwFeIrs2feiP6S5LHZzwmKbGHEMLwk8ehrFY4OY0PDM session_id=4iNWk/manTs/6qiXvBbfdGS0nXjnwHHQF059w+4ZG68
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Event decrypted successfully action="decrypt megolm event" component=crypto decrypted_event_type="m.room.message (message)" event_id=$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54 message_index=2 sender=@mat:nope.chat sender_key=DwFeIrs2feiP6S5LHZzwmKbGHEMLwk8ehrFY4OY0PDM session_id=4iNWk/manTs/6qiXvBbfdGS0nXjnwHHQF059w+4ZG68
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Sent message checkpoint message_checkpoint={"event_id":"$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54","event_type":"m.room.message","message_type":"m.text","reported_by":"BRIDGE","retry_num":0,"room_id":"!hkZjzTsUGyPV321F:matdoes.dev","status":"SUCCESS","step":"DECRYPTED","timestamp":1704503428769}
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Request completed as_user_id=@discordbot:matdoes.dev duration=21.07348 method=GET req_id=572 response_length=1039 response_mime=application/json status_code=200 url=https://matrix.matdoes.dev/_matrix/client/v3/rooms/%21hkZjzTsUGyPV321F:matdoes.dev/event/$gg4ahmQuPUdf3BafEo6dboncSO3eO4LmywswQQvYck4?user_id=%40discordbot%3Amatdoes.dev
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 WRN Failed to convert reply message to embed for webhook send error="unsupported event type m.room.encrypted / *event.EncryptedEventContent" channel_id=1085173760895754250 channel_receiver= room_id=!hkZjzTsUGyPV321F:matdoes.dev
Jan 06 01:10:28 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:28 DBG Unhandled event event_type=*discordgo.PresenceUpdate user_id=@pypylia:matrix.org
Jan 06 01:10:29 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:29 DBG Matrix event handled successfully action="send matrix message metrics" channel_id=1085173760895754250 channel_receiver= event_id=$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54 event_type=m.room.message room_id=!hkZjzTsUGyPV321F:matdoes.dev sender=@mat:nope.chat
Jan 06 01:10:29 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:29 DBG Sent message checkpoint message_checkpoint={"event_id":"$DXr-C1-AWFKD9_zfYqybK5-lfXEoBKHZwncFTJxqM54","event_type":"m.room.message","message_type":"m.text","reported_by":"BRIDGE","retry_num":0,"room_id":"!hkZjzTsUGyPV321F:matdoes.dev","status":"SUCCESS","step":"REMOTE","timestamp":1704503429380}
Jan 06 01:10:29 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:29 DBG Dropping duplicate message action="discord message create" author_id=1109637780587434005 channel_id=1085173760895754250 channel_receiver= message_id=1192998591036391504 message_type=0 room_id=!hkZjzTsUGyPV321F:matdoes.dev
Jan 06 01:10:29 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:29 DBG Dropping duplicate message action="discord message create" author_id=1109637780587434005 channel_id=1085173760895754250 channel_receiver= message_id=1192998591036391504 message_type=0 room_id=!hkZjzTsUGyPV321F:matdoes.dev
Jan 06 01:10:29 matrix-mautrix-discord[350220]: Jan  6, 2024 01:10:29 DBG Dropping duplicate message action="discord message create" author_id=1109637780587434005 channel_id=1085173760895754250 channel_receiver= message_id=1192998591036391504 message_type=0 room_id=!hkZjzTsUGyPV321F:matdoes.dev

(There might be some unrelated logs since I have several active rooms bridged) This looks like the important line:

WRN Failed to convert reply message to embed for webhook send error="unsupported event type m.room.encrypted / *event.EncryptedEventContent" channel_id=1085173760895754250 channel_receiver= room_id=!hkZjzTsUGyPV321F:matdoes.dev

tulir commented 6 months ago

Ah yeah encrypted rooms might not be supported in that specific context, why do you have an encrypted relay bridge to discord anyway 🤔

mat-1 commented 6 months ago

Ah yeah encrypted rooms might not be supported in that specific context, why do you have an encrypted relay bridge to discord anyway 🤔

Interesting, but the weird thing is that sometimes the reply embed does work for encrypted rooms, just not consistently. They're encrypted because the rooms are semi-private and we don't want homeserver admins to be able to see them.

mat-1 commented 6 months ago

I love you <3

mat-1 commented 6 months ago

I can confirm the update fixes it. I checked message history and reply embeds haven't been working for months (might've been when we switched encryption on). I think I just got confused because we have a different bot that sends a similar reply embed, and we also have some non-encrypted rooms that replies were working in.