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 { TriggerStrategy, createTrigger, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common';
import { microsoftToDoAuth } from '../auth';
import { TodoTaskList } from '@microsoft/microsoft-graph-types';
import { createTodoClient } from '../common';
import { taskListOutputSchema } from '../output-schemas';

const polling: Polling<AppConnectionValueForAuthProperty<typeof microsoftToDoAuth>, Record<string, never>> = {
    strategy: DedupeStrategy.LAST_ITEM,
    items: async ({ auth }) => {
        const client = createTodoClient(auth);

        const response = await client.api('/me/todo/lists').get();
        const lists = response.value as TodoTaskList[];

        return lists.map((list) => ({
            id: list.id!,
            data: list,
        }));
    },
};

export const newListCreatedTrigger = createTrigger({
    auth: microsoftToDoAuth,
    name: 'new_list_created',
    outputSchema: taskListOutputSchema,
    classification: 'READ',
    displayName: 'New List',
    description: 'Triggers when a new task list is created.',
    aiMetadata: {
        description: 'Fires when a new task list is created in the authenticated user\'s Microsoft To Do account. Each event represents one newly added task list; watches all of the user\'s lists rather than a single one.',
    },
    props: {},
    type: TriggerStrategy.POLLING,
    sampleData: {
        '@odata.etag': 'W/"m19slk90924jJPD1941jla="',
        'displayName': 'Vacation Plans',
        'isOwner': true,
        'isShared': false,
        'wellknownListName': 'none',
        'id': 'AAMkAGI2NGY3NTY0LTZmYjEtNDk0MS04YjQ5LTFlNmQ5NjI1MWI5ZgAuAAAAAAC50Fk_sKMfS5_62i1Isws2AQD3xL9-24sxT5RO4265g_AEAAB3x24kAAA=',
    },

    async onEnable(context) {
        await pollingHelper.onEnable(polling, context as any);
    },

    async onDisable(context) {
        await pollingHelper.onDisable(polling, context as any);
        },

    async run(context) {
        return await pollingHelper.poll(polling, context as any);
    },

    async test(context) {
        try {
            const client = createTodoClient(context.auth);

            const response = await client.api('/me/todo/lists').get();
            const lists = (response.value as TodoTaskList[]).slice(0, 5);
            return lists;
        } catch (error: any) {
            throw new Error(`Failed to fetch task lists: ${error?.message || error}`);
        }
    },
});