mautrix / telegram

A Matrix-Telegram hybrid puppeting/relaybot bridge
https://matrix.to/#/#telegram:maunium.net
GNU Affero General Public License v3.0
1.33k stars 175 forks source link

Telegram-to-telegram replies do not propagate to IRC appservice #400

Closed zouppen closed 4 years ago

zouppen commented 4 years ago

Steps to reproduce:

  1. Prepare a channel which has both Telegram and IRC integration
  2. In Telegram, send a message with any content
  3. In Telegram, reply to that message. (You may reply to your own message, too)
  4. The message shows up correctly in Matrix but doesn't propagate to IRC.

This might be matrix-appservice-irc bug but the message content is somehow "hostile" so I'm filing this bug in this project first because replies to Telegram messages made in Matrix side do propagate correctly. Maybe m_relates_to content is somehow malformed?

Example message payload which is not propagating correctly:

{
    "body": "> <Zouppen> testing\n\nreply to a telegram message",
    "format": "org.matrix.custom.html",
    "msgtype": "m.text",
    "m.relates_to": {
    "event_id": "$15760700702709kXicd:hacklab.fi",
    "rel_type": "m.reference",
    "m.in_reply_to": {
            "event_id": "$15760700702709kXicd:hacklab.fi"
    }
    },
    "formatted_body": "<mx-reply><blockquote><a href='https://matrix.to/#/!RtlwJVOHzddeloiByq:liittovaltio.fi/$15760700702709kXicd:hacklab.fi'>In reply to</a> <a href='https://matrix.to/#/@_telegram_284794645:hacklab.fi'>Zouppen</a><br/>testing</blockquote></mx-reply>reply to a telegram message",
    "external_url": "https://t.me/c/310521202/56947"
}

For comparison, this is the payload of a message which is a reply to the same Telegram message but the reply is made from Matrix by Riot.im. It propagates to IRC correctly:

{
    "body": "> <@_telegram_284794645:hacklab.fi> testing\n\nReply from Matrix",
    "msgtype": "m.text",
    "m.relates_to": {
    "m.in_reply_to": {
            "event_id": "$15760700702709kXicd:hacklab.fi"
    }
    },
    "formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!RtlwJVOHzddeloiByq:liittovaltio.fi/$15760700702709kXicd:hacklab.fi?via=jkl.hacklab.fi&via=hacklab.fi&via=irc.snt.utwente.nl\">In reply to</a> <a href=\"https://matrix.to/#/@_telegram_284794645:hacklab.fi\">@_telegram_284794645:hacklab.fi</a><br>testing</blockquote></mx-reply>Reply from Matrix",
    "format": "org.matrix.custom.html"
}
tulir commented 4 years ago

IRC bridge bug, overly sensitive reply fallback removal. It parses replies like they're supposed to be sent rather than the way the spec tells you to parse them. Not sure if I made an issue, but I'm pretty sure I've complained about it

https://github.com/matrix-org/matrix-appservice-irc/blob/develop/src/bridge/MatrixHandler.ts#L1100

zouppen commented 4 years ago

The issue seems to be in m.in_reply_to. When I generate otherwise identical Matrix message, it is propagated to IRC.

Removed this part and it propagates:

"m.in_reply_to": {
    "event_id": "$15760700702709kXicd:hacklab.fi"
}
tulir commented 4 years ago

The problem is in the fallback, specifically <Zouppen> instead of <@_telegram_...:hacklab.fi>