Merge pull request #1297 from automatisch/pipedrive-new-note

feat(pipedrive): add new notes trigger
This commit is contained in:
Ömer Faruk Aydın
2023-09-29 11:53:10 +02:00
committed by GitHub
5 changed files with 66 additions and 1 deletions

View File

@@ -19,6 +19,9 @@ const refreshToken = async ($: IGlobalVariable) => {
params.toString(),
{
headers,
additionalProperties: {
skipAddingAuthHeader: true,
},
}
);

View File

@@ -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}`;
}

View File

@@ -1,3 +1,4 @@
import newDeals from './new-deals';
import newNotes from './new-notes';
export default [newDeals];
export default [newDeals, newNotes];

View File

@@ -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);
},
});

View File

@@ -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>