javascriptzendeskzendesk-appzendesk-sdk

Zendesk - Listen agent response event ZAF Client [Support Location]


for a while now I am stuck, trying to listen to the event where the agent sends a reply to the ticket. I have tried listening to ticket.comments.changed and ticket.conversation.changed but have not been successful.

I can't use the ticket.submit.[done|fail|always] or ticket.save because I don't have a way of knowing if it is the event I want or is being called with another event.

Maybe someone who knows of a configuration or some way that would allow me to do this, I would be very grateful.


Solution

  • You can configure triggers and webhooks to be added to your app as requirements. If you must use a ticket_sidebar app, you can listen to the following events:

    var client = ZAFClient.init();
        client.on('ticket.comments.changed', (e) => {
            // Here is the latest comment
            let comment = e[0];
            console.log(comment);
    
            // Check author role
            console.log((comment.author.role !== "end-user") ? "Comment made by agent" : "Comment made by end user");
            
            // Get ticket object if needed
            client.get('ticket').then(
                (res) => {
                    // Send ticket payload to my backend
                },
                (err) => {
                    console.error(err);
                }
            )
        });
        client.on('ticket.status.changed', (e) => {
            // Here is the new status
            console.log("Status changed to", e);
            
            // Get ticket object if needed
            client.get('ticket').then(
                (res) => {
                    // Send ticket payload to my backend
                },
                (err) => {
                    console.error(err);
                }
            )
        });