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.5 KB
Raw Blame
import {
    DedupeStrategy,
    Polling,
    pollingHelper,
} from '@activepieces/pieces-common';
import {
  AppConnectionValueForAuthProperty,
    createTrigger,
    PiecePropValueSchema,
    TriggerStrategy,
} from '@activepieces/pieces-framework';
import { parseurAuth, parseurCommon } from '../common';

const polling: Polling<
  AppConnectionValueForAuthProperty<typeof parseurAuth>,
  Record<string, never>
> = {
  strategy: DedupeStrategy.LAST_ITEM,
  items: async ({ auth: apiKey }) => {
    const response = await parseurCommon.listMailboxes({
      apiKey: apiKey.secret_text,
    });
    const items = response.results;
    return items.map((item) => ({
      id: item.id,
      data: item,
    }));
  },
};

export const newMailbox = createTrigger({
  auth: parseurAuth,
  name: 'newMailbox',
  classification: 'READ',
  displayName: 'New Mailbox',
  description: 'Fires when a new mailbox is created in the Parseur account.',
  aiMetadata: {
    description:
      'Fires when a new mailbox (parser) is created in the Parseur account, discovered by polling the list of mailboxes. Use to react to newly provisioned parsers/mailboxes.',
  },
  props: {},
  sampleData: {},
  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);
  },
});