Hello, all.

I’m trying to get a similar look to Twitter in terms of how it decides who the tweet is replying to. The response I get back only comes with a single replying to user, but on Twitter it will often say “Replying to @userOne and @userTwo”.

The text object will come back as something like:
@userOne @userTwo Some text that the tweet has”

I tried extracting any mentions at the start of the text, and I’m only removing those that sequentially come after each other. This was my first pass. I then realized there was a problem.

Take this tweet for example.

Here’s the response:

{
    "data": [
        {
            "conversation_id": "1551963877042053120",
            "text": "@Yoda4ever @quelques_idees_ @NeelaDbD si ça, c'est pas du foutage de gueule 😂!",
            "referenced_tweets": [
                {
                    "type": "replied_to",
                    "id": "1551963877042053120"
                }
            ],
            "entities": {
                "mentions": [
                    {
                        "start": 0,
                        "end": 10,
                        "username": "Yoda4ever",
                        "id": "358175664"
                    },
                    {
                        "start": 11,
                        "end": 27,
                        "username": "quelques_idees_",
                        "id": "977554533550362624"
                    },
                    {
                        "start": 28,
                        "end": 37,
                        "username": "NeelaDbD",
                        "id": "2194568642"
                    }
                ]
            },
            "created_at": "2022-07-26T20:37:06.000Z",
            "source": "Twitter for Android",
            "public_metrics": {
                "retweet_count": 0,
                "reply_count": 2,
                "like_count": 1,
                "quote_count": 0
            },
            "in_reply_to_user_id": "358175664",
            "author_id": "1344704016807305218",
            "id": "1552030271515643905"
        }
    ],
    "includes": {
        "users": [
            {
                "verified": false,
                "username": "EnzoLapino",
                "profile_image_url": "https://pbs.twimg.com/profile_images/1357747458915389442/mILoOAVZ_normal.jpg",
                "name": "Enzo🐰Lapino",
                "id": "1344704016807305218"
            },
            {
                "verified": false,
                "username": "Yoda4ever",
                "profile_image_url": "https://pbs.twimg.com/profile_images/1371562774577385473/dlYvfORX_normal.jpg",
                "name": "𝕐o̴g̴",
                "id": "358175664"
            }
        ]
    }
}

How is Twitter deciding which mention to leave in the text of the tweet?

I tried looking at the response from the conversation ids, but it only ever has one user it’s replying to.

Thanks!