I'm using facebook Workplace Graph API. I'm looking for two things:
1) How to get the messages from message ID 2) How to get the new message only.
What I have done so far? 1) I'm able to get the messages for each convo through this api https://graph.facebook.com/user_id/conversations?fields=messages{message,attachments,from} and it is returning all convo and messgaes together.
I want to get the messages in sequential manner like they have even mentioned in their document : https://developers.facebook.com/docs/workplace/reference/graph-api/community#examples
With this API :
https://graph.facebook.com/Thread_id/messages?user=user_id This api is returning message id in below format:
"data": [
{
"id": "m_mid.$cAAAAAB3Zz_JwhPe3PFqU7JtwhKkY",
"created_time": "2019-04-25T08:52:43+0000"
},
{
"id": "m_mid.$cAAAAAB3Zz_JwhOZDsVqU6D6aTMok",
"created_time": "2019-04-25T08:33:40+0000"
},
{
"id": "m_mid.$cAAAAAB3Zz_JwhOIeqVqU5zVO0W_t",
"created_time": "2019-04-25T08:29:08+0000"
},
{
"id": "m_mid.$cAAAAAB3Zz_JwhOGJq1qU5xAa27DB",
"created_time": "2019-04-25T08:28:30+0000"
},
{
"id": "m_mid.$cAAAAAB3Zz_JwhOF-BlqU5wyRZs39",
"created_time": "2019-04-25T08:28:27+0000"
}
],
"paging": {
"cursors": {
"before": "QVFIUjBadUdDcHV6SWRrQkhpQy1iUURYa3lKZADRGR3ZA1RDRIOEE2LWp3aERiRXZAPbWxORFBKOWRWdXBpOWQySWx3TjdxSHpsQm0tRmpNNTc1dnBfV1JYNDFRWmtLbC1QSW5jVkk4a0NUNUF1RUNuemhxUUYzWkllVE9tWkM0Y2tpY1A4",
"after": "QVFIUnRlc3VPUEdLM2FQdWxob1Y0YWxhdWFrMGQwWUxHSVZAwbmlaZA015RlUwLWRWTHhsdjRnNi03MTl3eWJvMUxiNXBaUFd4bVVBWkhpbmFCYkNLdzR5YlJVZA3YyT1RMVnJIY2JLbXVyTjNaN1pBaWVFeEkta0NLazljUHc5WGhEQlo0"
}
}
}
I can't figure out how to use these message Ids to get the actual message.
to read users' messages you need to use an impersonate_token. This allows you to see also the content of the message and to use that thread_id.
To read a message, you don't need to call the thread_id, since you can use nested calls, like:
me/conversations?fields=thread_id,messages{message,created_time}
In any case, once you have impersonated a user and retrieved the thread_id, you can do this call
{thread_id}?fields=messages{message,created_time}
to read all the messages of a specific thread. Messages are already ordered by creation_time, so you just need to take the last one.