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

2.8 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 } from '../common/props';
import { createTaskOutputSchema } from '../output-schemas';

export const createTaskAction = createAction({
	auth: ticktickAuth,
	name: 'create_task',
	outputSchema: createTaskOutputSchema,
	classification: 'WRITE',
	displayName: 'Create Task',
	description: 'Creates a new in a specific list.',
	audience: 'human',
	aiMetadata: {
		description:
			'Creates a new task in a TickTick list, with optional content, checklist description, start/due dates, and priority. Use to add a to-do item. Requires the target list (project) ID and a task title. Not idempotent: each call creates a separate task even with identical input.',
		idempotent: false,
	},
	props: {
		projectId: projectId({
			displayName: 'List',
			description: 'The list to create the task in.',
			required: true,
		}),
		title: Property.ShortText({
			displayName: 'Task Title',
			required: true,
		}),
		content: Property.LongText({
			displayName: 'Task Content',
			required: false,
		}),
		desc: Property.LongText({
			displayName: 'Description (Checklist)',
			description: 'Description of the checklist, often used with subtasks (items).',
			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 { projectId, title, content, desc, startDate, dueDate, priority } = context.propsValue;

		const createTaskParams: Record<string, any> = {
			title,
			projectId: projectId as string,
		};

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

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

		return response;
	},
});