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.9 KB
Raw Blame
import {
    DedupeStrategy,
    Polling,
    pollingHelper,
} from '@activepieces/pieces-common';
import {
    AppConnectionValueForAuthProperty,
    createTrigger,
    StaticPropsValue,
    TriggerStrategy,
} from '@activepieces/pieces-framework';
import dayjs from 'dayjs';
import { microsoft365PlannerAuth } from '../auth';
import { microsoft365PlannerApi } from '../common/api';
import { microsoft365PlannerProps } from '../common/props';
import { microsoft365PlannerTaskOutputSchema } from '../output-schemas';

const props = {
  planId: microsoft365PlannerProps.planId({ required: true }),
};

const polling: Polling<
  AppConnectionValueForAuthProperty<typeof microsoft365PlannerAuth>,
  StaticPropsValue<typeof props>
> = {
  strategy: DedupeStrategy.TIMEBASED,
  items: async ({ auth, propsValue: { planId } }) => {
    if (!planId) {
      return [];
    }
    const items = await microsoft365PlannerApi.listTasks({
      auth,
      planId,
    });
    return items.map((item) => ({
      epochMilliSeconds: dayjs(item.createdDateTime).valueOf(),
      data: item,
    }));
  },
};

export const newTaskCreatedTrigger = createTrigger({
  auth: microsoft365PlannerAuth,
  name: 'newTaskCreated',
  outputSchema: microsoft365PlannerTaskOutputSchema,
  classification: 'READ',
  displayName: 'New Task Created',
  description: 'Triggers when a new Task is created in Microsoft 365 Planner.',
  aiMetadata: {
    description: 'Fires when a new task is created within a specified Planner plan. Polls periodically and emits each newly created task for the configured plan.',
  },
  props,
  sampleData: {
    '@odata.etag': 'W/"JzEtVGFzayAgQEBAffEBAQEBAQEBARCc="',
    planId: 's58lztas2UyCXSffEjnlVRgWUAFMLw',
    bucketId: 'xZ2RCz88uE6BffffftN-0TKffPGUAB-pQ',
    title: 'test task 123',
    orderHint: '8584411578775238762',
    assigneePriority: '',
    percentComplete: 0,
    startDateTime: null,
    createdDateTime: '2025-10-14T13:36:47.953708Z',
    dueDateTime: null,
    hasDescription: false,
    previewType: 'automatic',
    completedDateTime: null,
    referenceCount: 0,
    checklistItemCount: 0,
    activeChecklistItemCount: 0,
    conversationThreadId: null,
    priority: 5,
    id: 'wvG9lNxhuUO2JuedF9-rimUAFsBA',
    completedBy: null,
    createdBy: {
      user: {
        displayName: null,
        id: '90b3720d-f459-42c1-a02e-6471a1ecb068',
      },
      application: {
        displayName: null,
        id: '5ea0744c-62fa-4a19-99be-99f0869d3182',
      },
    },
    appliedCategories: {},
    assignments: {},
  },
  type: TriggerStrategy.POLLING,
  async test(context) {
    return await pollingHelper.test(polling, context);
  },
  async onEnable(context) {
    await pollingHelper.onEnable(polling, context);
  },

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

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