From fedb198ae73ba544874a461a937555be397007c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Wed, 4 Oct 2023 12:51:58 +0300 Subject: [PATCH] feat(pipedrive): add create activity action --- .../actions/create-activity/index.ts | 206 ++++++++++++++++++ .../src/apps/pipedrive/actions/index.ts | 3 +- .../src/apps/pipedrive/dynamic-data/index.ts | 2 + .../dynamic-data/list-activity-types/index.ts | 33 +++ packages/docs/pages/apps/pipedrive/actions.md | 2 + 5 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/pipedrive/actions/create-activity/index.ts create mode 100644 packages/backend/src/apps/pipedrive/dynamic-data/list-activity-types/index.ts diff --git a/packages/backend/src/apps/pipedrive/actions/create-activity/index.ts b/packages/backend/src/apps/pipedrive/actions/create-activity/index.ts new file mode 100644 index 0000000000..b65bc1d82d --- /dev/null +++ b/packages/backend/src/apps/pipedrive/actions/create-activity/index.ts @@ -0,0 +1,206 @@ +import defineAction from '../../../../helpers/define-action'; + +function filterProvidedFields(body: Record) { + return Object.keys(body).reduce>((result, key) => { + if (body[key]) { + result[key] = body[key]; + } + return result; + }, {}); +} + +export default defineAction({ + name: 'Create activity', + key: 'createNote', + description: 'Creates a new activity.', + arguments: [ + { + label: 'Subject', + key: 'subject', + type: 'string' as const, + required: true, + description: '', + variables: true, + }, + { + label: 'Organization', + key: 'organizationId', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listOrganizations', + }, + ], + }, + }, + { + label: 'Assigned To', + key: 'userId', + type: 'dropdown' as const, + required: false, + description: + 'If omitted, the activity will be assigned to the user of the connected account.', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listUsers', + }, + ], + }, + }, + { + label: 'Person', + key: 'personId', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listPersons', + }, + ], + }, + }, + { + label: 'Deal', + key: 'dealId', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listDeals', + }, + ], + }, + }, + { + label: 'Is done?', + key: 'isDone', + type: 'dropdown' as const, + required: false, + description: '', + options: [ + { + label: 'No', + value: 0, + }, + { + label: 'Yes', + value: 1, + }, + ], + }, + { + label: 'Type', + key: 'type', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listActivityTypes', + }, + ], + }, + }, + { + label: 'Due Date', + key: 'dueDate', + type: 'string' as const, + required: false, + description: 'Format must be YYYY-MM-DD', + variables: true, + }, + { + label: 'Due Time', + key: 'dueTime', + type: 'string' as const, + required: false, + description: 'Format must be HH:MM', + variables: true, + }, + { + label: 'Duration', + key: 'duration', + type: 'string' as const, + required: false, + description: 'Format must be HH:MM', + variables: true, + }, + { + label: 'Note', + key: 'note', + type: 'string' as const, + required: false, + description: 'Accepts HTML format', + variables: true, + }, + ], + + async run($) { + const { + subject, + organizationId, + userId, + personId, + dealId, + isDone, + type, + dueTime, + dueDate, + duration, + note, + } = $.step.parameters; + + const fields = { + subject: subject as string, + org_id: organizationId as number, + user_id: userId as number, + person_id: personId as number, + deal_id: dealId as number, + done: isDone as number, + type: type as string, + due_time: dueTime as string, + due_date: dueDate as string, + duration: duration as string, + note: note as string, + }; + + const body = filterProvidedFields(fields); + + const { + data: { data }, + } = await $.http.post(`${$.auth.data.apiDomain}/api/v1/activities`, body); + + $.setActionItem({ + raw: data, + }); + }, +}); diff --git a/packages/backend/src/apps/pipedrive/actions/index.ts b/packages/backend/src/apps/pipedrive/actions/index.ts index 516066d795..23450a7b25 100644 --- a/packages/backend/src/apps/pipedrive/actions/index.ts +++ b/packages/backend/src/apps/pipedrive/actions/index.ts @@ -1,4 +1,5 @@ +import createActivity from './create-activity'; import createDeal from './create-deal'; import createNote from './create-note'; -export default [createDeal, createNote]; +export default [createActivity, createDeal, createNote]; diff --git a/packages/backend/src/apps/pipedrive/dynamic-data/index.ts b/packages/backend/src/apps/pipedrive/dynamic-data/index.ts index 7af49dcc79..f10ab0e8b2 100644 --- a/packages/backend/src/apps/pipedrive/dynamic-data/index.ts +++ b/packages/backend/src/apps/pipedrive/dynamic-data/index.ts @@ -1,3 +1,4 @@ +import listActivityTypes from './list-activity-types'; import listCurrencies from './list-currencies'; import listDeals from './list-deals'; import listLeads from './list-leads'; @@ -6,6 +7,7 @@ import listPersons from './list-persons'; import listUsers from './list-users'; export default [ + listActivityTypes, listCurrencies, listDeals, listLeads, diff --git a/packages/backend/src/apps/pipedrive/dynamic-data/list-activity-types/index.ts b/packages/backend/src/apps/pipedrive/dynamic-data/list-activity-types/index.ts new file mode 100644 index 0000000000..c6f8dc3a03 --- /dev/null +++ b/packages/backend/src/apps/pipedrive/dynamic-data/list-activity-types/index.ts @@ -0,0 +1,33 @@ +import { IGlobalVariable, IJSONObject } from '@automatisch/types'; + +export default { + name: 'List activity types', + key: 'listActivityTypes', + + async run($: IGlobalVariable) { + const activityTypes: { + data: IJSONObject[]; + } = { + data: [], + }; + + const { data } = await $.http.get( + `${$.auth.data.apiDomain}/api/v1/activityTypes` + ); + + if (!data?.data) { + return { data: [] }; + } + + if (data.data.length) { + for (const activityType of data.data) { + activityTypes.data.push({ + value: activityType.key_string, + name: activityType.name, + }); + } + } + + return activityTypes; + }, +}; diff --git a/packages/docs/pages/apps/pipedrive/actions.md b/packages/docs/pages/apps/pipedrive/actions.md index 996b2ebe5a..d10197eeac 100644 --- a/packages/docs/pages/apps/pipedrive/actions.md +++ b/packages/docs/pages/apps/pipedrive/actions.md @@ -5,6 +5,8 @@ items: desc: Creates a new deal. - name: Create note desc: Creates a new note. + - name: Create activity + desc: Creates a new activity. ---