Direct Messages duplicating requests to webhooks

webhooks

#1

Hey everyone,

I’m currently consuming Direct Messages in real-time via webhooks, and when I try to send a message (on Twitter Web Client) from two different users for my App’s user at (almost) the same time, the message from the second user is sent twice to my server.

The duplicated message is slightly different, containing a field source_app_id:

"direct_message_events": [
  {
    ...
    "message_create": {
      ...
      "source_app_id": "268278",
      ...
    }
  }
]

And a root block apps:

"apps": {
  "268278": {
    "id": "268278",
    "name": "Twitter Web Client",
    "url": "http://twitter.com"
  }
}

I already solved this internally by persisting the event id and checking every request, but in order to save server load I believe that issue should be fixed.

If you guys found the same issue and have a better solution to workaround this let me know :slight_smile:

Thanks!


#2

Hey @edgar, Twitter sends a webhook event for messages sent and received.

What may be happening is if your app is subscribed to two users (User A and User B) and User A sends a DM to User B, you will get one event representing the message sent from User A and another for the message being received by User B. It’s an edge case that needs to be accounted for, but is rare for most applications. It’s noted at the end of the getting started guide.


#3

Hey @joncipriano,

Actually my app is subscribed only for a single user (User B in your example), and when this user receives DMs from User A and from another User C in a short period of seconds, my server receives the duplicated request from Twitter, related to the last message (User C to User B).

I already handled the messages sent from my User.

Thanks!