feat(zendesk): add new tickets trigger
This commit is contained in:
@@ -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,
|
||||||
];
|
];
|
||||||
|
@@ -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;
|
||||||
|
},
|
||||||
|
};
|
@@ -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,
|
||||||
});
|
});
|
||||||
|
3
packages/backend/src/apps/zendesk/triggers/index.ts
Normal file
3
packages/backend/src/apps/zendesk/triggers/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import newTickets from './new-tickets';
|
||||||
|
|
||||||
|
export default [newTickets];
|
@@ -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);
|
||||||
|
},
|
||||||
|
});
|
12
packages/docs/pages/apps/zendesk/triggers.md
Normal file
12
packages/docs/pages/apps/zendesk/triggers.md
Normal 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 />
|
Reference in New Issue
Block a user