Facebook - Get conversation thread ID with message ID?
Asked Answered
M

3

18

When I receive a "message received callback" event from the Facebook Realtime API (webhooks) I want to fetch previous messages in the conversation. To do that I need the ID of the conversation thread.

https://developers.facebook.com/docs/messenger-platform/webhook-reference/message?locale=en_US

The event does not contain any information about the ID of the conversation thread (t_id). It only contains the message ID (mid).

https://developers.facebook.com/docs/graph-api/reference/v2.8/conversation

Is there a way to get the conversation thread ID?

Magnesia answered 24/3, 2017 at 9:5 Comment(7)
I see here a similar discussion: #19129517Iago
Sadly that doesn't help. "As of August 8, 2016, FQL will no longer be available and cannot be queried." I'm only using the Graph API.Magnesia
Having this issue as well!Ormiston
@John, have you gotten anything?Ormiston
Sadly I didn't find a solution, yet.Magnesia
Apparently this isn't possible without searching through all of the conversations to find the one that contains the message you want. I was told that Messenger webhook updates will soon start including thread_key, but I'm not sure when or if that will happen.Rothermere
I am also facing same query for Facebook API. Please let me know if there is any other solution. I also need Conversation ID from its one of the Message ID. ThanksOfficiant
S
10

I thing there is an easier way to do this. You can use the user_id filter on conversations:

https://graph.facebook.com/v3.0/--PAGE-ID--/conversations?fields=senders&user_id=

See the Parameters section from here: https://developers.facebook.com/docs/graph-api/reference/page/conversations/

Starfish answered 16/1, 2019 at 15:29 Comment(1)
thanks man it save my dayGelid
G
1

There is no straight way of doing it. You can use the workaround below to loop conversation ids:

(a) Fetch all conversation ids with sender ids https://graph.facebook.com/v3.0/--PAGE-ID--/conversations?fields=senders

(b) lookup the user_id of the sender of the message. https://graph.facebook.com/v3.0/--MESSAGE-ID--?fields=from

(c) loop through conversation ids to find a match for the message user_id and get the thread_id.

PS: this is an expensive solution. Try to avoid it unless you really need it.

Glennglenna answered 4/7, 2018 at 18:7 Comment(0)
C
0

To get a conversation ID using a message ID in the Facebook Graph API, you need to follow these steps:

  1. Get the Message Details: Retrieve the message details using the message ID. This will include the conversation ID.
  2. Use the Access Token: Ensure you have the proper access token with the necessary permissions.

Here is an example of how you can do this using a GET request:

https://graph.facebook.com/v{API_VERSION}/{message-id}?fields=thread_id,id,message,created_time,to,from,attachments,is_unsupported,shares,tags&access_token=<accesstokensanitized>

The response will include details about the message, including the thread_id (thread_id is the conversation ID.)

Colossal answered 30/5, 2024 at 7:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.