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.5 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { HttpMethod, getAccessTokenOrThrow } from '@activepieces/pieces-common';
import { clickupCommon, callClickUpApi } from '../../common';
import { clickupAuth } from '../../auth';
import { createTaskCommentOutputSchema } from '../../output-schemas';

export const createClickupTaskComment = createAction({
  auth: clickupAuth,
  name: 'create_task_comments',
  classification: 'WRITE',
  description: 'Add a comment to a ClickUp task.',
  audience: 'human',
  aiMetadata: { description: 'Post a new comment on a ClickUp task and notify the workspace. Each call adds a distinct comment, so repeated calls create duplicates (not idempotent). If no assignee is given, the comment is attributed to the authenticated user.', idempotent: false },
  displayName: 'Create Task Comment',
  propertyGroups: [
    {
      key: 'target',
      display: 'section',
      label: 'Task',
      icon: 'inbox',
      props: ['workspace_id', 'space_id', 'list_id', 'task_id'],
    },
    {
      key: 'comment',
      display: 'section',
      label: 'Comment',
      icon: 'text',
      props: ['comment', 'assignee_id'],
    },
  ],
  props: {
    workspace_id: clickupCommon.workspace_id(),
    space_id: clickupCommon.space_id(),
    list_id: clickupCommon.list_id(),
    task_id: clickupCommon.task_id(),
    comment: Property.LongText({
      displayName: 'Text',
      description: 'What the comment says.',
      placeholder: 'e.g. Ready for review',
      required: true,
    }),
    assignee_id: clickupCommon.single_assignee_id(
      false,
      'Assignee',
      'Who should act on the comment. Empty: you.'
    ),
  },
  outputSchema: createTaskCommentOutputSchema,
  async run(configValue) {
    const { task_id, comment } = configValue.propsValue;

    let assignee_id = configValue.propsValue.assignee_id;

    if (!assignee_id) {
      const user_request = await callClickUpApi(
        HttpMethod.GET,
        `user`,
        getAccessTokenOrThrow(configValue.auth),
        {}
      );

      if (user_request.body['user'] === undefined) {
        throw new Error('Please connect to your ClickUp account');
      }

      assignee_id = user_request.body['user']['id'];
    }

    const response = await callClickUpApi(
      HttpMethod.POST,
      `task/${task_id}/comment`,
      getAccessTokenOrThrow(configValue.auth),
      {
        comment_text: comment,
        assignee: assignee_id,
        notify_all: true,
      }
    );

    return response.body;
  },
});