Skip to content

Commit

Permalink
feat(pipedrive): add create activity action
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca committed Oct 4, 2023
1 parent 8d90cb8 commit 6191413
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 1 deletion.
206 changes: 206 additions & 0 deletions packages/backend/src/apps/pipedrive/actions/create-activity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import defineAction from '../../../../helpers/define-action';

function filterProvidedFields(body: Record<string, unknown>) {
return Object.keys(body).reduce<Record<string, unknown>>((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,
});
},
});
3 changes: 2 additions & 1 deletion packages/backend/src/apps/pipedrive/actions/index.ts
Original file line number Diff line number Diff line change
@@ -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];
2 changes: 2 additions & 0 deletions packages/backend/src/apps/pipedrive/dynamic-data/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -6,6 +7,7 @@ import listPersons from './list-persons';
import listUsers from './list-users';

export default [
listActivityTypes,
listCurrencies,
listDeals,
listLeads,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
},
};
2 changes: 2 additions & 0 deletions packages/docs/pages/apps/pipedrive/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
---

<script setup>
Expand Down

0 comments on commit 6191413

Please sign in to comment.