I updated my getConversations
endpoint to return only the most recent number of messages given to me by the query parameter messages_limit
, which seems to be 30. I’ve now moved on to getConversationsById
endpoint to implement fetching older messages.
The endpoint is hit correctly when I scroll up in the messages screen but the loader doesn’t stop loading. When I check my logs I see the following request:
Incoming request: GET /api/channels/<provider-channel-id>/conversations/<conversation-id>?after=<next-messages-cursor>&messages_limit=30
I can see that the provider channel ID and conversation ID values are set correctly for the conversation I’m trying to fetch more messages for. The after
parameter is simply the cursor I pass in the previous getConversations
endpoint under the field next_messages_cursor
.
I create a correctly-formatted JSON response for this request:
{
"success": true,
"data": [
{
"link": <conversation-url>,
"id": <conversation-id>,
"status": "open",
"created_at": "2024-01-13T16:59:30.352Z",
"seen": true,
"next_messages_cursor": <the-next-next-messages-cursor>,
"messages": [
{
"id": <unique-id-of-message>,
"status": "sent",
"created_at": "2024-01-13T17:00:02.316Z",
"message": "This is message number 972",
"sender_id": "pipedrive7",
"reply_by": null,
"attachments": []
},
{
"id": <unique-id-of-message>,
"status": "sent",
"created_at": "2024-01-13T17:00:01.210Z",
"message": "This is message number 971",
"sender_id": "pipedrive8",
"reply_by": null,
"attachments": []
},
...
{
"id": <unique-id-of-message>,
"status": "sent",
"created_at": "2024-01-13T16:59:31.425Z",
"message": "This is message number 944",
"sender_id": "pipedrive7",
"reply_by": null,
"attachments": []
},
{
"id": <unique-id-of-message>,
"status": "sent",
"created_at": "2024-01-13T16:59:30.352Z",
"message": "This is message number 943",
"sender_id": "pipedrive8",
"reply_by": null,
"attachments": []
}
],
"participants": [
{
"id": "pipedrive7",
"name": "pipedrive7",
"role": "source_user",
"avatar_url": null,
"avatar_expires": false,
"fetch_avatar": false
},
{
"id": "pipedrive8",
"name": "pipedrive8",
"role": "end_user",
"avatar_url": null,
"avatar_expires": false,
"fetch_avatar": false
}
]
}
],
"additional_data": {
"after": "not null"
}
}
Obviously, everything in the JSON is in string format as required. Despite sending this JSON response in the api route with res.json(response)
and seeing this correctly formatted JSON on my enpoint URL, the messages do not properly load in the front end. How come?