Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.0 KB
Raw Blame
import { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import dayjs from 'dayjs';
import { ticktickAuth } from '../auth';
import { tickTickApiCall } from '../common/client';
import {
	TICKTICK_PRIORITY_HIGH,
	TICKTICK_PRIORITY_LOW,
	TICKTICK_PRIORITY_MEDIUM,
	TICKTICK_PRIORITY_NONE,
} from '../common/constants';
import { projectId, taskId } from '../common/props';
import { updateTaskOutputSchema } from '../output-schemas';


export const updateTaskAction = createAction({
	auth: ticktickAuth,
	name: 'update_task',
	outputSchema: updateTaskOutputSchema,
	classification: 'WRITE',
	displayName: 'Update Task',
	description: 'Update an existing task.',
	audience: 'human',
	aiMetadata: {
		description:
			'Updates fields (title, content, checklist description, start/due dates, priority) on an existing TickTick task identified by its list and task ID. Only the fields you supply are changed. Use to edit a known task. Idempotent: repeating with the same values leaves the task in the same state.',
		idempotent: true,
	},
	props: {
		projectId: projectId({
			displayName: 'List',
			description: 'The list to update the task in.',
			required: true,
		}),
		taskId: taskId({
			displayName: 'Task ID',
			description: 'The ID of the task to update.',
			required: true,
		}),
		title: Property.ShortText({
			displayName: 'Title',
			required: false,
		}),
		content: Property.LongText({
			displayName: 'Content',
			required: false,
		}),
		desc: Property.LongText({
			displayName: 'Description (Checklist)',
			description: 'New description of the checklist items. Replaces existing.',
			required: false,
		}),
		startDate: Property.DateTime({
			displayName: 'Start Date',
			required: false,
		}),
		dueDate: Property.DateTime({
			displayName: 'Due Date',
			required: false,
		}),
		priority: Property.StaticDropdown({
			displayName: 'Priority',
			required: false,
			options: {
				options: [
					{ label: 'None', value: TICKTICK_PRIORITY_NONE },
					{ label: 'Low', value: TICKTICK_PRIORITY_LOW },
					{ label: 'Medium', value: TICKTICK_PRIORITY_MEDIUM },
					{ label: 'High', value: TICKTICK_PRIORITY_HIGH },
				],
			},
		}),
	},
	async run(context) {
		const { taskId, projectId, title, content, desc, startDate, dueDate, priority } =
			context.propsValue;

		const updateTaskParams: Record<string, any> = {
			id: taskId,
			projectId: projectId as string,
		};

		if (title) updateTaskParams['title'] = title;
		if (content) updateTaskParams['content'] = content;
		if (desc) updateTaskParams['desc'] = desc;
		if (startDate)
			updateTaskParams['startDate'] = dayjs(startDate).format('YYYY-MM-DDTHH:mm:ssZZ');
		if (dueDate) updateTaskParams['dueDate'] = dayjs(dueDate).format('YYYY-MM-DDTHH:mm:ssZZ');
		if (priority) updateTaskParams['priority'] = priority;

		const response = await tickTickApiCall({
			accessToken: context.auth.access_token,
			method: HttpMethod.POST,
			resourceUri: `/task/${taskId}`,
			body: updateTaskParams,
		});

		return response;
	},
});