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 { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { attioAuth } from '../auth';
import { attioApiCall } from '../common/client';
import { linkedRecordDropdown, objectTypeIdDropdown } from '../common/props';
import { listTasksOutputSchema } from '../output-schemas';

export const listTasksAction = createAction({
	auth: attioAuth,
	name: 'list_tasks',
	outputSchema: listTasksOutputSchema,
	classification: 'SEARCH',
	displayName: 'List Tasks',
	description: 'List tasks with optional filters by linked record, assignee, or completion status.',
	audience: 'human',
	aiMetadata: { description: 'Lists tasks in Attio, optionally narrowed by linked object type, linked record, assignee (member email/ID, or "null" for unassigned), and completion status. With no filters it returns all tasks. Use this to find tasks before getting or updating one. Read-only and idempotent.', idempotent: true },
	props: {
		linked_object: objectTypeIdDropdown({
			displayName: 'Linked Object',
			description: 'Filter tasks linked to records of this object type.',
			required: false,
		}),
		linked_record_id: linkedRecordDropdown({
			displayName: 'Linked Record',
			description: 'Filter tasks linked to this specific record.',
			required: false,
		}),
		assignee: Property.ShortText({
			displayName: 'Assignee',
			description:
				'Filter by workspace member email or ID. Enter "null" to find unassigned tasks.',
			required: false,
		}),
		is_completed: Property.StaticDropdown({
			displayName: 'Completion Status',
			required: false,
			options: {
				disabled: false,
				options: [
					{ label: 'All', value: 'all' },
					{ label: 'Completed', value: 'true' },
					{ label: 'Incomplete', value: 'false' },
				],
			},
		}),
	},
	async run(context) {
		const { linked_object, linked_record_id, assignee, is_completed } = context.propsValue;

		const query: Record<string, string | number | undefined> = {
			limit: 500,
			offset: 0,
		};

		if (linked_object) query['linked_object'] = linked_object;
		if (linked_record_id) query['linked_record_id'] = linked_record_id;
		if (assignee) query['assignee'] = assignee;
		if (is_completed && is_completed !== 'all') query['is_completed'] = is_completed;

		const response = await attioApiCall<{ data: Array<Record<string, unknown>> }>({
			accessToken: context.auth.secret_text,
			method: HttpMethod.GET,
			resourceUri: '/tasks',
			query,
		});

		return {
			found: response.data.length > 0,
			result: response.data,
		};
	},
});