feat(pipedrive): add create activity action
This commit is contained in:
@@ -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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,4 +1,5 @@
|
|||||||
|
import createActivity from './create-activity';
|
||||||
import createDeal from './create-deal';
|
import createDeal from './create-deal';
|
||||||
import createNote from './create-note';
|
import createNote from './create-note';
|
||||||
|
|
||||||
export default [createDeal, createNote];
|
export default [createActivity, createDeal, createNote];
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import listActivityTypes from './list-activity-types';
|
||||||
import listCurrencies from './list-currencies';
|
import listCurrencies from './list-currencies';
|
||||||
import listDeals from './list-deals';
|
import listDeals from './list-deals';
|
||||||
import listLeads from './list-leads';
|
import listLeads from './list-leads';
|
||||||
@@ -6,6 +7,7 @@ import listPersons from './list-persons';
|
|||||||
import listUsers from './list-users';
|
import listUsers from './list-users';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
|
listActivityTypes,
|
||||||
listCurrencies,
|
listCurrencies,
|
||||||
listDeals,
|
listDeals,
|
||||||
listLeads,
|
listLeads,
|
||||||
|
@@ -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;
|
||||||
|
},
|
||||||
|
};
|
@@ -5,6 +5,8 @@ items:
|
|||||||
desc: Creates a new deal.
|
desc: Creates a new deal.
|
||||||
- name: Create note
|
- name: Create note
|
||||||
desc: Creates a new note.
|
desc: Creates a new note.
|
||||||
|
- name: Create activity
|
||||||
|
desc: Creates a new activity.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user