feat(zendesk): add create user action

This commit is contained in:
Rıdvan Akca
2023-11-27 14:28:21 +03:00
parent b4e12b0ea8
commit b07bd4374f
6 changed files with 205 additions and 1 deletions

View File

@@ -0,0 +1,102 @@
export const fields = [
{
label: 'Name',
key: 'name',
type: 'string' as const,
required: true,
variables: true,
description: '',
},
{
label: 'Email',
key: 'email',
type: 'string' as const,
required: true,
variables: true,
description:
'It is essential to be distinctive. Zendesk prohibits the existence of identical users sharing the same email address.',
},
{
label: 'Details',
key: 'details',
type: 'string' as const,
required: false,
variables: true,
description: '',
},
{
label: 'Notes',
key: 'notes',
type: 'string' as const,
required: false,
variables: true,
description:
'Within this field, you have the capability to save any remarks or comments you may have concerning the user.',
},
{
label: 'Phone',
key: 'phone',
type: 'string' as const,
required: false,
variables: true,
description:
"The user's contact number should be entered in the following format: +1 (555) 123-4567.",
},
{
label: 'Tags',
key: 'tags',
type: 'string' as const,
required: false,
variables: true,
description: 'A comma separated list of tags.',
},
{
label: 'Role',
key: 'role',
type: 'string' as const,
required: false,
variables: true,
description:
"It can take on one of the designated roles: 'end-user', 'agent', or 'admin'. If a different value is set or none is specified, the default is 'end-user.'",
},
{
label: 'Organization',
key: 'organizationId',
type: 'dropdown' as const,
required: false,
variables: true,
description: 'Assign this user to a specific organization.',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listOrganizations',
},
],
},
},
{
label: 'External Id',
key: 'externalId',
type: 'string' as const,
required: false,
variables: true,
description:
'An exclusive external identifier; you can utilize this to link organizations with an external record.',
},
{
label: 'Verified',
key: 'verified',
type: 'dropdown' as const,
required: false,
description:
"Specify if you can verify that the user's assertion of their identity is accurate.",
variables: true,
options: [
{ label: 'True', value: 'true' },
{ label: 'False', value: 'false' },
],
},
];

View File

@@ -0,0 +1,53 @@
import { IJSONObject } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import { fields } from './fields';
type Payload = {
user: IJSONObject;
};
export default defineAction({
name: 'Create user',
key: 'createUser',
description: 'Creates a new user.',
arguments: fields,
async run($) {
const {
name,
email,
details,
notes,
phone,
role,
organizationId,
externalId,
verified,
} = $.step.parameters;
const tags = $.step.parameters.tags as string;
const formattedTags = tags.split(',');
const payload: Payload = {
user: {
name,
email,
details,
notes,
phone,
organization_id: organizationId,
external_id: externalId,
verified: verified || 'false',
tags: formattedTags,
},
};
if (role) {
payload.user.role = role;
}
const response = await $.http.post('/api/v2/users', payload);
$.setActionItem({ raw: response.data });
},
});

View File

@@ -1,6 +1,13 @@
import createTicket from './create-ticket'; import createTicket from './create-ticket';
import createUser from './create-user';
import deleteTicket from './delete-ticket'; import deleteTicket from './delete-ticket';
import findTicket from './find-ticket'; import findTicket from './find-ticket';
import updateTicket from './update-ticket'; import updateTicket from './update-ticket';
export default [createTicket, deleteTicket, findTicket, updateTicket]; export default [
createTicket,
createUser,
deleteTicket,
findTicket,
updateTicket,
];

View File

@@ -2,6 +2,7 @@ import listUsers from './list-users';
import listBrands from './list-brands'; import listBrands from './list-brands';
import listFirstPageOfTickets from './list-first-page-of-tickets'; import listFirstPageOfTickets from './list-first-page-of-tickets';
import listGroups from './list-groups'; import listGroups from './list-groups';
import listOrganizations from './list-organizations';
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'; import listViews from './list-views';
@@ -11,6 +12,7 @@ export default [
listBrands, listBrands,
listFirstPageOfTickets, listFirstPageOfTickets,
listGroups, listGroups,
listOrganizations,
listSharingAgreements, listSharingAgreements,
listFirstPageOfTickets, listFirstPageOfTickets,
listTicketForms, listTicketForms,

View File

@@ -0,0 +1,38 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List organizations',
key: 'listOrganizations',
async run($: IGlobalVariable) {
const organizations: {
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/organizations', { params });
const allOrganizations = response?.data?.organizations;
hasMore = response?.data?.meta?.has_more;
params['page[after]'] = response.data.meta?.after_cursor;
if (allOrganizations?.length) {
for (const organization of allOrganizations) {
organizations.data.push({
value: organization.id,
name: organization.name,
});
}
}
} while (hasMore);
return organizations;
},
};

View File

@@ -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: Create user
desc: Creates a new user.
- name: Delete ticket - name: Delete ticket
desc: Deletes an existing ticket. desc: Deletes an existing ticket.
- name: Find ticket - name: Find ticket