Plugin SDK - list messages

  • 19 February 2023
  • 3 replies

  • Conversationalist
  • 2 replies

I’m working on a plugin which needs to list and parse messages and discussions using context.listMessages() and context.listComments()

I ever receive the whole conversation, only the first 20 discussion messages and in the case of emails 3, even though the conversations contains many more.

If I understand the docs correctly, I should use the nextPageToken form the response, in order to read more/all messages. I did this according to the documentation (see code below) This however, makes no difference and I still receive 3 or fewer emails.  

 const listAllEmails = async () => {
const emailList = await context.listMessages();

let nextPageToken = emailList.token;
const emails = emailList.results;

while (nextPageToken) {
const { results, token } = await context.listMessages(nextPageToken);

nextPageToken = token;
return emails;

I found that my nextPageToken is always undefined, which surely is the reason behind this behaviour.

For more info, I’m calling my listAllEmails() function (in my React apps) useEffect function, like so: 

  useEffect(() => {
if (context.conversation.type === 'email') {
listAllEmails().then((emails) => {
}, [context]);

And this is the result of the console log, every time. I can’t figure out why this would be the case. Why would nextPageToken be undefined?  And am I correct to assume that I must use nextPageToken in order to view all messages (I have tried without it with the same result of only receiving a few messages)? 

{nextPageToken: undefined, results: Array(1)}

/ Any help is greatly appreciated! 



Best answer by henry 22 February 2023, 00:03

View original

3 replies

Userlevel 1
Badge +5

Hi Victor,

One of our support engineers is reaching out to troubleshoot this unexpected behavior.  Thank you!

Hi Victor,

This is expected behavior as the `listMessages` method simply lists the messages that are visible to the user in their app. For performance reasons, we don’t load all messages when a user views a conversation, because some conversations can have a huge number of messages. As a result, there is no guarantee that `listMessages` will include the full list of messages. I can certainly see how this is confusing based on the way the endpoint is designed though. We do have an open idea in our ideas portal to improve this though: Please feel free to add a vote.

One workaround is to use the conversation ID from the SDK to make a Core API request using the list conversation messages endpoint: Not the most convenient but one option.


Thanks henry!

I see how this makes sense, although I was hoping to do it all through the context API in the plugin, however I don’t think it will be a major hassle or workaround to use the core APIs alternative.{conversation_id}/messages

I consider this solved, much appreciated!