Skip to content

Commit

Permalink
Merge pull request #4641 from kishanprmr/todoist
Browse files Browse the repository at this point in the history
feat(todoist): update task, find task and mark task completed action
  • Loading branch information
abuaboud committed May 8, 2024
2 parents 0f8e263 + d766004 commit f1421f5
Show file tree
Hide file tree
Showing 10 changed files with 528 additions and 291 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/todoist/package.json
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-todoist",
"version": "0.3.7"
"version": "0.3.8"
}
50 changes: 28 additions & 22 deletions packages/pieces/community/todoist/src/index.ts
Expand Up @@ -3,31 +3,37 @@ import { OAuth2PropertyValue, PieceAuth, createPiece } from '@activepieces/piece
import { PieceCategory } from '@activepieces/shared';
import { todoistCreateTaskAction } from './lib/actions/create-task-action';
import { todoistTaskCompletedTrigger } from './lib/triggers/task-completed-trigger';
import { todoistUpdateTaskAction } from './lib/actions/update-task.action';
import { todoistFindTaskAction } from './lib/actions/find-task.action';
import { todoistMarkTaskCompletedAction } from './lib/actions/mark-task-completed.action';

export const todoistAuth = PieceAuth.OAuth2({
required: true,
authUrl: 'https://todoist.com/oauth/authorize',
tokenUrl: 'https://todoist.com/oauth/access_token',
scope: ['data:read_write'],
required: true,
authUrl: 'https://todoist.com/oauth/authorize',
tokenUrl: 'https://todoist.com/oauth/access_token',
scope: ['data:read_write'],
});

export const todoist = createPiece({
displayName: 'Todoist',
description: 'To-do list and task manager',
minimumSupportedRelease: '0.5.0',
logoUrl: 'https://cdn.activepieces.com/pieces/todoist.png',
authors: ["MyWay","kishanprmr","MoShizzle","khaledmashaly","abuaboud"],
categories: [PieceCategory.PRODUCTIVITY],
auth: todoistAuth,
actions: [
todoistCreateTaskAction,
createCustomApiCallAction({
baseUrl: () => 'https://api.todoist.com/rest/v2',
auth: todoistAuth,
authMapping: (auth) => ({
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`,
}),
}),
],
triggers: [todoistTaskCompletedTrigger],
displayName: 'Todoist',
description: 'To-do list and task manager',
minimumSupportedRelease: '0.5.0',
logoUrl: 'https://cdn.activepieces.com/pieces/todoist.png',
authors: ['MyWay', 'kishanprmr', 'MoShizzle', 'khaledmashaly', 'abuaboud'],
categories: [PieceCategory.PRODUCTIVITY],
auth: todoistAuth,
actions: [
todoistCreateTaskAction,
todoistUpdateTaskAction,
todoistFindTaskAction,
todoistMarkTaskCompletedAction,
createCustomApiCallAction({
baseUrl: () => 'https://api.todoist.com/rest/v2',
auth: todoistAuth,
authMapping: (auth) => ({
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`,
}),
}),
],
triggers: [todoistTaskCompletedTrigger],
});
@@ -1,70 +1,65 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import { assertNotNullOrUndefined } from '@activepieces/shared';
import { todoistRestClient } from '../common/client/rest-client';
import { todoistProjectIdDropdown } from '../common/props';
import { todoistProjectIdDropdown, todoistSectionIdDropdown } from '../common/props';
import { TodoistCreateTaskRequest } from '../common/models';
import { todoistAuth } from '../..';

