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;
emails.push(...results);
}
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') {
setConversationTypeState('email');
listAllEmails().then((emails) => {
console.log(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!