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.8 KB
Raw Blame
import { AppConnectionValueForAuthProperty, TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
import {
  DedupeStrategy,
  Polling,
  pollingHelper,
} from '@activepieces/pieces-common';
import { currentYear } from '../common';
import { ClockodoClient } from '../common/client';
import { clockodoAuth } from '../auth';

const polling: Polling<AppConnectionValueForAuthProperty<typeof clockodoAuth>, unknown> = {
  strategy: DedupeStrategy.LAST_ITEM,
  items: async ({ auth }) => {

    const client = new ClockodoClient(
      auth.props.email,
      auth.props.token,
      auth.props.company_name,
      auth.props.company_email
    );
    const res = await client.listAbsences({ year: currentYear() });
    return res.absences
      .sort((a, b) => b.id - a.id)
      .map((a) => ({
        id: a.id,
        data: a,
      }));
  },
};

export default createTrigger({
  auth: clockodoAuth,
  name: 'new_absence_enquiry',
  classification: 'READ',
  displayName: 'New Absence Enquiry',
  description: 'Triggers when a new absence enquiry is created',
  aiMetadata: {
    description: 'Fires when a new absence enquiry (such as a vacation, sick leave, or other time-off request) is created in Clockodo for the current year. Emits the newly created absence record, including its details such as the absence type, date range, and requesting employee.',
  },
  type: TriggerStrategy.POLLING,
  props: {},
  sampleData: {},
  onEnable: async (context) => {
    await pollingHelper.onEnable(polling, context);
  },
  onDisable: async (context) => {
    await pollingHelper.onDisable(polling, context);
  },
  run: async (context) => {
    return await pollingHelper.poll(polling, context);
  },
  test: async (context) => {
    return await pollingHelper.test(polling, context);
  },
});