// Generated by scripts/generate-events.ts — do not edit by hand. // Regenerate with: pnpm run generate import type { CalendarTriggerTarget, WorkflowConnectionDeclarations, WorkflowConnectionKeys, WorkflowTriggerConnections } from "./connections.js"; import { compileWorkflowInputSchema } from "./workflow-schema.js"; import { j, type SchemaBuilder } from "./schema-builder.js"; import { scheduled, notionPageCreated, notionPageUpdated } from "./configured-events.js"; import type { NotionPageCreatedTrigger, NotionPageUpdatedTrigger, PageUpdatedOptions, RecurrenceTrigger } from "./configured-events.js"; import type { DataSourceHandle } from "./notion-as-code/database.js"; import type { NotionAsCodeSchema } from "./notion-as-code/intents.js"; import type { RecurrenceSchedule } from "./notion-as-code/recurrence.js"; import type { CalendarEventCanceledEvent, CalendarEventCreatedEvent, CalendarEventUpdatedEvent, DiscordInteractionEvent, GoogleDriveOauthFilesChangedEvent, MailEmailReceivedEvent, MailEmailSentEvent, MailLabelAppliedEvent, NotionAgentMentionedEvent, NotionButtonPressedEvent, NotionCommentAddedEvent, NotionDatabaseAgentUpdatedEvent, NotionMeetingNoteSummaryCompletedEvent, NotionPageCreatedEvent, NotionPageDeletedEvent, NotionPageUpdatedEvent, RecurrenceEvent, SlackAppMentionEvent, SlackMessageEvent, SlackReactionAddedEvent, WebhookEvent, } from "./events.js"; export type { Actor, ActorLike, CalendarEventCanceledEvent, CalendarEventCreatedEvent, CalendarEventLike, CalendarEventUpdatedEvent, ChatMessageLike, ChatThreadMessage, DiscordChatThreadMessage, DiscordInteractionEvent, EmailMessageLike, EmailThreadLike, EmailTriggerMessage, GoogleDriveOauthFilesChangedEvent, LinkLike, MailEmailReceivedEvent, MailEmailSentEvent, MailLabelAppliedEvent, MessageLike, NotionAgentMentionedEvent, NotionButtonPressedEvent, NotionCommentAddedEvent, NotionDatabaseAgentUpdatedEvent, NotionMeetingNoteSummaryCompletedEvent, NotionPageCreatedEvent, NotionPageDeletedEvent, NotionPageEdit, NotionPageUpdatedEvent, RecurrenceEvent, RecurrenceFrequency, SlackAppMentionEvent, SlackChatThreadMessage, SlackMessageEvent, SlackReactionAddedEvent, ThreadLike, ThreadMessage, TimestampLike, TriggerEvent, TriggerEventBase, TriggerEventMap, TriggerType, VendorActor, VendorExtensions, WebhookEvent, } from "./events.js"; export type { NotionPageCreatedTrigger, NotionPageUpdatedTrigger, PageUpdatedOptions, RecurrenceTrigger } from "./configured-events.js"; export type { RecurrenceSchedule } from "./notion-as-code/recurrence.js"; declare const manualWorkflowInputSchema: unique symbol; const manualInputValidators = new WeakMap void>(); export type ManualWorkflowTrigger = Record> = { type: "workflow.manual"; inputJsonSchema: Record; readonly [manualWorkflowInputSchema]?: TInput; }; /** Triggers immediately after a new message is posted in Slack (includes new threads and replies) */ export type SlackMessageTrigger = { type: "slack.message"; /** Key of the declared slack connection. */ connectionKey?: TKey; }; /** Triggers immediately after a reaction is added to a message in Slack */ export type SlackReactionAddedTrigger = { type: "slack.reaction.added"; /** Key of the declared slack connection. */ connectionKey?: TKey; }; /** Triggers when the agent is mentioned in a Slack channel or direct message */ export type SlackAppMentionTrigger = { type: "slack.app.mention"; /** Key of the declared slack connection. */ connectionKey?: TKey; }; /** Triggers when a user invokes the /ai slash command in a configured Discord channel */ export type DiscordInteractionTrigger = { type: "discord.interaction"; /** Key of the declared discord connection. */ connectionKey?: TKey; }; /** Triggers immediately when a new email is received in Notion Mail */ export type MailEmailReceivedTrigger = { type: "mail.email.received"; /** Key of the declared mail connection. */ connectionKey?: TKey; }; /** Triggers immediately when a new email is sent from Notion Mail */ export type MailEmailSentTrigger = { type: "mail.email.sent"; /** Key of the declared mail connection. */ connectionKey?: TKey; }; /** Triggers immediately when a label is applied to an email in Notion Mail */ export type MailLabelAppliedTrigger = { type: "mail.label.applied"; /** Key of the declared mail connection. */ connectionKey?: TKey; }; /** Triggers immediately when a calendar event is created */ export type CalendarEventCreatedTrigger = { type: "calendar.event.created"; /** Key of the declared calendar connection. */ connectionKey: TKey; /** Named target from this Calendar connection; resolved from saved setup. */ calendarTarget: string; }; /** Triggers immediately when a calendar event is updated */ export type CalendarEventUpdatedTrigger = { type: "calendar.event.updated"; /** Key of the declared calendar connection. */ connectionKey: TKey; /** Named target from this Calendar connection; resolved from saved setup. */ calendarTarget: string; }; /** Triggers immediately when a calendar event is canceled */ export type CalendarEventCanceledTrigger = { type: "calendar.event.canceled"; /** Key of the declared calendar connection. */ connectionKey: TKey; /** Named target from this Calendar connection; resolved from saved setup. */ calendarTarget: string; }; /** A page was deleted. */ export type NotionPageDeletedTrigger = { type: "notion.page.deleted"; }; /** A meeting note's AI summary finished generating. */ export type NotionMeetingNoteSummaryCompletedTrigger = { type: "notion.meetingNote.summary.completed"; }; /** A comment was added to a page discussion. */ export type NotionCommentAddedTrigger = { type: "notion.page.discussion.comment.added"; }; /** An agent was mentioned in page content or a person property. */ export type NotionAgentMentionedTrigger = { type: "notion.agent.mentioned"; }; /** A button block was pressed. */ export type NotionButtonPressedTrigger = { type: "notion.button.pressed"; }; /** A database agent's configuration was updated. */ export type NotionDatabaseAgentUpdatedTrigger = { type: "notion.database.agent.updated"; }; /** An incoming webhook request was received. */ export type WebhookTrigger = { type: "webhooks.webhook"; }; /** Watches for file changes in a specific Google Drive folder (direct children only) or shared drive. The My Drive root is not supported. Fires on a schedule and provides change tokens for fetching the list of changes. */ export type GoogleDriveOauthFilesChangedTrigger = { type: "googleDriveOauth.filesChanged"; /** Key of the declared googleDriveOauth connection. */ connectionKey?: TKey; }; function manual(): ManualWorkflowTrigger>; function manual>(options: { inputSchema: SchemaBuilder; }): ManualWorkflowTrigger; function manual(options?: { inputSchema: SchemaBuilder, "object">; }): ManualWorkflowTrigger { const { jsonSchema, validate } = compileWorkflowInputSchema( options === undefined ? j.object({}) : options.inputSchema, ); const trigger: ManualWorkflowTrigger = { type: "workflow.manual", inputJsonSchema: jsonSchema, }; manualInputValidators.set(trigger, validate); return trigger; } /** Creators for each event that can trigger a workflow. */ export const events = { manual, /** * Declare that a workflow can run on `slack.message` events. * * Triggers immediately after a new message is posted in Slack (includes new threads and replies) */ slackMessage(options: { connectionKey: TKey } | undefined = undefined): SlackMessageTrigger { return { type: "slack.message", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `slack.reaction.added` events. * * Triggers immediately after a reaction is added to a message in Slack */ slackReactionAdded(options: { connectionKey: TKey } | undefined = undefined): SlackReactionAddedTrigger { return { type: "slack.reaction.added", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `slack.app.mention` events. * * Triggers when the agent is mentioned in a Slack channel or direct message */ slackAppMention(options: { connectionKey: TKey } | undefined = undefined): SlackAppMentionTrigger { return { type: "slack.app.mention", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `discord.interaction` events. * * Triggers when a user invokes the /ai slash command in a configured Discord channel */ discordInteraction(options: { connectionKey: TKey } | undefined = undefined): DiscordInteractionTrigger { return { type: "discord.interaction", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `mail.email.received` events. * * Triggers immediately when a new email is received in Notion Mail */ mailEmailReceived(options: { connectionKey: TKey } | undefined = undefined): MailEmailReceivedTrigger { return { type: "mail.email.received", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `mail.email.sent` events. * * Triggers immediately when a new email is sent from Notion Mail */ mailEmailSent(options: { connectionKey: TKey } | undefined = undefined): MailEmailSentTrigger { return { type: "mail.email.sent", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `mail.label.applied` events. * * Triggers immediately when a label is applied to an email in Notion Mail */ mailLabelApplied(options: { connectionKey: TKey } | undefined = undefined): MailLabelAppliedTrigger { return { type: "mail.label.applied", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, /** * Declare that a workflow can run on `calendar.event.created` events. * * Triggers immediately when a calendar event is created */ calendarEventCreated(options: { calendars: CalendarTriggerTarget }): CalendarEventCreatedTrigger { return { type: "calendar.event.created", connectionKey: options.calendars.connectionKey, calendarTarget: options.calendars.target, }; }, /** * Declare that a workflow can run on `calendar.event.updated` events. * * Triggers immediately when a calendar event is updated */ calendarEventUpdated(options: { calendars: CalendarTriggerTarget }): CalendarEventUpdatedTrigger { return { type: "calendar.event.updated", connectionKey: options.calendars.connectionKey, calendarTarget: options.calendars.target, }; }, /** * Declare that a workflow can run on `calendar.event.canceled` events. * * Triggers immediately when a calendar event is canceled */ calendarEventCanceled(options: { calendars: CalendarTriggerTarget }): CalendarEventCanceledTrigger { return { type: "calendar.event.canceled", connectionKey: options.calendars.connectionKey, calendarTarget: options.calendars.target, }; }, notionPageCreated, notionPageUpdated, /** * Declare that a workflow can run on `notion.page.deleted` events. * * A page was deleted. */ notionPageDeleted(): NotionPageDeletedTrigger { return { type: "notion.page.deleted", }; }, /** * Declare that a workflow can run on `notion.meetingNote.summary.completed` events. * * A meeting note's AI summary finished generating. */ notionMeetingNoteSummaryCompleted(): NotionMeetingNoteSummaryCompletedTrigger { return { type: "notion.meetingNote.summary.completed", }; }, /** * Declare that a workflow can run on `notion.page.discussion.comment.added` events. * * A comment was added to a page discussion. */ notionCommentAdded(): NotionCommentAddedTrigger { return { type: "notion.page.discussion.comment.added", }; }, /** * Declare that a workflow can run on `notion.agent.mentioned` events. * * An agent was mentioned in page content or a person property. */ notionAgentMentioned(): NotionAgentMentionedTrigger { return { type: "notion.agent.mentioned", }; }, /** * Declare that a workflow can run on `notion.button.pressed` events. * * A button block was pressed. */ notionButtonPressed(): NotionButtonPressedTrigger { return { type: "notion.button.pressed", }; }, /** * Declare that a workflow can run on `notion.database.agent.updated` events. * * A database agent's configuration was updated. */ notionDatabaseAgentUpdated(): NotionDatabaseAgentUpdatedTrigger { return { type: "notion.database.agent.updated", }; }, /** * Declare that a workflow can run on `webhooks.webhook` events. * * An incoming webhook request was received. */ webhook(): WebhookTrigger { return { type: "webhooks.webhook", }; }, /** * Declare that a workflow can run on `googleDriveOauth.filesChanged` events. * * Watches for file changes in a specific Google Drive folder (direct children only) or shared drive. The My Drive root is not supported. Fires on a schedule and provides change tokens for fetching the list of changes. */ googleDriveOauthFilesChanged(options: { connectionKey: TKey } | undefined = undefined): GoogleDriveOauthFilesChangedTrigger { return { type: "googleDriveOauth.filesChanged", ...(options === undefined ? {} : { connectionKey: options.connectionKey }), }; }, scheduled, } as const; /** Trigger creators restricted to the workflow's declared provider keys. */ export type WorkflowEventCreators = { manual(): ManualWorkflowTrigger>; manual>(options: { inputSchema: SchemaBuilder }): ManualWorkflowTrigger; slackMessage(options?: { connectionKey: WorkflowConnectionKeys }): SlackMessageTrigger>; slackReactionAdded(options?: { connectionKey: WorkflowConnectionKeys }): SlackReactionAddedTrigger>; slackAppMention(options?: { connectionKey: WorkflowConnectionKeys }): SlackAppMentionTrigger>; discordInteraction(options?: { connectionKey: WorkflowConnectionKeys }): DiscordInteractionTrigger>; mailEmailReceived(options?: { connectionKey: WorkflowConnectionKeys }): MailEmailReceivedTrigger>; mailEmailSent(options?: { connectionKey: WorkflowConnectionKeys }): MailEmailSentTrigger>; mailLabelApplied(options?: { connectionKey: WorkflowConnectionKeys }): MailLabelAppliedTrigger>; calendarEventCreated(options: { calendars: CalendarTriggerTarget> }): CalendarEventCreatedTrigger>; calendarEventUpdated(options: { calendars: CalendarTriggerTarget> }): CalendarEventUpdatedTrigger>; calendarEventCanceled(options: { calendars: CalendarTriggerTarget> }): CalendarEventCanceledTrigger>; notionPageCreated(options?: { dataSource: DataSourceHandle }): NotionPageCreatedTrigger; notionPageUpdated(options?: PageUpdatedOptions): NotionPageUpdatedTrigger; notionPageDeleted(): NotionPageDeletedTrigger; notionMeetingNoteSummaryCompleted(): NotionMeetingNoteSummaryCompletedTrigger; notionCommentAdded(): NotionCommentAddedTrigger; notionAgentMentioned(): NotionAgentMentionedTrigger; notionButtonPressed(): NotionButtonPressedTrigger; notionDatabaseAgentUpdated(): NotionDatabaseAgentUpdatedTrigger; webhook(): WebhookTrigger; googleDriveOauthFilesChanged(options?: { connectionKey: WorkflowConnectionKeys }): GoogleDriveOauthFilesChangedTrigger>; scheduled(options?: RecurrenceSchedule): RecurrenceTrigger; }; /** Triggers whose connection keys belong to the declared provider. */ export type WorkflowTriggerForConnections = | ManualWorkflowTrigger | SlackMessageTrigger> | SlackReactionAddedTrigger> | SlackAppMentionTrigger> | DiscordInteractionTrigger> | MailEmailReceivedTrigger> | MailEmailSentTrigger> | MailLabelAppliedTrigger> | CalendarEventCreatedTrigger> | CalendarEventUpdatedTrigger> | CalendarEventCanceledTrigger> | NotionPageCreatedTrigger | NotionPageUpdatedTrigger | NotionPageDeletedTrigger | NotionMeetingNoteSummaryCompletedTrigger | NotionCommentAddedTrigger | NotionAgentMentionedTrigger | NotionButtonPressedTrigger | NotionDatabaseAgentUpdatedTrigger | WebhookTrigger | GoogleDriveOauthFilesChangedTrigger> | RecurrenceTrigger; /** @internal */ export function createWorkflowTriggerContext( declarations: TConnections | undefined, ): { events: WorkflowEventCreators; connections: WorkflowTriggerConnections }; export function createWorkflowTriggerContext(declarations: WorkflowConnectionDeclarations | undefined) { const connections: Record }> = {}; Object.setPrototypeOf(connections, null); for (const [connectionKey, declaration] of Object.entries(declarations ?? {})) { if (declaration.type !== "calendar" || !declaration.calendar) continue; connections[connectionKey] = Object.freeze({ targets: Object.freeze(Object.fromEntries( Object.keys(declaration.calendar.targets).map((target) => [ target, Object.freeze({ connectionKey, target }), ]), )), }); } return { events, connections: Object.freeze(connections) }; } /** Event that can trigger a workflow. */ export type WorkflowTrigger = | ManualWorkflowTrigger | SlackMessageTrigger | SlackReactionAddedTrigger | SlackAppMentionTrigger | DiscordInteractionTrigger | MailEmailReceivedTrigger | MailEmailSentTrigger | MailLabelAppliedTrigger | CalendarEventCreatedTrigger | CalendarEventUpdatedTrigger | CalendarEventCanceledTrigger | NotionPageCreatedTrigger | NotionPageUpdatedTrigger | NotionPageDeletedTrigger | NotionMeetingNoteSummaryCompletedTrigger | NotionCommentAddedTrigger | NotionAgentMentionedTrigger | NotionButtonPressedTrigger | NotionDatabaseAgentUpdatedTrigger | WebhookTrigger | GoogleDriveOauthFilesChangedTrigger | RecurrenceTrigger; /** All workflow trigger type strings. */ export const WORKFLOW_TRIGGER_TYPES = [ "workflow.manual", "slack.message", "slack.reaction.added", "slack.app.mention", "discord.interaction", "mail.email.received", "mail.email.sent", "mail.label.applied", "calendar.event.created", "calendar.event.updated", "calendar.event.canceled", "notion.page.created", "notion.page.updated", "notion.page.deleted", "notion.meetingNote.summary.completed", "notion.page.discussion.comment.added", "notion.agent.mentioned", "notion.button.pressed", "notion.database.agent.updated", "webhooks.webhook", "googleDriveOauth.filesChanged", "recurrence", ] as const; /** A workflow trigger type string. */ export type WorkflowTriggerType = (typeof WORKFLOW_TRIGGER_TYPES)[number]; /** Maps each supported workflow trigger to the event its handler receives. */ export type WorkflowEventMap = { "slack.message": SlackMessageEvent; "slack.reaction.added": SlackReactionAddedEvent; "slack.app.mention": SlackAppMentionEvent; "discord.interaction": DiscordInteractionEvent; "mail.email.received": MailEmailReceivedEvent; "mail.email.sent": MailEmailSentEvent; "mail.label.applied": MailLabelAppliedEvent; "calendar.event.created": CalendarEventCreatedEvent; "calendar.event.updated": CalendarEventUpdatedEvent; "calendar.event.canceled": CalendarEventCanceledEvent; "notion.page.created": NotionPageCreatedEvent; "notion.page.updated": NotionPageUpdatedEvent; "notion.page.deleted": NotionPageDeletedEvent; "notion.meetingNote.summary.completed": NotionMeetingNoteSummaryCompletedEvent; "notion.page.discussion.comment.added": NotionCommentAddedEvent; "notion.agent.mentioned": NotionAgentMentionedEvent; "notion.button.pressed": NotionButtonPressedEvent; "notion.database.agent.updated": NotionDatabaseAgentUpdatedEvent; "webhooks.webhook": WebhookEvent; "googleDriveOauth.filesChanged": GoogleDriveOauthFilesChangedEvent; recurrence: RecurrenceEvent; }; /** @internal */ export function validateManualWorkflowInput( trigger: ManualWorkflowTrigger, input: unknown, ): void { const validate = manualInputValidators.get(trigger); if (validate === undefined) { throw new Error("Manual workflow trigger is missing its input schema"); } validate(input); }