-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipedrive): add create activity action
- Loading branch information
1 parent
8d90cb8
commit 6191413
Showing
5 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
packages/backend/src/apps/pipedrive/actions/create-activity/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/backend/src/apps/pipedrive/dynamic-data/list-activity-types/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters