Merge pull request #1297 from automatisch/pipedrive-new-note
feat(pipedrive): add new notes trigger
This commit is contained in:
@@ -19,6 +19,9 @@ const refreshToken = async ($: IGlobalVariable) => {
|
||||
params.toString(),
|
||||
{
|
||||
headers,
|
||||
additionalProperties: {
|
||||
skipAddingAuthHeader: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
if (requestConfig.additionalProperties?.skipAddingAuthHeader)
|
||||
return requestConfig;
|
||||
|
||||
if ($.auth.data?.accessToken) {
|
||||
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import newDeals from './new-deals';
|
||||
import newNotes from './new-notes';
|
||||
|
||||
export default [newDeals];
|
||||
export default [newDeals, newNotes];
|
||||
|
@@ -0,0 +1,56 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
|
||||
type Payload = {
|
||||
start: number;
|
||||
limit: number;
|
||||
sort: string;
|
||||
};
|
||||
|
||||
type ResponseData = {
|
||||
data: {
|
||||
id: number;
|
||||
}[];
|
||||
additional_data: {
|
||||
pagination: {
|
||||
next_start: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New notes',
|
||||
key: 'newNotes',
|
||||
pollInterval: 15,
|
||||
description: 'Triggers when a new note is created.',
|
||||
arguments: [],
|
||||
|
||||
async run($) {
|
||||
const params: Payload = {
|
||||
start: 0,
|
||||
limit: 100,
|
||||
sort: 'add_time DESC',
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get<ResponseData>(
|
||||
`${$.auth.data.apiDomain}/api/v1/notes`,
|
||||
{ params }
|
||||
);
|
||||
|
||||
if (!data?.data?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
params.start = data.additional_data?.pagination?.next_start;
|
||||
|
||||
for (const note of data.data) {
|
||||
$.pushTriggerItem({
|
||||
raw: note,
|
||||
meta: {
|
||||
internalId: note.id.toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
} while (params.start);
|
||||
},
|
||||
});
|
@@ -3,6 +3,8 @@ favicon: /favicons/pipedrive.svg
|
||||
items:
|
||||
- name: New deals
|
||||
desc: Triggers when a new deal is created.
|
||||
- name: New notes
|
||||
desc: Triggers when a new note is created.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
|
Reference in New Issue
Block a user