mautrix / twitter

A Matrix-Twitter DM puppeting bridge
GNU Affero General Public License v3.0
81 stars 19 forks source link

Matrix -> Twitter mentions do not work #12

Open bdelwood opened 3 years ago

bdelwood commented 3 years ago

If a user mentions a Twitter user on Matrix, it appears on the Twitter end in plain text as the Matrix user's display name.

Is this a fundamental limitation of the bridge? If not, I would be interested in contributing a fix.

tulir commented 3 years ago

Should be doable, involves some browser devtools on twitter.com/messages to find out how twitter sends mentions in messages (it's probably a separate field in the send request body) and then parsing the Matrix HTML similar to https://github.com/mautrix/facebook/blob/master/mautrix_facebook/formatter/from_matrix.py to generate that field

Other direction already happens in https://github.com/mautrix/twitter/blob/master/mautrix_twitter/formatter.py

bdelwood commented 3 years ago

Mostly notes for myself as I debug this, but it appears what happens when a user is mentioned is

  1. The "text" key has a value that is the plaintext message, including the raw handle of the user, ie @{USER}.

  2. The "entities" object is included in "message" (this also happens for URLs, which are handled correctly), with a "user_mentions" key containing and array of objects with info on the mentioned user. It appears there is already a class, Message Entities, particularly MessageEntityUserMention, that already has the json object that twitter expects is included in the entity.

I'll check out what the formatter is doing to the value of "text" and "user_mentions." Currently it appears the formatter is only sending the full Matrix username in the "text" field, and not including the expected "entities" key.

tulir commented 3 years ago

There's currently no formatter in the Matrix -> Twitter direction, the bridge just sends the plain body.