export const todoistCreateTaskAction = createAction({
auth: todoistAuth,
name: 'create_task',
displayName: 'Create Task',
description: 'Create task',
props: {
project_id: todoistProjectIdDropdown,
content: Property.LongText({
displayName: 'content',
description:
"The task's content. It may contain some markdown-formatted text and hyperlinks",
required: true,
}),
description: Property.LongText({
displayName: 'Description',
description:
'A description for the task. This value may contain some markdown-formatted text and hyperlinks.',
required: false,
}),
labels: Property.Array({
displayName: 'Labels',
required: false,
description:
"The task's labels (a list of names that may represent either personal or shared labels)",
}),
priority: Property.Number({
displayName: 'Priority',
description: 'Task priority from 1 (normal) to 4 (urgent)',
required: false,
}),
due_date: Property.ShortText({
displayName: 'Due date',
description:
"Specific date in YYYY-MM-DD format relative to user's timezone",
required: false,
}),
section_id: Property.ShortText({
displayName: 'Section',
description:
"A section for the task. It should be a Section ID under the same project",
required: false,
}),
},
auth: todoistAuth,
name: 'create_task',
displayName: 'Create Task',
description: 'Create task',
props: {
project_id: todoistProjectIdDropdown(
"Task project ID. If not set, task is put to user's Inbox.",
),
content: Property.LongText({
displayName: 'content',
description: "The task's content. It may contain some markdown-formatted text and hyperlinks",
required: true,
}),
description: Property.LongText({
displayName: 'Description',
description:
'A description for the task. This value may contain some markdown-formatted text and hyperlinks.',
required: false,
}),
labels: Property.Array({
displayName: 'Labels',
required: false,
description:
"The task's labels (a list of names that may represent either personal or shared labels)",
}),
priority: Property.Number({
displayName: 'Priority',
description: 'Task priority from 1 (normal) to 4 (urgent)',
required: false,
}),
due_date: Property.ShortText({
displayName: 'Due date',
description: "Specific date in YYYY-MM-DD format relative to user's timezone",
required: false,
}),
section_id: todoistSectionIdDropdown,
},

async run({ auth, propsValue }) {
const token = auth.access_token;
const { project_id, content, description, labels, priority, due_date, section_id} =
propsValue as TodoistCreateTaskRequest;
async run({ auth, propsValue }) {
const token = auth.access_token;
const { project_id, content, description, labels, priority, due_date, section_id } =
propsValue as TodoistCreateTaskRequest;

assertNotNullOrUndefined(token, 'token');
assertNotNullOrUndefined(content, 'content');
return await todoistRestClient.tasks.create({
token,
project_id,
content,
description,
labels,
priority,
due_date,
section_id
});
},
assertNotNullOrUndefined(token, 'token');
assertNotNullOrUndefined(content, 'content');
return await todoistRestClient.tasks.create({
token,
project_id,
content,
description,
labels,
priority,
due_date,
section_id,
});
},
});
@@ -0,0 +1,36 @@
import { todoistAuth } from '../..';
import { createAction, Property } from '@activepieces/pieces-framework';
import { todoistProjectIdDropdown } from '../common/props';
import { todoistRestClient } from '../common/client/rest-client';
import { assertNotNullOrUndefined } from '@activepieces/shared';

export const todoistFindTaskAction = createAction({
auth: todoistAuth,
name: 'find_task',
displayName: 'Find Task',
description: 'Finds a task by name.',
props: {
name: Property.ShortText({
displayName: 'Name',
description: 'The name of the task to search for.',
required: true,
}),
project_id: todoistProjectIdDropdown(
'Search for tasks within the selected project. If left blank, then all projects are searched.',
),
},
async run(context) {
const token = context.auth.access_token;
const { name, project_id } = context.propsValue;

assertNotNullOrUndefined(token, 'token');
const tasks = await todoistRestClient.tasks.list({ token, project_id });

const matchedTask = tasks.find((task) => task.content == name);
if (!matchedTask) {
throw new Error('Task not found');
} else {
return matchedTask;
}
},
});
@@ -0,0 +1,25 @@
import { assertNotNullOrUndefined } from '@activepieces/shared';
import { todoistAuth } from '../..';
import { createAction, Property } from '@activepieces/pieces-framework';
import { todoistRestClient } from '../common/client/rest-client';

export const todoistMarkTaskCompletedAction = createAction({
auth: todoistAuth,
name: 'mark_task_completed',
displayName: 'Mark Task as Completed',
description: 'Marks a task as being completed.',
props: {
task_id: Property.ShortText({
displayName: 'Task ID',
required: true,
}),
},
async run(context) {
const token = context.auth.access_token;
const { task_id } = context.propsValue;

assertNotNullOrUndefined(token, 'token');

return await todoistRestClient.tasks.close({ token, task_id });
},
});
@@ -0,0 +1,61 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import { assertNotNullOrUndefined } from '@activepieces/shared';
import { todoistRestClient } from '../common/client/rest-client';
import { todoistAuth } from '../..';

export const todoistUpdateTaskAction = createAction({
auth: todoistAuth,
name: 'update_task',
displayName: 'Update Task',
description: 'Updates an existing task.',
props: {
task_id: Property.ShortText({
displayName: 'Task ID',
required: true,
}),
content: Property.LongText({
displayName: 'content',
description: "The task's content. It may contain some markdown-formatted text and hyperlinks",
required: false,
}),
description: Property.LongText({
displayName: 'Description',
description:
'A description for the task. This value may contain some markdown-formatted text and hyperlinks.',
required: false,
}),
labels: Property.Array({
displayName: 'Labels',
required: false,
description:
"The task's labels (a list of names that may represent either personal or shared labels)",
}),
priority: Property.Number({
displayName: 'Priority',
description: 'Task priority from 1 (normal) to 4 (urgent)',
required: false,
}),
due_date: Property.ShortText({
displayName: 'Due date',
description: "Specific date in YYYY-MM-DD format relative to user's timezone",
required: false,
}),
},

async run({ auth, propsValue }) {
const token = auth.access_token;
const { task_id, content, description, priority, due_date } = propsValue;
const labels = propsValue.labels as string[];

assertNotNullOrUndefined(token, 'token');
return await todoistRestClient.tasks.update({
token,
task_id,
content,
description,
labels,
priority,
due_date,
});
},
});

0 comments on commit f1421f5

Please sign in to comment.