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

1.9 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { createTask, googleTasksCommon, Task, TaskStatus } from '../common';
import { googleTasksAuth } from '../auth';
import { googleTasksAddTaskOutputSchema } from '../output-schemas';

export const googleTasksAddNewTaskAction = createAction({
  auth: googleTasksAuth,
  name: 'add_task',
  classification: 'WRITE',
  description: 'Add a new task to a specified task list',
  audience: 'human',
  aiMetadata: {
    description: 'Creates a new task in a specific Google Tasks list, with optional notes, due date, and a completed flag. Use to add a to-do item for the authenticated user; requires a valid task-list ID (resolve it first if you only have a list name). Not idempotent: each call appends a separate task even with identical input.',
    idempotent: false,
  },
  displayName: 'Add Task',
  outputSchema: googleTasksAddTaskOutputSchema,
  props: {
    tasks_list: googleTasksCommon.tasksList,
    title: googleTasksCommon.title,
    notes: googleTasksCommon.notes,
    due: googleTasksCommon.due,
    completed: googleTasksCommon.completed,
  },
  propertyGroups: [
    { key: 'destination', display: 'section', label: 'Add to', icon: 'inbox', props: ['tasks_list'] },
    { key: 'task', display: 'section', label: 'Task', icon: 'text', props: ['title', 'notes', 'due', 'completed'] },
  ],
  async run({ auth, propsValue }) {
    const task: Task = {
      kind: 'tasks#task',
      status: propsValue.completed
        ? TaskStatus.COMPLETED
        : TaskStatus.NEEDS_ACTION,
      title: propsValue.title,
      completed: propsValue.completed ? new Date().toISOString() : undefined,
      notes: propsValue.notes,
      due: propsValue.due
        ? `${new Date(propsValue.due).toISOString().split('T')[0]}T00:00:00Z`
        : undefined,
    };

    return createTask(auth, propsValue.tasks_list!, task);
  },
});