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 { ActionContext, Property, createAction } from '@activepieces/pieces-framework';
import { calendar as googleCalendar } from '@googleapis/calendar';
import { googleCalendarCommon, googleCalendarAuth, createGoogleClient } from '../common';

export const deleteEventProps = {
  calendar_id: googleCalendarCommon.calendarDropdown('writer'),
  eventId: Property.ShortText({
    displayName: 'Event ID',
    description: 'Paste the ID from the event URL or a previous step.',
    required: true,
  }),
};

export async function runDeleteEvent(
  context: ActionContext<typeof googleCalendarAuth, typeof deleteEventProps>
) {
  const authClient = await createGoogleClient(context.auth);

  const calendarId = context.propsValue.calendar_id;
  const eventId = context.propsValue.eventId;

  const calendar = googleCalendar({ version: 'v3', auth: authClient });

  const response = await calendar.events.delete({
    calendarId,
    eventId,
  });

  return response.data;
}

export const deleteEventAction = createAction({
  displayName: 'Delete Event',
  auth: googleCalendarAuth,
  name: 'delete_event',
  classification: 'DESTRUCTIVE',
  description: 'Deletes an event from Google Calendar.',
  audience: 'human',
  aiMetadata: { description: 'Permanently removes an event from a Google Calendar, identified by calendar and event ID. Use to cancel or delete an existing event. Requires the event ID and cannot be undone. Idempotent: once the event is deleted, repeating the call leaves it absent (a second call may report it as already gone).', idempotent: true },
  propertyGroups: [
    {
      key: 'event',
      display: 'section',
      label: 'Event',
      icon: 'calendar',
      props: ['calendar_id', 'eventId'],
    },
  ],
  props: deleteEventProps,
  run: runDeleteEvent,
});