From 7a6aa99840cd34a76f5e5bf6d8156164a2371dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Thu, 14 Dec 2023 13:55:41 +0300 Subject: [PATCH 01/12] feat(google-tasks): add google tasks integration --- .../src/apps/google-tasks/assets/favicon.svg | 16 +++++++ .../google-tasks/auth/generate-auth-url.js | 23 +++++++++ .../src/apps/google-tasks/auth/index.js | 48 +++++++++++++++++++ .../google-tasks/auth/is-still-verified.js | 8 ++++ .../apps/google-tasks/auth/refresh-token.js | 25 ++++++++++ .../google-tasks/auth/verify-credentials.js | 42 ++++++++++++++++ .../google-tasks/common/add-auth-header.js | 9 ++++ .../apps/google-tasks/common/auth-scope.js | 7 +++ .../google-tasks/common/get-current-user.js | 8 ++++ .../backend/src/apps/google-tasks/index.js | 16 +++++++ packages/docs/pages/.vitepress/config.js | 10 +++- .../pages/apps/google-tasks/connection.md | 28 +++++++++++ .../pages/public/favicons/google-tasks.svg | 16 +++++++ 13 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/google-tasks/assets/favicon.svg create mode 100644 packages/backend/src/apps/google-tasks/auth/generate-auth-url.js create mode 100644 packages/backend/src/apps/google-tasks/auth/index.js create mode 100644 packages/backend/src/apps/google-tasks/auth/is-still-verified.js create mode 100644 packages/backend/src/apps/google-tasks/auth/refresh-token.js create mode 100644 packages/backend/src/apps/google-tasks/auth/verify-credentials.js create mode 100644 packages/backend/src/apps/google-tasks/common/add-auth-header.js create mode 100644 packages/backend/src/apps/google-tasks/common/auth-scope.js create mode 100644 packages/backend/src/apps/google-tasks/common/get-current-user.js create mode 100644 packages/backend/src/apps/google-tasks/index.js create mode 100644 packages/docs/pages/apps/google-tasks/connection.md create mode 100644 packages/docs/pages/public/favicons/google-tasks.svg diff --git a/packages/backend/src/apps/google-tasks/assets/favicon.svg b/packages/backend/src/apps/google-tasks/assets/favicon.svg new file mode 100644 index 00000000..1de5d7ab --- /dev/null +++ b/packages/backend/src/apps/google-tasks/assets/favicon.svg @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/packages/backend/src/apps/google-tasks/auth/generate-auth-url.js b/packages/backend/src/apps/google-tasks/auth/generate-auth-url.js new file mode 100644 index 00000000..c972ae16 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/auth/generate-auth-url.js @@ -0,0 +1,23 @@ +import { URLSearchParams } from 'url'; +import authScope from '../common/auth-scope.js'; + +export default async function generateAuthUrl($) { + const oauthRedirectUrlField = $.app.auth.fields.find( + (field) => field.key == 'oAuthRedirectUrl' + ); + const redirectUri = oauthRedirectUrlField.value; + const searchParams = new URLSearchParams({ + client_id: $.auth.data.clientId, + redirect_uri: redirectUri, + prompt: 'select_account', + scope: authScope.join(' '), + response_type: 'code', + access_type: 'offline', + }); + + const url = `https://accounts.google.com/o/oauth2/v2/auth?${searchParams.toString()}`; + + await $.auth.set({ + url, + }); +} diff --git a/packages/backend/src/apps/google-tasks/auth/index.js b/packages/backend/src/apps/google-tasks/auth/index.js new file mode 100644 index 00000000..eefda57c --- /dev/null +++ b/packages/backend/src/apps/google-tasks/auth/index.js @@ -0,0 +1,48 @@ +import generateAuthUrl from './generate-auth-url.js'; +import verifyCredentials from './verify-credentials.js'; +import refreshToken from './refresh-token.js'; +import isStillVerified from './is-still-verified.js'; + +export default { + fields: [ + { + key: 'oAuthRedirectUrl', + label: 'OAuth Redirect URL', + type: 'string', + required: true, + readOnly: true, + value: '{WEB_APP_URL}/app/google-tasks/connections/add', + placeholder: null, + description: + 'When asked to input a redirect URL in Google Cloud, enter the URL above.', + clickToCopy: true, + }, + { + key: 'clientId', + label: 'Client ID', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: null, + clickToCopy: false, + }, + { + key: 'clientSecret', + label: 'Client Secret', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: null, + clickToCopy: false, + }, + ], + + generateAuthUrl, + verifyCredentials, + isStillVerified, + refreshToken, +}; diff --git a/packages/backend/src/apps/google-tasks/auth/is-still-verified.js b/packages/backend/src/apps/google-tasks/auth/is-still-verified.js new file mode 100644 index 00000000..68f4d7db --- /dev/null +++ b/packages/backend/src/apps/google-tasks/auth/is-still-verified.js @@ -0,0 +1,8 @@ +import getCurrentUser from '../common/get-current-user.js'; + +const isStillVerified = async ($) => { + const currentUser = await getCurrentUser($); + return !!currentUser.resourceName; +}; + +export default isStillVerified; diff --git a/packages/backend/src/apps/google-tasks/auth/refresh-token.js b/packages/backend/src/apps/google-tasks/auth/refresh-token.js new file mode 100644 index 00000000..f706ffa7 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/auth/refresh-token.js @@ -0,0 +1,25 @@ +import { URLSearchParams } from 'node:url'; +import authScope from '../common/auth-scope.js'; + +const refreshToken = async ($) => { + const params = new URLSearchParams({ + client_id: $.auth.data.clientId, + client_secret: $.auth.data.clientSecret, + grant_type: 'refresh_token', + refresh_token: $.auth.data.refreshToken, + }); + + const { data } = await $.http.post( + 'https://oauth2.googleapis.com/token', + params.toString() + ); + + await $.auth.set({ + accessToken: data.access_token, + expiresIn: data.expires_in, + scope: authScope.join(' '), + tokenType: data.token_type, + }); +}; + +export default refreshToken; diff --git a/packages/backend/src/apps/google-tasks/auth/verify-credentials.js b/packages/backend/src/apps/google-tasks/auth/verify-credentials.js new file mode 100644 index 00000000..a636b72c --- /dev/null +++ b/packages/backend/src/apps/google-tasks/auth/verify-credentials.js @@ -0,0 +1,42 @@ +import getCurrentUser from '../common/get-current-user.js'; + +const verifyCredentials = async ($) => { + const oauthRedirectUrlField = $.app.auth.fields.find( + (field) => field.key == 'oAuthRedirectUrl' + ); + const redirectUri = oauthRedirectUrlField.value; + const { data } = await $.http.post(`https://oauth2.googleapis.com/token`, { + client_id: $.auth.data.clientId, + client_secret: $.auth.data.clientSecret, + code: $.auth.data.code, + grant_type: 'authorization_code', + redirect_uri: redirectUri, + }); + + await $.auth.set({ + accessToken: data.access_token, + tokenType: data.token_type, + }); + + const currentUser = await getCurrentUser($); + + const { displayName } = currentUser.names.find( + (name) => name.metadata.primary + ); + const { value: email } = currentUser.emailAddresses.find( + (emailAddress) => emailAddress.metadata.primary + ); + + await $.auth.set({ + clientId: $.auth.data.clientId, + clientSecret: $.auth.data.clientSecret, + scope: $.auth.data.scope, + idToken: data.id_token, + expiresIn: data.expires_in, + refreshToken: data.refresh_token, + resourceName: currentUser.resourceName, + screenName: `${displayName} - ${email}`, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/google-tasks/common/add-auth-header.js b/packages/backend/src/apps/google-tasks/common/add-auth-header.js new file mode 100644 index 00000000..02477aa4 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/common/add-auth-header.js @@ -0,0 +1,9 @@ +const addAuthHeader = ($, requestConfig) => { + if ($.auth.data?.accessToken) { + requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`; + } + + return requestConfig; +}; + +export default addAuthHeader; diff --git a/packages/backend/src/apps/google-tasks/common/auth-scope.js b/packages/backend/src/apps/google-tasks/common/auth-scope.js new file mode 100644 index 00000000..030adb80 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/common/auth-scope.js @@ -0,0 +1,7 @@ +const authScope = [ + 'https://www.googleapis.com/auth/tasks', + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile', +]; + +export default authScope; diff --git a/packages/backend/src/apps/google-tasks/common/get-current-user.js b/packages/backend/src/apps/google-tasks/common/get-current-user.js new file mode 100644 index 00000000..2663ad20 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/common/get-current-user.js @@ -0,0 +1,8 @@ +const getCurrentUser = async ($) => { + const { data: currentUser } = await $.http.get( + 'https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses' + ); + return currentUser; +}; + +export default getCurrentUser; diff --git a/packages/backend/src/apps/google-tasks/index.js b/packages/backend/src/apps/google-tasks/index.js new file mode 100644 index 00000000..9b23d099 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/index.js @@ -0,0 +1,16 @@ +import defineApp from '../../helpers/define-app.js'; +import addAuthHeader from './common/add-auth-header.js'; +import auth from './auth/index.js'; + +export default defineApp({ + name: 'Google Tasks', + key: 'google-tasks', + baseUrl: 'https://calendar.google.com/calendar/u/0/r/tasks', + apiBaseUrl: 'https://tasks.googleapis.com', + iconUrl: '{BASE_URL}/apps/google-tasks/assets/favicon.svg', + authDocUrl: 'https://automatisch.io/docs/apps/google-tasks/connection', + primaryColor: '0066DA', + supportsConnections: true, + beforeRequest: [addAuthHeader], + auth, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 04d3fdcf..15dfc3fd 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -169,6 +169,14 @@ export default defineConfig({ { text: 'Connection', link: '/apps/google-sheets/connection' }, ], }, + { + text: 'Google Tasks', + collapsible: true, + collapsed: true, + items: [ + { text: 'Connection', link: '/apps/google-tasks/connection' }, + ], + }, { text: 'HTTP Request', collapsible: true, @@ -305,7 +313,7 @@ export default defineConfig({ collapsed: true, items: [ { text: 'Actions', link: '/apps/removebg/actions' }, - { text: 'Connection', link: '/apps/removebg/connection' } + { text: 'Connection', link: '/apps/removebg/connection' }, ], }, { diff --git a/packages/docs/pages/apps/google-tasks/connection.md b/packages/docs/pages/apps/google-tasks/connection.md new file mode 100644 index 00000000..c09c62df --- /dev/null +++ b/packages/docs/pages/apps/google-tasks/connection.md @@ -0,0 +1,28 @@ +# Google Tasks + +:::info +This page explains the steps you need to follow to set up the Google Tasks +connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +1. Go to the [Google Cloud Console](https://console.cloud.google.com) to create a project. +2. Click on the project drop-down menu at the top of the page, and click on the **New Project** button. +3. Enter a name for your project and click on the **Create** button. +4. Go to [API Library](https://console.cloud.google.com/apis/library) in Google Cloud console. +5. Search for **Google Tasks API** in the search bar and click on it. +6. Click on the **Enable** button to enable the API. +7. Repeat steps 5 and 6 for the **People API**. +8. Go to [OAuth consent screen](https://console.cloud.google.com/apis/credentials/consent) in Google Cloud console. +9. Select **External** here for starting your app in testing mode at first. Click on the **Create** button. +10. Fill **App Name**, **User Support Email**, and **Developer Contact Information**. Click on the **Save and Continue** button. +11. Skip adding or removing scopes and click on the **Save and Continue** button. +12. Click on the **Add Users** button and add a test email because only test users can access the app while publishing status is set to "Testing". +13. Click on the **Save and Continue** button and now you have configured the consent screen. +14. Go to [Credentials](https://console.cloud.google.com/apis/credentials) in Google Cloud console. +15. Click on the **Create Credentials** button and select the **OAuth client ID** option. +16. Select the application type as **Web application** and fill the **Name** field. +17. Copy **OAuth Redirect URL** from Automatisch to **Authorized redirect URIs** field, and click on the **Create** button. +18. Copy the **Your Client ID** value from the following popup to the `Client ID` field on Automatisch. +19. Copy the **Your Client Secret** value from the following popup to the `Client Secret` field on Automatisch. +20. Click **Submit** button on Automatisch. +21. Congrats! Start using your new Google Tasks connection within the flows. diff --git a/packages/docs/pages/public/favicons/google-tasks.svg b/packages/docs/pages/public/favicons/google-tasks.svg new file mode 100644 index 00000000..1de5d7ab --- /dev/null +++ b/packages/docs/pages/public/favicons/google-tasks.svg @@ -0,0 +1,16 @@ + + + + + + + + + From 92a9b096ecdc0c86ab1efc7009b33003b9a45042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Tue, 16 Jan 2024 16:27:45 +0300 Subject: [PATCH 02/12] feat(google-tasks): add find task action --- .../google-tasks/actions/find-task/index.js | 50 +++++++++++++++++++ .../src/apps/google-tasks/actions/index.js | 3 ++ .../apps/google-tasks/dynamic-data/index.js | 3 ++ .../dynamic-data/list-task-lists/index.js | 33 ++++++++++++ .../backend/src/apps/google-tasks/index.js | 4 ++ packages/docs/pages/.vitepress/config.js | 1 + .../docs/pages/apps/google-tasks/actions.md | 12 +++++ packages/docs/pages/guide/available-apps.md | 1 + 8 files changed, 107 insertions(+) create mode 100644 packages/backend/src/apps/google-tasks/actions/find-task/index.js create mode 100644 packages/backend/src/apps/google-tasks/actions/index.js create mode 100644 packages/backend/src/apps/google-tasks/dynamic-data/index.js create mode 100644 packages/backend/src/apps/google-tasks/dynamic-data/list-task-lists/index.js create mode 100644 packages/docs/pages/apps/google-tasks/actions.md diff --git a/packages/backend/src/apps/google-tasks/actions/find-task/index.js b/packages/backend/src/apps/google-tasks/actions/find-task/index.js new file mode 100644 index 00000000..d7e8e2a6 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/actions/find-task/index.js @@ -0,0 +1,50 @@ +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Find task', + key: 'findTask', + description: 'Looking for an incomplete task.', + arguments: [ + { + label: 'Task List', + key: 'taskListId', + type: 'dropdown', + required: true, + description: 'The list to be searched.', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTaskLists', + }, + ], + }, + }, + { + label: 'Title', + key: 'title', + type: 'string', + required: true, + description: '', + variables: true, + }, + ], + + async run($) { + const taskListId = $.step.parameters.taskListId; + const title = $.step.parameters.title; + + const { data } = await $.http.get(`/tasks/v1/lists/${taskListId}/tasks`); + + const filteredTask = data.items?.filter((task) => + task.title.includes(title) + ); + + $.setActionItem({ + raw: filteredTask[0], + }); + }, +}); diff --git a/packages/backend/src/apps/google-tasks/actions/index.js b/packages/backend/src/apps/google-tasks/actions/index.js new file mode 100644 index 00000000..62c5889b --- /dev/null +++ b/packages/backend/src/apps/google-tasks/actions/index.js @@ -0,0 +1,3 @@ +import findTask from './find-task/index.js'; + +export default [findTask]; diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/index.js new file mode 100644 index 00000000..4ef1c1a9 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/dynamic-data/index.js @@ -0,0 +1,3 @@ +import listTaskLists from './list-task-lists/index.js'; + +export default [listTaskLists]; diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/list-task-lists/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/list-task-lists/index.js new file mode 100644 index 00000000..a430a48e --- /dev/null +++ b/packages/backend/src/apps/google-tasks/dynamic-data/list-task-lists/index.js @@ -0,0 +1,33 @@ +export default { + name: 'List task lists', + key: 'listTaskLists', + + async run($) { + const taskLists = { + data: [], + }; + + const params = { + maxResults: 100, + pageToken: undefined, + }; + + do { + const { data } = await $.http.get('/tasks/v1/users/@me/lists', { + params, + }); + params.pageToken = data.nextPageToken; + + if (data.items) { + for (const taskList of data.items) { + taskLists.data.push({ + value: taskList.id, + name: taskList.title, + }); + } + } + } while (params.pageToken); + + return taskLists; + }, +}; diff --git a/packages/backend/src/apps/google-tasks/index.js b/packages/backend/src/apps/google-tasks/index.js index 9b23d099..6474f86e 100644 --- a/packages/backend/src/apps/google-tasks/index.js +++ b/packages/backend/src/apps/google-tasks/index.js @@ -1,6 +1,8 @@ import defineApp from '../../helpers/define-app.js'; import addAuthHeader from './common/add-auth-header.js'; import auth from './auth/index.js'; +import actions from './actions/index.js'; +import dynamicData from './dynamic-data/index.js'; export default defineApp({ name: 'Google Tasks', @@ -13,4 +15,6 @@ export default defineApp({ supportsConnections: true, beforeRequest: [addAuthHeader], auth, + actions, + dynamicData, }); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 15dfc3fd..868fa5b2 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -174,6 +174,7 @@ export default defineConfig({ collapsible: true, collapsed: true, items: [ + { text: 'Actions', link: '/apps/google-tasks/actions' }, { text: 'Connection', link: '/apps/google-tasks/connection' }, ], }, diff --git a/packages/docs/pages/apps/google-tasks/actions.md b/packages/docs/pages/apps/google-tasks/actions.md new file mode 100644 index 00000000..118f2a77 --- /dev/null +++ b/packages/docs/pages/apps/google-tasks/actions.md @@ -0,0 +1,12 @@ +--- +favicon: /favicons/google-tasks.svg +items: + - name: Find task + desc: Looking for an incomplete task. +--- + + + + diff --git a/packages/docs/pages/guide/available-apps.md b/packages/docs/pages/guide/available-apps.md index 90f8ba0a..75be1bcc 100644 --- a/packages/docs/pages/guide/available-apps.md +++ b/packages/docs/pages/guide/available-apps.md @@ -17,6 +17,7 @@ The following integrations are currently supported by Automatisch. - [Google Drive](/apps/google-drive/triggers) - [Google Forms](/apps/google-forms/triggers) - [Google Sheets](/apps/google-sheets/triggers) +- [Google Tasks](/apps/google-tasks/actions) - [HTTP Request](/apps/http-request/actions) - [HubSpot](/apps/hubspot/actions) - [Invoice Ninja](/apps/invoice-ninja/triggers) From a90b58b6db5f32d251c4b0a81dd864660dcc1e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Tue, 16 Jan 2024 16:33:41 +0300 Subject: [PATCH 03/12] feat(google-tasks): add update task action --- .../src/apps/google-tasks/actions/index.js | 3 +- .../google-tasks/actions/update-task/index.js | 108 ++++++++++++++++++ .../apps/google-tasks/dynamic-data/index.js | 3 +- .../dynamic-data/list-tasks/index.js | 40 +++++++ .../docs/pages/apps/google-tasks/actions.md | 2 + 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 packages/backend/src/apps/google-tasks/actions/update-task/index.js create mode 100644 packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js diff --git a/packages/backend/src/apps/google-tasks/actions/index.js b/packages/backend/src/apps/google-tasks/actions/index.js index 62c5889b..5a5941db 100644 --- a/packages/backend/src/apps/google-tasks/actions/index.js +++ b/packages/backend/src/apps/google-tasks/actions/index.js @@ -1,3 +1,4 @@ import findTask from './find-task/index.js'; +import updateTask from './update-task/index.js'; -export default [findTask]; +export default [findTask, updateTask]; diff --git a/packages/backend/src/apps/google-tasks/actions/update-task/index.js b/packages/backend/src/apps/google-tasks/actions/update-task/index.js new file mode 100644 index 00000000..e38aefaf --- /dev/null +++ b/packages/backend/src/apps/google-tasks/actions/update-task/index.js @@ -0,0 +1,108 @@ +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Update task', + key: 'updateTask', + description: 'Updates an existing task.', + arguments: [ + { + label: 'Task List', + key: 'taskListId', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTaskLists', + }, + ], + }, + }, + { + label: 'Task', + key: 'taskId', + type: 'dropdown', + required: true, + description: 'Ensure that you choose a list before proceeding.', + variables: true, + dependsOn: ['parameters.taskListId'], + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTasks', + }, + { + name: 'parameters.taskListId', + value: '{parameters.taskListId}', + }, + ], + }, + }, + { + label: 'Title', + key: 'title', + type: 'string', + required: false, + description: 'Provide a new title for the revised task.', + variables: true, + }, + { + label: 'Status', + key: 'status', + type: 'dropdown', + required: false, + description: + 'Specify the status of the updated task. If you opt for a custom value, enter either "needsAttention" or "completed."', + variables: true, + options: [ + { label: 'Incomplete', value: 'needsAction' }, + { label: 'Complete', value: 'completed' }, + ], + }, + { + label: 'Notes', + key: 'notes', + type: 'string', + required: false, + description: 'Provide a note for the revised task.', + variables: true, + }, + { + label: 'Due Date', + key: 'due', + type: 'string', + required: false, + description: + 'Specify the deadline for the task (as a RFC 3339 timestamp).', + variables: true, + }, + ], + + async run($) { + const { taskListId, taskId, title, status, notes, due } = $.step.parameters; + + const body = { + title, + status, + notes, + due, + }; + + const { data } = await $.http.patch( + `/tasks/v1/lists/${taskListId}/tasks/${taskId}`, + body + ); + + $.setActionItem({ + raw: data, + }); + }, +}); diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/index.js index 4ef1c1a9..71940ffd 100644 --- a/packages/backend/src/apps/google-tasks/dynamic-data/index.js +++ b/packages/backend/src/apps/google-tasks/dynamic-data/index.js @@ -1,3 +1,4 @@ import listTaskLists from './list-task-lists/index.js'; +import listTasks from './list-tasks/index.js'; -export default [listTaskLists]; +export default [listTaskLists, listTasks]; diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js new file mode 100644 index 00000000..534dbdbb --- /dev/null +++ b/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js @@ -0,0 +1,40 @@ +export default { + name: 'List tasks', + key: 'listTasks', + + async run($) { + const tasks = { + data: [], + }; + const taskListId = $.step.parameters.taskListId; + + const params = { + maxResults: 100, + pageToken: undefined, + }; + + if (!taskListId) { + return tasks; + } + + do { + const { data } = await $.http.get(`/tasks/v1/lists/${taskListId}/tasks`, { + params, + }); + params.pageToken = data.nextPageToken; + + if (data.items) { + for (const task of data.items) { + if (task.title !== '') { + tasks.data.push({ + value: task.id, + name: task.title, + }); + } + } + } + } while (params.pageToken); + + return tasks; + }, +}; diff --git a/packages/docs/pages/apps/google-tasks/actions.md b/packages/docs/pages/apps/google-tasks/actions.md index 118f2a77..f53be795 100644 --- a/packages/docs/pages/apps/google-tasks/actions.md +++ b/packages/docs/pages/apps/google-tasks/actions.md @@ -3,6 +3,8 @@ favicon: /favicons/google-tasks.svg items: - name: Find task desc: Looking for an incomplete task. + - name: Update task + desc: Updates an existing task. --- + + From cab040c74a0d7444b67432c8a5acebf27f00e4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Tue, 16 Jan 2024 17:25:25 +0300 Subject: [PATCH 07/12] feat(google-tasks): add new tasks trigger --- .../src/apps/google-tasks/triggers/index.js | 3 +- .../google-tasks/triggers/new-tasks/index.js | 53 +++++++++++++++++++ .../docs/pages/apps/google-tasks/triggers.md | 2 + 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js diff --git a/packages/backend/src/apps/google-tasks/triggers/index.js b/packages/backend/src/apps/google-tasks/triggers/index.js index 6b2b05ca..41a30e9d 100644 --- a/packages/backend/src/apps/google-tasks/triggers/index.js +++ b/packages/backend/src/apps/google-tasks/triggers/index.js @@ -1,3 +1,4 @@ import newTaskLists from './new-task-lists/index.js'; +import newTasks from './new-tasks/index.js'; -export default [newTaskLists]; +export default [newTaskLists, newTasks]; diff --git a/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js b/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js new file mode 100644 index 00000000..0b88b330 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js @@ -0,0 +1,53 @@ +import defineTrigger from '../../../../helpers/define-trigger.js'; + +export default defineTrigger({ + name: 'New tasks', + key: 'newTasks', + pollInterval: 15, + description: 'Triggers when a new task is created.', + arguments: [ + { + label: 'Task List', + key: 'taskListId', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTaskLists', + }, + ], + }, + }, + ], + + async run($) { + const taskListId = $.step.parameters.taskListId; + + const params = { + maxResults: 100, + pageToken: undefined, + }; + + do { + const { data } = await $.http.get(`/tasks/v1/lists/${taskListId}/tasks`); + params.pageToken = data.nextPageToken; + + if (data.items?.length) { + for (const task of data.items) { + $.pushTriggerItem({ + raw: task, + meta: { + internalId: task.etag, + }, + }); + } + } + } while (params.pageToken); + }, +}); diff --git a/packages/docs/pages/apps/google-tasks/triggers.md b/packages/docs/pages/apps/google-tasks/triggers.md index b92a3bd8..ad8ed507 100644 --- a/packages/docs/pages/apps/google-tasks/triggers.md +++ b/packages/docs/pages/apps/google-tasks/triggers.md @@ -3,6 +3,8 @@ favicon: /favicons/google-tasks.svg items: - name: New task lists desc: Triggers when a new task list is created. + - name: New tasks + desc: Triggers when a new task is created. ---