Recent searches


No recent searches

Listening to 'ticket.collaborators.changed'



Posted Jun 17, 2022

Hello

I've issue I have created an app using ZCLI, and I listening to 'ticket.collaborators.changed' and what I notice is Organization array is empty every time even time a collaborator is added, I just want to know if this known issue or will not return the organization in the array.


0

10

10 comments

image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Michael! `ticket.collaborators.changed` is an event listener and doesn't itself return any data. I'm guessing that there is some action that you're taking during that event that you're expecting will return a user object with that org info in it. Could you share that code snippet with us so that we can see what might be going on here?

0


async _handleCollaboratorsChanged(data) {
const ticketRequestOrganizations = (await this._client.get(CORE_ENDPOINTS.ticketrequestororganizations))[CORE_ENDPOINTS.ticketrequestororganizations];
const collaboratorsOrganizations = (await this._getCollaboratorsOrganizations(data));
console.log(collaboratorsOrganizations);
}
 
async _getCollaboratorsOrganizations(collaborators) {
const collaboratorsOrganizations = [];
var coll = new Promise((reslove, reject) => {
collaborators.forEach(async collaborator => {
const collaboratorOrganizations = (await this._client
.request(API_ENDPOINTS.organization_members + collaborator.id + '/organization_memberships.json')
.catch(this._handleError.bind(this)))[CORE_ENDPOINTS.organizationmemberships]
Promise.all(collaboratorOrganizations).then(x => {
console.log(x);
});
if (collaboratorOrganizations.length != 0) {
if (collaboratorOrganizations.length > 1) {
collaboratorOrganizations.forEach(organization => {
collaboratorsOrganizations.push({
organization_id: organization.organization_id,
organizattion_name: organization.organization_name,
})
})
} else {
collaboratorsOrganizations.push({
organization_id: collaboratorOrganizations[0].organization_id,
organizattion_name: collaboratorOrganizations[0].organization_name,
});
}
} else {
console.log('Did Not Get Collaborator Organizations');
}
});
reslove(collaboratorsOrganizations);
});

coll.then((value) => {
return value;
})
}

0


const CORE_ENDPOINTS = {
ticketcollaboratorschanged: 'ticket.collaborators.changed',
ticketrequestororganizations: 'ticket.requester.organizations',
organizationmemberships: 'organization_memberships'
}

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

I see that is a variable that you've defined, but I'm not seeing what you're actually doing with it in a function. As in, when ticket.collaborators.changed fires, what are you doing with it?

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

Oh, apologies...it looks like your initial code snippet was caught in our spam filter for some reason and I just saw that. I'll get it out of there and then take a look. Sorry for what was probably a confusing response!

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

So I've looked over this, but I'm still not entirely sure what you're doing with the event listener here. I'm also not seeing where you're returning any ZAF methods, rather it looks like you are building your own array of organizations while iterating over collaborators that are being passed in to this function by hitting the organization_members endpoint. This appears to be a ticket sidebar app, so you do have access to the user object for collaborators there with this method...could you use that instead?

0


Hi Greg,

Reason why I want to listen to the event listener, is I want to warn the user before they save the ticket, that they're about to send a message to someone who is not in the requestors organization. So using the method instead will be after the fact which is to late.


Here is my github path for project https://github.com/mthomas-github/zd_cc_app

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

If you'd like to do that, I'd recommend using the ticket submission events, which allow you to hook into any point in the ticket save lifecycle: https://developer.zendesk.com/api-reference/apps/apps-support-api/ticket_sidebar/#ticket-submission-events This is a simplified version of what you're doing without any try/catch/finally, but something like this:
 
client.on('ticket.submit.start', async function() {
const collabs = await client.get('ticket.collaborators');
console.log(collabs.organizations);
return true;
});
The return true; is likely unnecessary as a resolved promise will allow the save to proceed, just adding it to be verbose.

0


Thanks for the code, but this will not work in my case, as I want to warn them before the submit, so as they add new CC I want do my check, so that why i was listening to the ticket.collaborators.changed, I might know the reason why organization array is empty, I just have to do a few test.

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

Understood! Let me know if you run into any other issues that I can try and help with.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post