Merge pull request #1313 from automatisch/AUT-303
feat(pipedrive): add create note action
This commit is contained in:
206
packages/backend/src/apps/pipedrive/actions/create-note/index.ts
Normal file
206
packages/backend/src/apps/pipedrive/actions/create-note/index.ts
Normal file
@@ -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 note',
|
||||||
|
key: 'createNote',
|
||||||
|
description: 'Creates a new note.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Content',
|
||||||
|
key: 'content',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: true,
|
||||||
|
description: 'Supports some HTML formatting.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Deal',
|
||||||
|
key: 'dealId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Note must be associated with at least one deal, person, organization, or lead.',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listDeals',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pin note on specified deal?',
|
||||||
|
key: 'pinnedDeal',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Person',
|
||||||
|
key: 'personId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Note must be associated with at least one deal, person, organization, or lead.',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listPersons',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pin note on specified person?',
|
||||||
|
key: 'pinnedPerson',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Organization',
|
||||||
|
key: 'organizationId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Note must be associated with at least one deal, person, organization, or lead.',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listOrganizations',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pin note on specified organization?',
|
||||||
|
key: 'pinnedOrganization',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Lead',
|
||||||
|
key: 'leadId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Note must be associated with at least one deal, person, organization, or lead.',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listLeads',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pin note on specified lead?',
|
||||||
|
key: 'pinnedLead',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const {
|
||||||
|
content,
|
||||||
|
dealId,
|
||||||
|
pinnedDeal,
|
||||||
|
personId,
|
||||||
|
pinnedPerson,
|
||||||
|
organizationId,
|
||||||
|
pinnedOrganization,
|
||||||
|
leadId,
|
||||||
|
pinnedLead,
|
||||||
|
} = $.step.parameters;
|
||||||
|
|
||||||
|
const fields = {
|
||||||
|
content: content as string,
|
||||||
|
deal_id: dealId as number,
|
||||||
|
pinned_to_deal_flag: pinnedDeal as number,
|
||||||
|
person_id: personId as number,
|
||||||
|
pinned_to_person_flag: pinnedPerson as number,
|
||||||
|
org_id: organizationId as number,
|
||||||
|
pinned_to_organization_flag: pinnedOrganization as number,
|
||||||
|
lead_id: leadId as string,
|
||||||
|
pinned_to_lead_flag: pinnedLead as number,
|
||||||
|
};
|
||||||
|
|
||||||
|
const body = filterProvidedFields(fields);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { data },
|
||||||
|
} = await $.http.post(`${$.auth.data.apiDomain}/api/v1/notes`, body);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,3 +1,4 @@
|
|||||||
import createDeal from './create-deal';
|
import createDeal from './create-deal';
|
||||||
|
import createNote from './create-note';
|
||||||
|
|
||||||
export default [createDeal];
|
export default [createDeal, createNote];
|
||||||
|
@@ -1,6 +1,15 @@
|
|||||||
import listCurrencies from './list-currencies';
|
import listCurrencies from './list-currencies';
|
||||||
|
import listDeals from './list-deals';
|
||||||
|
import listLeads from './list-leads';
|
||||||
import listOrganizations from './list-organizations';
|
import listOrganizations from './list-organizations';
|
||||||
import listPersons from './list-persons';
|
import listPersons from './list-persons';
|
||||||
import listUsers from './list-users';
|
import listUsers from './list-users';
|
||||||
|
|
||||||
export default [listCurrencies, listOrganizations, listPersons, listUsers];
|
export default [
|
||||||
|
listCurrencies,
|
||||||
|
listDeals,
|
||||||
|
listLeads,
|
||||||
|
listOrganizations,
|
||||||
|
listPersons,
|
||||||
|
listUsers,
|
||||||
|
];
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'List deals',
|
||||||
|
key: 'listDeals',
|
||||||
|
|
||||||
|
async run($: IGlobalVariable) {
|
||||||
|
const deals: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
sort: 'add_time DESC',
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.get(`${$.auth.data.apiDomain}/api/v1/deals`, {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data?.data) {
|
||||||
|
return { data: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.data.length) {
|
||||||
|
for (const deal of data.data) {
|
||||||
|
deals.data.push({
|
||||||
|
value: deal.id,
|
||||||
|
name: deal.title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deals;
|
||||||
|
},
|
||||||
|
};
|
@@ -0,0 +1,37 @@
|
|||||||
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'List leads',
|
||||||
|
key: 'listLeads',
|
||||||
|
|
||||||
|
async run($: IGlobalVariable) {
|
||||||
|
const leads: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
sort: 'add_time DESC',
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.get(`${$.auth.data.apiDomain}/api/v1/leads`, {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data?.data) {
|
||||||
|
return { data: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.data.length) {
|
||||||
|
for (const lead of data.data) {
|
||||||
|
leads.data.push({
|
||||||
|
value: lead.id,
|
||||||
|
name: lead.title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return leads;
|
||||||
|
},
|
||||||
|
};
|
@@ -3,6 +3,8 @@ favicon: /favicons/pipedrive.svg
|
|||||||
items:
|
items:
|
||||||
- name: Create deal
|
- name: Create deal
|
||||||
desc: Creates a new deal.
|
desc: Creates a new deal.
|
||||||
|
- name: Create note
|
||||||
|
desc: Creates a new note.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user