Strange behavior of onTicketUpdate event in Freshservice Sandbox

I have built a custom severless app that sends a notification to a third party Chat application called Fuze. I am using the onTicketCreate, onTicketUpdate, and onConversationCreate events. Both the onTicketCreate and onConversationCreate events work by sending a single notification to the chat app. However, the onTicketUpdate event is duplicating itself and running twice, sending two notifications.

When I look at the serverless logs it shows the event being triggered twice regardless of what properties I change on the ticket. For example, I will change the source and click update on the ticket details page, and this will trigger the onTicketUpdate event twice according to the logs, and the fact that I get two notifications in the third party chat application.

Anyone else having this issue?

Hi Zachary,

I tried this in my Fservice and it seems that there is only one event triggered per property update. Can you also check if you make any property updates in onTicketUpdateHandler? That in turn might trigger another event. Try to provide the server.js file also. I will have a look

Hello @shravan.balasubraman, Below is the code that I am using. I don’t see where I would be triggering a second event. All we are doing is triggering a notification to be sent using a post request. Thank you for looking into this for me.

const axios = require(‘axios’).default;

exports = {
events : [
{
event : ‘onTicketCreate’,
callback : ‘onTicketCreateHandler’
},
{
event : ‘onTicketUpdate’,
callback : ‘onTicketUpdateHandler’
},
{
event : ‘onConversationCreate’,
callback : ‘onConversationCreateHandler’
}
],

// args is a JSON block containing the payload information.
// args['iparam'] will contain the installation parameter values.
onTicketCreateHandler : function (args) {
	console.log('Ticket Created');
	console.log(args);
	if (args.data.ticket.custom_fields[0].value !== null) {
		axios({
			method           : 'post',
			url              :
				'https://api.fuze.com/chat/v2/webhooks/incoming/apiKey',
			headers          : {
				'Content-Type' : 'text/plain'
			},
			transformRequest : [
				(data) => {
					let ticketSubject = JSON.stringify(args.data.ticket.subject);
					let majorIncidentType = JSON.stringify(
						args.data.ticket.custom_fields[0].value
					);
					let ticketID = JSON.stringify(args.data.ticket.id);
					data =
						`Ticket ${ticketSubject} has been identified as a ${majorIncidentType}. Please follow the link below to view the ticket.` +
						'\n' +
						'https://cedservicedesk-fs-sandbox.freshservice.com/helpdesk/tickets/' +
						ticketID;
					return data;
				}
			]
		});
	}
},

onTicketUpdateHandler : function (args) {
	console.log('Ticket Updated');
	console.log(args);
	if (args.data.ticket.custom_fields[0].value !== null) {
		axios({
			method           : 'post',
			url              :
				'https://api.fuze.com/chat/v2/webhooks/incoming/apiKey',
			headers          : {
				'Content-Type' : 'text/plain'
			},
			transformRequest : [
				(data) => {
					let ticketSubject = JSON.stringify(args.data.ticket.subject);
					let ticketID = JSON.stringify(args.data.ticket.id);
					let status = JSON.stringify(args.data.ticket.status_name);
					data =
						`Ticket ${ticketSubject} has had it's ticket properties updated. It's current status is ${status}. Please follow the link below to view the ticket.` +
						'\n' +
						'https://cedservicedesk-fs-sandbox.freshservice.com/helpdesk/tickets/' +
						ticketID;
					return data;
				}
			]
		});
	}
},

onConversationCreateHandler : function (args) {
	console.log('Note or Reply Added');
	console.log(args);
	let ticketID = JSON.stringify(args.data.conversation.ticket_id);
	let url = 'https://cedservicedesk-fs-sandbox.freshservice.com/api/v2/tickets/' + ticketID
	let apikey = 'XXXXXXXXXXXXX';
	axios({
		method:'get',
		url,
		auth: {
			username: `${apikey}`,
			password: 'X'
		}
	})
		.then((response) =>{
		console.log(response.data.ticket.custom_fields.major_incident);
		let isMajorIncident = response.data.ticket.custom_fields.major_incident;
		if (isMajorIncident !== null) {
			axios({
				method           : 'post',
				url              :
					'https://api.fuze.com/chat/v2/webhooks/incoming/apiKey',
				headers          : {
					'Content-Type' : 'text/plain'
				},
				transformRequest : [
					(data) => {
						let ticketSubject = JSON.stringify(response.data.ticket.subject);
						let ticketID = JSON.stringify(response.data.ticket.id);
						data =
							`A new comment has been added to ticket ${ticketSubject}. Please follow the link below to view the ticket.` +
							'\n' +
							'https://cedservicedesk-fs-sandbox.freshservice.com/helpdesk/tickets/' +
							ticketID;
						return data;
					}
				]
			});
		}
	}).catch(function (error) {
		console.log(error);
	});
}

};