diff --git a/packages/backend/src/apps/pipedrive/auth/refresh-token.ts b/packages/backend/src/apps/pipedrive/auth/refresh-token.ts index 89a3b71f..42994e38 100644 --- a/packages/backend/src/apps/pipedrive/auth/refresh-token.ts +++ b/packages/backend/src/apps/pipedrive/auth/refresh-token.ts @@ -24,6 +24,7 @@ const refreshToken = async ($: IGlobalVariable) => { await $.auth.set({ accessToken: response.data.access_token, + refreshToken: response.data.refresh_token, tokenType: response.data.token_type, expiresIn: response.data.expires_in, }); diff --git a/packages/backend/src/apps/pipedrive/index.ts b/packages/backend/src/apps/pipedrive/index.ts index 9999729e..3e01bfa7 100644 --- a/packages/backend/src/apps/pipedrive/index.ts +++ b/packages/backend/src/apps/pipedrive/index.ts @@ -1,6 +1,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; +import triggers from './triggers'; export default defineApp({ name: 'Pipedrive', @@ -13,4 +14,5 @@ export default defineApp({ supportsConnections: true, beforeRequest: [addAuthHeader], auth, + triggers, }); diff --git a/packages/backend/src/apps/pipedrive/triggers/index.ts b/packages/backend/src/apps/pipedrive/triggers/index.ts new file mode 100644 index 00000000..4e595290 --- /dev/null +++ b/packages/backend/src/apps/pipedrive/triggers/index.ts @@ -0,0 +1,3 @@ +import newDeals from './new-deals'; + +export default [newDeals]; diff --git a/packages/backend/src/apps/pipedrive/triggers/new-deals/index.ts b/packages/backend/src/apps/pipedrive/triggers/new-deals/index.ts new file mode 100644 index 00000000..204d01c3 --- /dev/null +++ b/packages/backend/src/apps/pipedrive/triggers/new-deals/index.ts @@ -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 deals', + key: 'newDeals', + pollInterval: 15, + description: 'Triggers when a new deal is created.', + arguments: [], + + async run($) { + const params: Payload = { + start: 0, + limit: 100, + sort: 'add_time DESC', + }; + + do { + const { data } = await $.http.get( + `${$.auth.data.apiDomain}/api/v1/deals`, + { params } + ); + + if (!data.data.length) { + return; + } + + params.start = data.additional_data?.pagination?.next_start; + + for (const deal of data.data) { + $.pushTriggerItem({ + raw: deal, + meta: { + internalId: deal.id.toString(), + }, + }); + } + } while (params.start); + }, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 71676c16..3058a946 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -215,6 +215,15 @@ export default defineConfig({ { text: 'Connection', link: '/apps/openai/connection' }, ], }, + { + text: 'Pipedrive', + collapsible: true, + collapsed: true, + items: [ + { text: 'Triggers', link: '/apps/pipedrive/triggers' }, + { text: 'Connection', link: '/apps/pipedrive/connection' }, + ], + }, { text: 'PostgreSQL', collapsible: true, diff --git a/packages/docs/pages/apps/pipedrive/connection.md b/packages/docs/pages/apps/pipedrive/connection.md new file mode 100644 index 00000000..aa94cfbc --- /dev/null +++ b/packages/docs/pages/apps/pipedrive/connection.md @@ -0,0 +1,17 @@ +# Pipedrive + +:::info +This page explains the steps you need to follow to set up the Pipedrive +connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +1. Go to [Pipedrive developers page](https://developers.pipedrive.com/). +2. Sign up for a **Sandbox account** in order to create an app. +3. Click create an app button and then choose **Create private app** option. +4. Write any app name to be displayed in Automatisch. +5. Copy **OAuth Redirect URL** from Automatisch to **Callback URL** field, and click on the **Save** button. +6. Check all options in **OAuth & Access scopes** with full access. +7. Click on the **Save** button. +8. Copy the **Client ID** value to the `Client ID` field on Automatisch. +9. Copy the **Client Secret** value to the `Client Secret` field on Automatisch. +10. Start using Pipedrive integration with Automatisch! diff --git a/packages/docs/pages/apps/pipedrive/triggers.md b/packages/docs/pages/apps/pipedrive/triggers.md new file mode 100644 index 00000000..e6b3b94d --- /dev/null +++ b/packages/docs/pages/apps/pipedrive/triggers.md @@ -0,0 +1,12 @@ +--- +favicon: /favicons/pipedrive.svg +items: + - name: New deals + desc: Triggers when a new deal is created. +--- + + + + diff --git a/packages/docs/pages/public/favicons/pipedrive.svg b/packages/docs/pages/public/favicons/pipedrive.svg new file mode 100644 index 00000000..5efad428 --- /dev/null +++ b/packages/docs/pages/public/favicons/pipedrive.svg @@ -0,0 +1 @@ + \ No newline at end of file