feat(zendesk): add update ticket action

This commit is contained in:
Rıdvan Akca
2023-11-23 15:11:18 +03:00
parent 772b195eca
commit df54f909c1
6 changed files with 263 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import createTicket from './create-ticket';
import updateTicket from './update-ticket';
export default [createTicket];
export default [createTicket, updateTicket];

View File

@@ -0,0 +1,167 @@
export const fields = [
{
label: 'Ticket',
key: 'ticketId',
type: 'dropdown' as const,
required: true,
variables: true,
description: 'Select the ticket you want to change.',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listFirstPageOfTickets',
},
],
},
},
{
label: 'Subject',
key: 'subject',
type: 'string' as const,
required: false,
variables: true,
description: '',
},
{
label: 'Assignee',
key: 'assigneeId',
type: 'dropdown' as const,
required: false,
variables: true,
description:
'Note: An error occurs if the assignee is not in the default group (or the specific group chosen below).',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
{
name: 'parameters.showUserRole',
value: 'true',
},
{
name: 'parameters.includeAdmins',
value: 'true',
},
],
},
},
{
label: 'Group',
key: 'groupId',
type: 'dropdown' as const,
required: false,
variables: true,
description: 'Allocate this ticket to a specific group.',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listGroups',
},
],
},
},
{
label: 'New Status',
key: 'status',
type: 'dropdown' as const,
required: false,
variables: true,
description: '',
options: [
{ label: 'New', value: 'new' },
{ label: 'Open', value: 'open' },
{ label: 'Pending', value: 'pending' },
{ label: 'Hold', value: 'hold' },
{ label: 'Solved', value: 'solved' },
{ label: 'Closed', value: 'closed' },
],
},
{
label: 'New comment to add to the ticket',
key: 'comment',
type: 'string' as const,
required: false,
variables: true,
description: '',
},
{
label: 'Should the first comment be public?',
key: 'publicOrNot',
type: 'dropdown' as const,
required: false,
variables: true,
description: '',
options: [
{ label: 'Yes', value: 'yes' },
{ label: 'No', value: 'no' },
],
},
{
label: 'Tags',
key: 'tags',
type: 'string' as const,
required: false,
variables: true,
description: 'A comma separated list of tags.',
},
{
label: 'Type',
key: 'type',
type: 'dropdown' as const,
required: false,
variables: true,
description: '',
options: [
{ label: 'Problem', value: 'problem' },
{ label: 'Incident', value: 'incident' },
{ label: 'Question', value: 'question' },
{ label: 'Task', value: 'task' },
],
},
{
label: 'Priority',
key: 'priority',
type: 'dropdown' as const,
required: false,
variables: true,
description: '',
options: [
{ label: 'Urgent', value: 'urgent' },
{ label: 'High', value: 'high' },
{ label: 'Normal', value: 'normal' },
{ label: 'Low', value: 'low' },
],
},
{
label: 'Submitter',
key: 'submitterId',
type: 'dropdown' as const,
required: false,
variables: true,
description: '',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
{
name: 'parameters.includeAdmins',
value: 'false',
},
],
},
},
];

View File

@@ -0,0 +1,57 @@
import defineAction from '../../../../helpers/define-action';
import { fields } from './fields';
import isEmpty from 'lodash/isEmpty';
import omitBy from 'lodash/omitBy';
export default defineAction({
name: 'Update ticket',
key: 'updateTicket',
description: 'Modify the status of an existing ticket or append comments.',
arguments: fields,
async run($) {
const {
ticketId,
subject,
assigneeId,
groupId,
status,
comment,
publicOrNot,
type,
priority,
submitterId,
} = $.step.parameters;
const tags = $.step.parameters.tags as string;
const formattedTags = tags.split(',');
const payload = {
subject,
assignee_id: assigneeId,
group_id: groupId,
status,
comment: {
body: comment,
public: publicOrNot,
},
tags: formattedTags,
type,
priority,
submitter_id: submitterId,
};
const fieldsToRemoveIfEmpty = ['group_id', 'status', 'type', 'priority'];
const filteredPayload = omitBy(
payload,
(value, key) => fieldsToRemoveIfEmpty.includes(key) && isEmpty(value)
);
const response = await $.http.put(`/api/v2/tickets/${ticketId}`, {
ticket: filteredPayload,
});
$.setActionItem({ raw: response.data });
},
});

View File

@@ -2,6 +2,7 @@ import listUsers from './list-users';
import listBrands from './list-brands';
import listGroups from './list-groups';
import listSharingAgreements from './list-sharing-agreements';
import listFirstPageOfTickets from './list-first-page-of-tickets';
import listTicketForms from './list-ticket-forms';
import listViews from './list-views';
@@ -10,6 +11,7 @@ export default [
listBrands,
listGroups,
listSharingAgreements,
listFirstPageOfTickets,
listTicketForms,
listViews,
];

View File

@@ -0,0 +1,33 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List first page of tickets',
key: 'listFirstPageOfTickets',
async run($: IGlobalVariable) {
const tickets: {
data: IJSONObject[];
} = {
data: [],
};
const params = {
'page[size]': 100,
sort: '-id',
};
const response = await $.http.get('/api/v2/tickets', { params });
const allTickets = response.data.tickets;
if (allTickets?.length) {
for (const ticket of allTickets) {
tickets.data.push({
value: ticket.id,
name: ticket.subject,
});
}
}
return tickets;
},
};

View File

@@ -3,6 +3,8 @@ favicon: /favicons/zendesk.svg
items:
- name: Create ticket
desc: Creates a new ticket.
- name: Update ticket
desc: Modify the status of an existing ticket or append comments.
---
<script setup>