feat(pipedrive): add new notes trigger

This commit is contained in:
Rıdvan Akca
2023-09-22 12:42:35 +03:00
committed by Faruk AYDIN
parent e43c083d50
commit 991f593b2e
3 changed files with 60 additions and 1 deletions

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>