如何通过Facebook Webhook的mid获取conversation id?
t_xxxx格式)从mid的解决方案 Hey there, let's work through this issue you're having with getting that t_xxxx-formatted conversation ID when you only receive an mid in your webhook payload.
首先,先明确一个关键点:一对一对话的对话ID等价于发送者ID
In your provided webhook data, the sender.id (2112675102192095) is actually the valid conversation ID for one-on-one chats with your page. You can use this ID directly in all Messenger API calls (like sending replies) — it works exactly the same as the t_xxxx formatted ID. So if you're building a bot for direct user-page conversations, you might not even need to fetch the t_ version at all!
如果确实需要t_xxxx格式的ID(比如群组对话场景)
If you're dealing with group conversations or specifically need the t_ prefixed thread ID, you can retrieve it using the Retrieve Message API with the mid you have:
- API Endpoint:
GET /v18.0/{mid}(use the latest Graph API version available) - Authorization: Include your Page Access Token as a query parameter or in the request header
- 示例Curl请求:
curl -X GET "https://graph.facebook.com/v18.0/n89QDNpjbh7UUZjDj7mkfk-Mqd_vry00MlXChtxjo-ZLokFwJAtZ6udnPZibQjzAZpuqsN64UVjTly5cTCEKTQ?access_token=YOUR_PAGE_ACCESS_TOKEN"
When you make this call, the response will include a thread_id field with that t_xxxx formatted value you're looking for.
补充说明
The mid is just a unique identifier for the individual message, not the conversation thread. For most bot use cases, the sender.id (for one-on-one) or the thread_id (for groups) is what you need to track ongoing conversations and send messages back to users.
内容的提问来源于stack exchange,提问作者colinmorgan

