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

3 Comentarios

  • Tipene Hughes
    Zendesk Developer Advocacy

    Hey jigar,

    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
  • jigar

    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
  • 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

Iniciar sesión para dejar un comentario.

Tecnología de Zendesk