Recent searches


No recent searches

How can I get only the last message in the attached thread conversation from the "ticket conversation"?



Posted Oct 26, 2023

I have to get only the actual message from the thread in an email-type ticket using client SDK.

 

client.get('ticket.conversation').then((res: any) => resolve(res['ticket.conversation']));


0

3

3 comments

image avatar

Tipene Hughes

Zendesk Developer Advocacy

Hey Jigar Patel,

This code snippet should be helpful:

client.get("ticket.conversation").then((data) => {

// get most recent conversation object
const arrItem = data["ticket.conversation"].at(-1);

// get message content
const lastMsg = arrItem.message.content;

console.log(lastMsg);
});

0


Tipene Hughes

Tnx for the answer but I want,

From the agent side, I know how to get the last message, but the issue is if the last message contains the whole thread (previous conversation text) body, then I need to remove that part in HTML because I only need the last message text from the HTML content.

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Hi Jigar,
 
Here's another code sample that makes a call to the Ticket Comments API and pulls only the plain text body from the most recent message. Let me know if this is closer to what you were hoping to do.
 
client.get("ticket.id").then((ticketId) => {

// call the tickets API to get a list of comments on the ticket
client.request(`/api/v2/tickets/${ticketId["ticket.id"]}/comments`).then((data) => {

// get most recent comment object
const arrItem = data.comments.at(-1);

// get plain text content
const lastMsg = arrItem.plain_body;

console.log(lastMsg);
});
});

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post