Merge pull request #1443 from automatisch/AUT-411
feat(zendesk): add update ticket action
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
import createTicket from './create-ticket';
|
import createTicket from './create-ticket';
|
||||||
|
import updateTicket from './update-ticket';
|
||||||
|
|
||||||
export default [createTicket];
|
export default [createTicket, updateTicket];
|
||||||
|
@@ -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',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
@@ -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 });
|
||||||
|
},
|
||||||
|
});
|
@@ -2,6 +2,7 @@ import listUsers from './list-users';
|
|||||||
import listBrands from './list-brands';
|
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 listFirstPageOfTickets from './list-first-page-of-tickets';
|
||||||
import listTicketForms from './list-ticket-forms';
|
import listTicketForms from './list-ticket-forms';
|
||||||
import listViews from './list-views';
|
import listViews from './list-views';
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ export default [
|
|||||||
listBrands,
|
listBrands,
|
||||||
listGroups,
|
listGroups,
|
||||||
listSharingAgreements,
|
listSharingAgreements,
|
||||||
|
listFirstPageOfTickets,
|
||||||
listTicketForms,
|
listTicketForms,
|
||||||
listViews,
|
listViews,
|
||||||
];
|
];
|
||||||
|
@@ -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;
|
||||||
|
},
|
||||||
|
};
|
@@ -3,6 +3,8 @@ favicon: /favicons/zendesk.svg
|
|||||||
items:
|
items:
|
||||||
- name: Create ticket
|
- name: Create ticket
|
||||||
desc: Creates a new ticket.
|
desc: Creates a new ticket.
|
||||||
|
- name: Update ticket
|
||||||
|
desc: Modify the status of an existing ticket or append comments.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user