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.4 KB
Raw Blame
import { meistertaskAuth } from '../auth';
import { makeRequest, meisterTaskCommon } from '../common/common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';

export const findTask = createAction({
  auth: meistertaskAuth,
  name: 'find_task',
  classification: 'SEARCH',
  displayName: 'Find Task',
  description: 'Finds a task by searching',
  audience: 'both',
  aiMetadata: { description: 'Look up tasks in a specific MeisterTask section and return the first match. With a name supplied it returns the first task whose name contains that text (case-insensitive); leaving the name empty returns the first task in the section. Read-only and idempotent. Requires the project and section; returns null if no task matches.', idempotent: true },
  props: {
    project: meisterTaskCommon.project,
    section: meisterTaskCommon.section,
    name: Property.ShortText({
      displayName: 'Task Name',
      required: false,
    }),
  },
  async run(context) {
    const token = context.auth.access_token;
    const { section, name } = context.propsValue;

    const response = await makeRequest(
      HttpMethod.GET,
      `/sections/${section}/tasks`,
      token
    );

    let tasks = response.body;

    if (name) {
      tasks = tasks.filter((task: any) =>
        task.name.toLowerCase().includes(name.toLowerCase())
      );
    }

    return tasks.length > 0 ? tasks[0] : null;
  },
});