Merge pull request #1441 from automatisch/AUT-409

feat(zendesk): add new tickets trigger
This commit is contained in:
Ali BARIN
2023-11-28 11:52:22 +01:00
committed by GitHub
6 changed files with 116 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import listBrands from './list-brands';
import listGroups from './list-groups'; import listGroups from './list-groups';
import listSharingAgreements from './list-sharing-agreements'; import listSharingAgreements from './list-sharing-agreements';
import listTicketForms from './list-ticket-forms'; import listTicketForms from './list-ticket-forms';
import listViews from './list-views';
export default [ export default [
listUsers, listUsers,
@@ -10,4 +11,5 @@ export default [
listGroups, listGroups,
listSharingAgreements, listSharingAgreements,
listTicketForms, listTicketForms,
listViews,
]; ];

View File

@@ -0,0 +1,38 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List views',
key: 'listViews',
async run($: IGlobalVariable) {
const views: {
data: IJSONObject[];
} = {
data: [],
};
let hasMore;
const params = {
'page[size]': 100,
'page[after]': undefined as unknown as string,
};
do {
const response = await $.http.get('/api/v2/views', { params });
const allViews = response?.data?.views;
hasMore = response?.data?.meta?.has_more;
params['page[after]'] = response.data.meta?.after_cursor;
if (allViews?.length) {
for (const view of allViews) {
views.data.push({
value: view.id,
name: view.title,
});
}
}
} while (hasMore);
return views;
},
};

View File

@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app'; import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-headers'; import addAuthHeader from './common/add-auth-headers';
import auth from './auth'; import auth from './auth';
import triggers from './triggers';
import actions from './actions'; import actions from './actions';
import dynamicData from './dynamic-data'; import dynamicData from './dynamic-data';
@@ -15,6 +16,7 @@ export default defineApp({
supportsConnections: true, supportsConnections: true,
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
triggers,
actions, actions,
dynamicData, dynamicData,
}); });

View File

@@ -0,0 +1,3 @@
import newTickets from './new-tickets';
export default [newTickets];

View File

@@ -0,0 +1,59 @@
import defineTrigger from '../../../../helpers/define-trigger';
export default defineTrigger({
name: 'New tickets',
key: 'newTickets',
pollInterval: 15,
description: 'Triggers when a new ticket is created in a specific view.',
arguments: [
{
label: 'View',
key: 'viewId',
type: 'dropdown' as const,
required: true,
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listViews',
},
],
},
},
],
async run($) {
const viewId = $.step.parameters.viewId;
const params = {
'page[size]': 100,
'page[after]': undefined as unknown as string,
sort_by: 'nice_id',
sort_order: 'desc',
};
let hasMore;
do {
const response = await $.http.get(`/api/v2/views/${viewId}/tickets`, {
params,
});
const allTickets = response?.data?.tickets;
hasMore = response?.data?.meta?.has_more;
params['page[after]'] = response.data.meta?.after_cursor;
if (allTickets?.length) {
for (const ticket of allTickets) {
$.pushTriggerItem({
raw: ticket,
meta: {
internalId: ticket.id.toString(),
},
});
}
}
} while (hasMore);
},
});

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/zendesk.svg
items:
- name: New tickets
desc: Triggers when a new ticket is created in a specific view.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />