diff --git a/packages/backend/src/apps/trello/dynamic-data/index.ts b/packages/backend/src/apps/trello/dynamic-data/index.ts new file mode 100644 index 00000000..94dfc629 --- /dev/null +++ b/packages/backend/src/apps/trello/dynamic-data/index.ts @@ -0,0 +1,4 @@ +import listBoardLists from './list-board-lists'; +import listBoards from './list-boards'; + +export default [listBoardLists, listBoards]; diff --git a/packages/backend/src/apps/trello/dynamic-data/list-board-lists/index.ts b/packages/backend/src/apps/trello/dynamic-data/list-board-lists/index.ts new file mode 100644 index 00000000..6ee93082 --- /dev/null +++ b/packages/backend/src/apps/trello/dynamic-data/list-board-lists/index.ts @@ -0,0 +1,33 @@ +import { IGlobalVariable, IJSONObject } from '@automatisch/types'; + +export default { + name: 'List board lists', + key: 'listBoardLists', + + async run($: IGlobalVariable) { + const boards: { + data: IJSONObject[]; + } = { + data: [], + }; + + const boardId = $.step.parameters.boardId; + + if (!boardId) { + return { data: [] }; + } + + const { data } = await $.http.get(`/1/boards/${boardId}/lists`); + + if (data) { + for (const list of data) { + boards.data.push({ + value: list.id, + name: list.name, + }); + } + } + + return boards; + }, +}; diff --git a/packages/backend/src/apps/trello/dynamic-data/list-boards/index.ts b/packages/backend/src/apps/trello/dynamic-data/list-boards/index.ts new file mode 100644 index 00000000..52e291b9 --- /dev/null +++ b/packages/backend/src/apps/trello/dynamic-data/list-boards/index.ts @@ -0,0 +1,29 @@ +import { IGlobalVariable, IJSONObject } from '@automatisch/types'; + +export default { + name: 'List boards', + key: 'listBoards', + + async run($: IGlobalVariable) { + const boards: { + data: IJSONObject[]; + } = { + data: [], + }; + + const { data } = await $.http.get(`/1/members/me/boards`); + + if (data) { + for (const board of data) { + boards.data.push({ + value: board.id, + name: board.name, + }); + } + } else { + return { data: [] }; + } + + return boards; + }, +}; diff --git a/packages/backend/src/apps/trello/index.ts b/packages/backend/src/apps/trello/index.ts index e6b54d85..c3f6bb0c 100644 --- a/packages/backend/src/apps/trello/index.ts +++ b/packages/backend/src/apps/trello/index.ts @@ -1,6 +1,8 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; +import triggers from './triggers'; +import dynamicData from './dynamic-data'; export default defineApp({ name: 'Trello', @@ -13,4 +15,6 @@ export default defineApp({ primaryColor: '0079bf', beforeRequest: [addAuthHeader], auth, + triggers, + dynamicData, }); diff --git a/packages/backend/src/apps/trello/triggers/index.ts b/packages/backend/src/apps/trello/triggers/index.ts new file mode 100644 index 00000000..e7218ecd --- /dev/null +++ b/packages/backend/src/apps/trello/triggers/index.ts @@ -0,0 +1,3 @@ +import newCards from './new-cards'; + +export default [newCards]; diff --git a/packages/backend/src/apps/trello/triggers/new-cards/index.ts b/packages/backend/src/apps/trello/triggers/new-cards/index.ts new file mode 100644 index 00000000..bdd10080 --- /dev/null +++ b/packages/backend/src/apps/trello/triggers/new-cards/index.ts @@ -0,0 +1,123 @@ +import defineTrigger from '../../../../helpers/define-trigger'; + +export default defineTrigger({ + name: 'New cards', + key: 'newCards', + pollInterval: 15, + description: 'Triggers upon the addition of a new card.', + arguments: [ + { + label: 'Board', + key: 'boardId', + type: 'dropdown' as const, + required: false, + description: + 'Selecting a board initiates the trigger for newly added cards on that board.', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listBoards', + }, + ], + }, + }, + { + label: 'List', + key: 'listId', + type: 'dropdown' as const, + required: false, + dependsOn: ['parameters.boardId'], + description: 'Requires to opt for a board.', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listBoardLists', + }, + { + name: 'parameters.boardId', + value: '{parameters.boardId}', + }, + ], + }, + }, + { + label: 'Filter', + key: 'filter', + type: 'dropdown' as const, + required: false, + description: 'Default is open.', + variables: true, + options: [ + { + label: 'open', + value: 'open', + }, + { + label: 'closed', + value: 'closed', + }, + { + label: 'all', + value: 'all', + }, + ], + }, + ], + + async run($) { + const { boardId, listId, filter } = $.step.parameters; + + if (boardId && !listId) { + const cardFilter = filter || 'open'; + + const { data } = await $.http.get( + `/1/boards/${boardId}/cards/${cardFilter}` + ); + + if (data) { + for (const card of data) { + $.pushTriggerItem({ + raw: card, + meta: { + internalId: card.id, + }, + }); + } + } + } else if (listId) { + const { data } = await $.http.get(`1/lists/${listId}/cards`); + + if (data) { + for (const card of data) { + $.pushTriggerItem({ + raw: card, + meta: { + internalId: card.id, + }, + }); + } + } + } else { + const { data } = await $.http.get(`/1/members/me/cards`); + + if (data) { + for (const card of data) { + $.pushTriggerItem({ + raw: card, + meta: { + internalId: card.id, + }, + }); + } + } + } + }, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 29b9b2fb..c6f27028 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -377,7 +377,10 @@ export default defineConfig({ text: 'Trello', collapsible: true, collapsed: true, - items: [{ text: 'Connection', link: '/apps/trello/connection' }], + items: [ + { text: 'Triggers', link: '/apps/trello/triggers' }, + { text: 'Connection', link: '/apps/trello/connection' }, + ], }, { text: 'Twilio', diff --git a/packages/docs/pages/apps/trello/triggers.md b/packages/docs/pages/apps/trello/triggers.md new file mode 100644 index 00000000..2aceda00 --- /dev/null +++ b/packages/docs/pages/apps/trello/triggers.md @@ -0,0 +1,12 @@ +--- +favicon: /favicons/trello.svg +items: + - name: New cards + desc: Triggers upon the addition of a new card. +--- + + + + diff --git a/packages/docs/pages/guide/available-apps.md b/packages/docs/pages/guide/available-apps.md index b6f2d901..2406e207 100644 --- a/packages/docs/pages/guide/available-apps.md +++ b/packages/docs/pages/guide/available-apps.md @@ -39,6 +39,7 @@ The following integrations are currently supported by Automatisch. - [Stripe](/apps/stripe/triggers) - [Telegram](/apps/telegram-bot/actions) - [Todoist](/apps/todoist/triggers) +- [Trello](/apps/trello/triggers) - [Twilio](/apps/twilio/triggers) - [Twitter](/apps/twitter/triggers) - [Typeform](/apps/typeform/triggers)