@notionhq/workers 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/block.d.ts +1 -1
- package/dist/block.d.ts.map +1 -1
- package/dist/builder.d.ts +7 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +13 -0
- package/dist/capabilities/ai_connector.js +1 -1
- package/dist/capabilities/automation.js +1 -1
- package/dist/capabilities/context.d.ts +2 -1
- package/dist/capabilities/context.d.ts.map +1 -1
- package/dist/capabilities/context.js +21 -3
- package/dist/capabilities/stateful-capability.js +1 -1
- package/dist/capabilities/sync.d.ts +11 -1
- package/dist/capabilities/sync.d.ts.map +1 -1
- package/dist/capabilities/sync.js +25 -5
- package/dist/capabilities/tool.d.ts +21 -0
- package/dist/capabilities/tool.d.ts.map +1 -1
- package/dist/capabilities/tool.js +3 -2
- package/dist/capabilities/webhook.js +1 -1
- package/dist/capabilities/workflow.d.ts +50 -0
- package/dist/capabilities/workflow.d.ts.map +1 -0
- package/dist/capabilities/workflow.js +40 -0
- package/dist/capabilities/workflow.test.d.ts +2 -0
- package/dist/capabilities/workflow.test.d.ts.map +1 -0
- package/dist/error.d.ts +36 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +14 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/schema-builder.d.ts.map +1 -1
- package/dist/triggers.d.ts +365 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.generated.d.ts +246 -0
- package/dist/triggers.generated.d.ts.map +1 -0
- package/dist/triggers.generated.js +239 -0
- package/dist/triggers.js +0 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts +33 -2
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +34 -0
- package/package.json +9 -2
- package/src/block.ts +40 -40
- package/src/builder.ts +20 -0
- package/src/capabilities/ai_connector.ts +1 -1
- package/src/capabilities/automation.ts +1 -1
- package/src/capabilities/context.ts +45 -3
- package/src/capabilities/stateful-capability.ts +1 -1
- package/src/capabilities/sync.test.ts +172 -1
- package/src/capabilities/sync.ts +46 -5
- package/src/capabilities/tool.test.ts +63 -0
- package/src/capabilities/tool.ts +23 -1
- package/src/capabilities/webhook.ts +1 -1
- package/src/capabilities/workflow.test.ts +184 -0
- package/src/capabilities/workflow.ts +119 -0
- package/src/error.ts +40 -0
- package/src/index.ts +22 -2
- package/src/schema-builder.ts +1 -0
- package/src/triggers.generated.ts +489 -0
- package/src/triggers.ts +504 -0
- package/src/types.ts +20 -0
- package/src/worker.ts +101 -8
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ExecutionError } from "../error.js";
|
|
2
|
+
import type {
|
|
3
|
+
WorkflowEventMap,
|
|
4
|
+
WorkflowTrigger,
|
|
5
|
+
} from "../triggers.generated.js";
|
|
6
|
+
import type { HandlerOptions } from "../types.js";
|
|
7
|
+
import type { CapabilityContext } from "./context.js";
|
|
8
|
+
import { createCapabilityContext } from "./context.js";
|
|
9
|
+
import { writeOutput } from "./output.js";
|
|
10
|
+
|
|
11
|
+
export type WorkflowEvent = WorkflowEventMap[keyof WorkflowEventMap];
|
|
12
|
+
|
|
13
|
+
export type WorkflowEventForTrigger<T extends WorkflowTrigger> =
|
|
14
|
+
WorkflowEventMap[T["type"]];
|
|
15
|
+
|
|
16
|
+
export type WorkflowEventForTriggers<T extends readonly WorkflowTrigger[]> =
|
|
17
|
+
WorkflowEventForTrigger<T[number]>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for a workflow capability
|
|
21
|
+
*/
|
|
22
|
+
export type WorkflowConfiguration<
|
|
23
|
+
TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
24
|
+
> = {
|
|
25
|
+
/**
|
|
26
|
+
* A human-readable title for the workflow, shown in the UI when viewing workflows
|
|
27
|
+
*/
|
|
28
|
+
title: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A human-readable description of what the workflow does, shown in the UI when viewing workflows
|
|
32
|
+
*/
|
|
33
|
+
description: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An array of triggers that can invoke this workflow.
|
|
37
|
+
*
|
|
38
|
+
* Each trigger defines a specific event or condition that causes the workflow to run.
|
|
39
|
+
*/
|
|
40
|
+
triggers: TTriggers;
|
|
41
|
+
|
|
42
|
+
execute: (
|
|
43
|
+
event: WorkflowEventForTriggers<TTriggers>,
|
|
44
|
+
context: CapabilityContext,
|
|
45
|
+
) => Promise<void> | void;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type WorkflowCapability<
|
|
49
|
+
TTriggers extends readonly [
|
|
50
|
+
WorkflowTrigger,
|
|
51
|
+
...WorkflowTrigger[],
|
|
52
|
+
] = readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
53
|
+
> = {
|
|
54
|
+
_tag: "workflow";
|
|
55
|
+
key: string;
|
|
56
|
+
config: {
|
|
57
|
+
title: string;
|
|
58
|
+
description: string;
|
|
59
|
+
triggers: TTriggers;
|
|
60
|
+
};
|
|
61
|
+
handler: (
|
|
62
|
+
event: WorkflowEventForTriggers<TTriggers>,
|
|
63
|
+
options?: HandlerOptions,
|
|
64
|
+
) => Promise<{ status: "success" } | undefined>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates a workflow capability from configuration.
|
|
69
|
+
*
|
|
70
|
+
* @param key - The unique name for this capability.
|
|
71
|
+
* @param config - The workflow configuration.
|
|
72
|
+
* @returns The capability object.
|
|
73
|
+
*/
|
|
74
|
+
export function createWorkflowCapability<
|
|
75
|
+
const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
76
|
+
>(
|
|
77
|
+
key: string,
|
|
78
|
+
config: WorkflowConfiguration<TTriggers>,
|
|
79
|
+
): WorkflowCapability<TTriggers> {
|
|
80
|
+
return {
|
|
81
|
+
_tag: "workflow",
|
|
82
|
+
key,
|
|
83
|
+
config: {
|
|
84
|
+
title: config.title,
|
|
85
|
+
description: config.description,
|
|
86
|
+
triggers: config.triggers,
|
|
87
|
+
},
|
|
88
|
+
async handler(
|
|
89
|
+
event: WorkflowEventForTriggers<TTriggers>,
|
|
90
|
+
options?: HandlerOptions,
|
|
91
|
+
): Promise<{ status: "success" } | undefined> {
|
|
92
|
+
try {
|
|
93
|
+
const capabilityContext = createCapabilityContext("workflow");
|
|
94
|
+
await config.execute(event, capabilityContext);
|
|
95
|
+
|
|
96
|
+
if (options?.concreteOutput) {
|
|
97
|
+
return { status: "success" };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
writeOutput({ _tag: "success", value: { status: "success" } });
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const error = new ExecutionError(err);
|
|
103
|
+
|
|
104
|
+
if (!options?.concreteOutput) {
|
|
105
|
+
writeOutput({
|
|
106
|
+
_tag: "error",
|
|
107
|
+
error: {
|
|
108
|
+
name: error.name,
|
|
109
|
+
message: error.message,
|
|
110
|
+
trace: error.stack,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
package/src/error.ts
CHANGED
|
@@ -11,6 +11,46 @@ export class ExecutionError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Throw this error from your sync execute handler to signal that the
|
|
16
|
+
* external API returned a rate-limit response (e.g. HTTP 429).
|
|
17
|
+
*
|
|
18
|
+
* When the platform receives this error it applies exponential backoff
|
|
19
|
+
* instead of retrying immediately. If `retryAfter` is provided, the
|
|
20
|
+
* platform will wait at least that many seconds before the next attempt.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* worker.sync("issues", {
|
|
25
|
+
* database: issuesDb,
|
|
26
|
+
* execute: async (state, ctx) => {
|
|
27
|
+
* const res = await fetch("https://api.example.com/issues");
|
|
28
|
+
* if (res.status === 429) {
|
|
29
|
+
* const retryAfter = Number(res.headers.get("Retry-After"));
|
|
30
|
+
* throw new RateLimitError({
|
|
31
|
+
* retryAfter: Number.isFinite(retryAfter) ? retryAfter : undefined,
|
|
32
|
+
* });
|
|
33
|
+
* }
|
|
34
|
+
* // ...
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class RateLimitError extends ExecutionError {
|
|
40
|
+
/**
|
|
41
|
+
* Optional number of seconds the external API asked us to wait
|
|
42
|
+
* before retrying. The platform takes the max of this value and its
|
|
43
|
+
* own exponential-backoff delay.
|
|
44
|
+
*/
|
|
45
|
+
readonly retryAfter: number | undefined;
|
|
46
|
+
|
|
47
|
+
constructor(options?: { retryAfter?: number }) {
|
|
48
|
+
super("Rate limited by external API");
|
|
49
|
+
this.name = "RateLimitError";
|
|
50
|
+
this.retryAfter = options?.retryAfter;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
14
54
|
/**
|
|
15
55
|
* Helper for exhaustive switch statements. TypeScript will error if a case is not handled.
|
|
16
56
|
*/
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
emojiIcon,
|
|
3
|
+
imageCover,
|
|
4
|
+
imageIcon,
|
|
5
|
+
notionIcon,
|
|
6
|
+
place,
|
|
7
|
+
} from "./builder.js";
|
|
2
8
|
export type {
|
|
3
9
|
AiConnectorArchetype,
|
|
4
10
|
AiConnectorCapability,
|
|
@@ -37,18 +43,32 @@ export type {
|
|
|
37
43
|
SyncExecutionResult,
|
|
38
44
|
SyncMode,
|
|
39
45
|
} from "./capabilities/sync.js";
|
|
40
|
-
export type {
|
|
46
|
+
export type {
|
|
47
|
+
ToolCapability,
|
|
48
|
+
ToolConfiguration,
|
|
49
|
+
ToolHints,
|
|
50
|
+
} from "./capabilities/tool.js";
|
|
41
51
|
export type {
|
|
42
52
|
WebhookCapability,
|
|
43
53
|
WebhookConfiguration,
|
|
44
54
|
WebhookEvent,
|
|
45
55
|
} from "./capabilities/webhook.js";
|
|
46
56
|
export { WebhookVerificationError } from "./capabilities/webhook.js";
|
|
57
|
+
export type {
|
|
58
|
+
WorkflowCapability,
|
|
59
|
+
WorkflowConfiguration,
|
|
60
|
+
WorkflowEvent,
|
|
61
|
+
WorkflowEventForTrigger,
|
|
62
|
+
WorkflowEventForTriggers,
|
|
63
|
+
} from "./capabilities/workflow.js";
|
|
64
|
+
export { RateLimitError } from "./error.js";
|
|
47
65
|
export type { AnyJSONSchema, JSONSchema } from "./json-schema.js";
|
|
48
66
|
export type { Infer, SchemaBuilder } from "./schema-builder.js";
|
|
49
67
|
export { getSchema, j } from "./schema-builder.js";
|
|
50
68
|
export type {
|
|
69
|
+
Cover,
|
|
51
70
|
Icon,
|
|
71
|
+
ImageCover,
|
|
52
72
|
ImageIcon,
|
|
53
73
|
NoticonColor,
|
|
54
74
|
NoticonName,
|
package/src/schema-builder.ts
CHANGED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
// Generated by scripts/generate-triggers.ts — do not edit by hand.
|
|
2
|
+
// Regenerate with: npm run generate
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CalendarEventCanceledEvent,
|
|
6
|
+
CalendarEventCreatedEvent,
|
|
7
|
+
CalendarEventUpdatedEvent,
|
|
8
|
+
DiscordInteractionEvent,
|
|
9
|
+
GoogleDriveOauthFilesChangedEvent,
|
|
10
|
+
MailEmailReceivedEvent,
|
|
11
|
+
MailEmailSentEvent,
|
|
12
|
+
MailLabelAppliedEvent,
|
|
13
|
+
NotionAgentMentionedEvent,
|
|
14
|
+
NotionButtonPressedEvent,
|
|
15
|
+
NotionCommentAddedEvent,
|
|
16
|
+
NotionDatabaseAgentUpdatedEvent,
|
|
17
|
+
NotionMeetingNoteSummaryCompletedEvent,
|
|
18
|
+
NotionPageCreatedEvent,
|
|
19
|
+
NotionPageDeletedEvent,
|
|
20
|
+
NotionPageUpdatedEvent,
|
|
21
|
+
RecurrenceEvent,
|
|
22
|
+
SlackAppMentionEvent,
|
|
23
|
+
SlackMessageEvent,
|
|
24
|
+
SlackReactionAddedEvent,
|
|
25
|
+
WebhookEvent,
|
|
26
|
+
} from "./triggers.js";
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
Actor,
|
|
30
|
+
ActorLike,
|
|
31
|
+
CalendarEventCanceledEvent,
|
|
32
|
+
CalendarEventCreatedEvent,
|
|
33
|
+
CalendarEventLike,
|
|
34
|
+
CalendarEventUpdatedEvent,
|
|
35
|
+
ChatMessageLike,
|
|
36
|
+
ChatThreadMessage,
|
|
37
|
+
DiscordChatThreadMessage,
|
|
38
|
+
DiscordInteractionEvent,
|
|
39
|
+
EmailMessageLike,
|
|
40
|
+
EmailThreadLike,
|
|
41
|
+
EmailTriggerMessage,
|
|
42
|
+
GoogleDriveOauthFilesChangedEvent,
|
|
43
|
+
LinkLike,
|
|
44
|
+
MailEmailReceivedEvent,
|
|
45
|
+
MailEmailSentEvent,
|
|
46
|
+
MailLabelAppliedEvent,
|
|
47
|
+
MessageLike,
|
|
48
|
+
NotionAgentMentionedEvent,
|
|
49
|
+
NotionButtonPressedEvent,
|
|
50
|
+
NotionCommentAddedEvent,
|
|
51
|
+
NotionDatabaseAgentUpdatedEvent,
|
|
52
|
+
NotionMeetingNoteSummaryCompletedEvent,
|
|
53
|
+
NotionPageCreatedEvent,
|
|
54
|
+
NotionPageDeletedEvent,
|
|
55
|
+
NotionPageEdit,
|
|
56
|
+
NotionPageUpdatedEvent,
|
|
57
|
+
RecurrenceEvent,
|
|
58
|
+
RecurrenceFrequency,
|
|
59
|
+
SlackAppMentionEvent,
|
|
60
|
+
SlackChatThreadMessage,
|
|
61
|
+
SlackMessageEvent,
|
|
62
|
+
SlackReactionAddedEvent,
|
|
63
|
+
ThreadLike,
|
|
64
|
+
ThreadMessage,
|
|
65
|
+
TimestampLike,
|
|
66
|
+
TriggerEvent,
|
|
67
|
+
TriggerEventBase,
|
|
68
|
+
TriggerEventMap,
|
|
69
|
+
TriggerType,
|
|
70
|
+
VendorActor,
|
|
71
|
+
VendorExtensions,
|
|
72
|
+
WebhookEvent,
|
|
73
|
+
} from "./triggers.js";
|
|
74
|
+
|
|
75
|
+
/** A message was posted in a subscribed Slack channel. */
|
|
76
|
+
export type SlackMessageTrigger = {
|
|
77
|
+
type: "slack.message";
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** A reaction was added to a Slack message. */
|
|
81
|
+
export type SlackReactionAddedTrigger = {
|
|
82
|
+
type: "slack.reaction.added";
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** The Notion app was mentioned in a Slack message. */
|
|
86
|
+
export type SlackAppMentionTrigger = {
|
|
87
|
+
type: "slack.app.mention";
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** A Discord interaction was received. */
|
|
91
|
+
export type DiscordInteractionTrigger = {
|
|
92
|
+
type: "discord.interaction";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** An email was received. */
|
|
96
|
+
export type MailEmailReceivedTrigger = {
|
|
97
|
+
type: "mail.email.received";
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** An email was sent. */
|
|
101
|
+
export type MailEmailSentTrigger = {
|
|
102
|
+
type: "mail.email.sent";
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** A label was applied to an email. */
|
|
106
|
+
export type MailLabelAppliedTrigger = {
|
|
107
|
+
type: "mail.label.applied";
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** A calendar event was created. */
|
|
111
|
+
export type CalendarEventCreatedTrigger = {
|
|
112
|
+
type: "calendar.event.created";
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** A calendar event was updated. */
|
|
116
|
+
export type CalendarEventUpdatedTrigger = {
|
|
117
|
+
type: "calendar.event.updated";
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** A calendar event was canceled. */
|
|
121
|
+
export type CalendarEventCanceledTrigger = {
|
|
122
|
+
type: "calendar.event.canceled";
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** A page has been added to a database. */
|
|
126
|
+
export type NotionPageCreatedTrigger = {
|
|
127
|
+
type: "notion.page.created";
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** A page was updated. */
|
|
131
|
+
export type NotionPageUpdatedTrigger = {
|
|
132
|
+
type: "notion.page.updated";
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** A page was deleted. */
|
|
136
|
+
export type NotionPageDeletedTrigger = {
|
|
137
|
+
type: "notion.page.deleted";
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** A meeting note's AI summary finished generating. */
|
|
141
|
+
export type NotionMeetingNoteSummaryCompletedTrigger = {
|
|
142
|
+
type: "notion.meetingNote.summary.completed";
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** A comment was added to a page discussion. */
|
|
146
|
+
export type NotionCommentAddedTrigger = {
|
|
147
|
+
type: "notion.page.discussion.comment.added";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** An agent was mentioned in page content or a person property. */
|
|
151
|
+
export type NotionAgentMentionedTrigger = {
|
|
152
|
+
type: "notion.agent.mentioned";
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** A button block was pressed. */
|
|
156
|
+
export type NotionButtonPressedTrigger = {
|
|
157
|
+
type: "notion.button.pressed";
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** A database agent's configuration was updated. */
|
|
161
|
+
export type NotionDatabaseAgentUpdatedTrigger = {
|
|
162
|
+
type: "notion.database.agent.updated";
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/** An incoming webhook request was received. */
|
|
166
|
+
export type WebhookTrigger = {
|
|
167
|
+
type: "webhooks.webhook";
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** Files changed in a watched Google Drive folder or drive. */
|
|
171
|
+
export type GoogleDriveOauthFilesChangedTrigger = {
|
|
172
|
+
type: "googleDriveOauth.filesChanged";
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** A recurring schedule fired. */
|
|
176
|
+
export type RecurrenceTrigger = {
|
|
177
|
+
type: "recurrence";
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** Creators for each event that can trigger a workflow. */
|
|
181
|
+
export const triggers = {
|
|
182
|
+
/**
|
|
183
|
+
* Declare that a workflow can run on `slack.message` events.
|
|
184
|
+
*
|
|
185
|
+
* A message was posted in a subscribed Slack channel.
|
|
186
|
+
*/
|
|
187
|
+
slackMessage(): SlackMessageTrigger {
|
|
188
|
+
return {
|
|
189
|
+
type: "slack.message",
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Declare that a workflow can run on `slack.reaction.added` events.
|
|
195
|
+
*
|
|
196
|
+
* A reaction was added to a Slack message.
|
|
197
|
+
*/
|
|
198
|
+
slackReactionAdded(): SlackReactionAddedTrigger {
|
|
199
|
+
return {
|
|
200
|
+
type: "slack.reaction.added",
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Declare that a workflow can run on `slack.app.mention` events.
|
|
206
|
+
*
|
|
207
|
+
* The Notion app was mentioned in a Slack message.
|
|
208
|
+
*/
|
|
209
|
+
slackAppMention(): SlackAppMentionTrigger {
|
|
210
|
+
return {
|
|
211
|
+
type: "slack.app.mention",
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Declare that a workflow can run on `discord.interaction` events.
|
|
217
|
+
*
|
|
218
|
+
* A Discord interaction was received.
|
|
219
|
+
*/
|
|
220
|
+
discordInteraction(): DiscordInteractionTrigger {
|
|
221
|
+
return {
|
|
222
|
+
type: "discord.interaction",
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Declare that a workflow can run on `mail.email.received` events.
|
|
228
|
+
*
|
|
229
|
+
* An email was received.
|
|
230
|
+
*/
|
|
231
|
+
mailEmailReceived(): MailEmailReceivedTrigger {
|
|
232
|
+
return {
|
|
233
|
+
type: "mail.email.received",
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Declare that a workflow can run on `mail.email.sent` events.
|
|
239
|
+
*
|
|
240
|
+
* An email was sent.
|
|
241
|
+
*/
|
|
242
|
+
mailEmailSent(): MailEmailSentTrigger {
|
|
243
|
+
return {
|
|
244
|
+
type: "mail.email.sent",
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Declare that a workflow can run on `mail.label.applied` events.
|
|
250
|
+
*
|
|
251
|
+
* A label was applied to an email.
|
|
252
|
+
*/
|
|
253
|
+
mailLabelApplied(): MailLabelAppliedTrigger {
|
|
254
|
+
return {
|
|
255
|
+
type: "mail.label.applied",
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Declare that a workflow can run on `calendar.event.created` events.
|
|
261
|
+
*
|
|
262
|
+
* A calendar event was created.
|
|
263
|
+
*/
|
|
264
|
+
calendarEventCreated(): CalendarEventCreatedTrigger {
|
|
265
|
+
return {
|
|
266
|
+
type: "calendar.event.created",
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Declare that a workflow can run on `calendar.event.updated` events.
|
|
272
|
+
*
|
|
273
|
+
* A calendar event was updated.
|
|
274
|
+
*/
|
|
275
|
+
calendarEventUpdated(): CalendarEventUpdatedTrigger {
|
|
276
|
+
return {
|
|
277
|
+
type: "calendar.event.updated",
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Declare that a workflow can run on `calendar.event.canceled` events.
|
|
283
|
+
*
|
|
284
|
+
* A calendar event was canceled.
|
|
285
|
+
*/
|
|
286
|
+
calendarEventCanceled(): CalendarEventCanceledTrigger {
|
|
287
|
+
return {
|
|
288
|
+
type: "calendar.event.canceled",
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Declare that a workflow can run on `notion.page.created` events.
|
|
294
|
+
*
|
|
295
|
+
* A page has been added to a database.
|
|
296
|
+
*/
|
|
297
|
+
notionPageCreated(): NotionPageCreatedTrigger {
|
|
298
|
+
return {
|
|
299
|
+
type: "notion.page.created",
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Declare that a workflow can run on `notion.page.updated` events.
|
|
305
|
+
*
|
|
306
|
+
* A page was updated.
|
|
307
|
+
*/
|
|
308
|
+
notionPageUpdated(): NotionPageUpdatedTrigger {
|
|
309
|
+
return {
|
|
310
|
+
type: "notion.page.updated",
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Declare that a workflow can run on `notion.page.deleted` events.
|
|
316
|
+
*
|
|
317
|
+
* A page was deleted.
|
|
318
|
+
*/
|
|
319
|
+
notionPageDeleted(): NotionPageDeletedTrigger {
|
|
320
|
+
return {
|
|
321
|
+
type: "notion.page.deleted",
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Declare that a workflow can run on `notion.meetingNote.summary.completed` events.
|
|
327
|
+
*
|
|
328
|
+
* A meeting note's AI summary finished generating.
|
|
329
|
+
*/
|
|
330
|
+
notionMeetingNoteSummaryCompleted(): NotionMeetingNoteSummaryCompletedTrigger {
|
|
331
|
+
return {
|
|
332
|
+
type: "notion.meetingNote.summary.completed",
|
|
333
|
+
};
|
|
334
|
+
},
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Declare that a workflow can run on `notion.page.discussion.comment.added` events.
|
|
338
|
+
*
|
|
339
|
+
* A comment was added to a page discussion.
|
|
340
|
+
*/
|
|
341
|
+
notionCommentAdded(): NotionCommentAddedTrigger {
|
|
342
|
+
return {
|
|
343
|
+
type: "notion.page.discussion.comment.added",
|
|
344
|
+
};
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Declare that a workflow can run on `notion.agent.mentioned` events.
|
|
349
|
+
*
|
|
350
|
+
* An agent was mentioned in page content or a person property.
|
|
351
|
+
*/
|
|
352
|
+
notionAgentMentioned(): NotionAgentMentionedTrigger {
|
|
353
|
+
return {
|
|
354
|
+
type: "notion.agent.mentioned",
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Declare that a workflow can run on `notion.button.pressed` events.
|
|
360
|
+
*
|
|
361
|
+
* A button block was pressed.
|
|
362
|
+
*/
|
|
363
|
+
notionButtonPressed(): NotionButtonPressedTrigger {
|
|
364
|
+
return {
|
|
365
|
+
type: "notion.button.pressed",
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Declare that a workflow can run on `notion.database.agent.updated` events.
|
|
371
|
+
*
|
|
372
|
+
* A database agent's configuration was updated.
|
|
373
|
+
*/
|
|
374
|
+
notionDatabaseAgentUpdated(): NotionDatabaseAgentUpdatedTrigger {
|
|
375
|
+
return {
|
|
376
|
+
type: "notion.database.agent.updated",
|
|
377
|
+
};
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Declare that a workflow can run on `webhooks.webhook` events.
|
|
382
|
+
*
|
|
383
|
+
* An incoming webhook request was received.
|
|
384
|
+
*/
|
|
385
|
+
webhook(): WebhookTrigger {
|
|
386
|
+
return {
|
|
387
|
+
type: "webhooks.webhook",
|
|
388
|
+
};
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Declare that a workflow can run on `googleDriveOauth.filesChanged` events.
|
|
393
|
+
*
|
|
394
|
+
* Files changed in a watched Google Drive folder or drive.
|
|
395
|
+
*/
|
|
396
|
+
googleDriveOauthFilesChanged(): GoogleDriveOauthFilesChangedTrigger {
|
|
397
|
+
return {
|
|
398
|
+
type: "googleDriveOauth.filesChanged",
|
|
399
|
+
};
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Declare that a workflow can run on `recurrence` events.
|
|
404
|
+
*
|
|
405
|
+
* A recurring schedule fired.
|
|
406
|
+
*/
|
|
407
|
+
recurrence(): RecurrenceTrigger {
|
|
408
|
+
return {
|
|
409
|
+
type: "recurrence",
|
|
410
|
+
};
|
|
411
|
+
},
|
|
412
|
+
} as const;
|
|
413
|
+
|
|
414
|
+
/** Event that can trigger a workflow. */
|
|
415
|
+
export type WorkflowTrigger =
|
|
416
|
+
| SlackMessageTrigger
|
|
417
|
+
| SlackReactionAddedTrigger
|
|
418
|
+
| SlackAppMentionTrigger
|
|
419
|
+
| DiscordInteractionTrigger
|
|
420
|
+
| MailEmailReceivedTrigger
|
|
421
|
+
| MailEmailSentTrigger
|
|
422
|
+
| MailLabelAppliedTrigger
|
|
423
|
+
| CalendarEventCreatedTrigger
|
|
424
|
+
| CalendarEventUpdatedTrigger
|
|
425
|
+
| CalendarEventCanceledTrigger
|
|
426
|
+
| NotionPageCreatedTrigger
|
|
427
|
+
| NotionPageUpdatedTrigger
|
|
428
|
+
| NotionPageDeletedTrigger
|
|
429
|
+
| NotionMeetingNoteSummaryCompletedTrigger
|
|
430
|
+
| NotionCommentAddedTrigger
|
|
431
|
+
| NotionAgentMentionedTrigger
|
|
432
|
+
| NotionButtonPressedTrigger
|
|
433
|
+
| NotionDatabaseAgentUpdatedTrigger
|
|
434
|
+
| WebhookTrigger
|
|
435
|
+
| GoogleDriveOauthFilesChangedTrigger
|
|
436
|
+
| RecurrenceTrigger;
|
|
437
|
+
|
|
438
|
+
/** All workflow trigger type strings. */
|
|
439
|
+
export const WORKFLOW_TRIGGER_TYPES = [
|
|
440
|
+
"slack.message",
|
|
441
|
+
"slack.reaction.added",
|
|
442
|
+
"slack.app.mention",
|
|
443
|
+
"discord.interaction",
|
|
444
|
+
"mail.email.received",
|
|
445
|
+
"mail.email.sent",
|
|
446
|
+
"mail.label.applied",
|
|
447
|
+
"calendar.event.created",
|
|
448
|
+
"calendar.event.updated",
|
|
449
|
+
"calendar.event.canceled",
|
|
450
|
+
"notion.page.created",
|
|
451
|
+
"notion.page.updated",
|
|
452
|
+
"notion.page.deleted",
|
|
453
|
+
"notion.meetingNote.summary.completed",
|
|
454
|
+
"notion.page.discussion.comment.added",
|
|
455
|
+
"notion.agent.mentioned",
|
|
456
|
+
"notion.button.pressed",
|
|
457
|
+
"notion.database.agent.updated",
|
|
458
|
+
"webhooks.webhook",
|
|
459
|
+
"googleDriveOauth.filesChanged",
|
|
460
|
+
"recurrence",
|
|
461
|
+
] as const;
|
|
462
|
+
|
|
463
|
+
/** A workflow trigger type string. */
|
|
464
|
+
export type WorkflowTriggerType = (typeof WORKFLOW_TRIGGER_TYPES)[number];
|
|
465
|
+
|
|
466
|
+
/** Maps each supported workflow trigger to the event its handler receives. */
|
|
467
|
+
export type WorkflowEventMap = {
|
|
468
|
+
"slack.message": SlackMessageEvent;
|
|
469
|
+
"slack.reaction.added": SlackReactionAddedEvent;
|
|
470
|
+
"slack.app.mention": SlackAppMentionEvent;
|
|
471
|
+
"discord.interaction": DiscordInteractionEvent;
|
|
472
|
+
"mail.email.received": MailEmailReceivedEvent;
|
|
473
|
+
"mail.email.sent": MailEmailSentEvent;
|
|
474
|
+
"mail.label.applied": MailLabelAppliedEvent;
|
|
475
|
+
"calendar.event.created": CalendarEventCreatedEvent;
|
|
476
|
+
"calendar.event.updated": CalendarEventUpdatedEvent;
|
|
477
|
+
"calendar.event.canceled": CalendarEventCanceledEvent;
|
|
478
|
+
"notion.page.created": NotionPageCreatedEvent;
|
|
479
|
+
"notion.page.updated": NotionPageUpdatedEvent;
|
|
480
|
+
"notion.page.deleted": NotionPageDeletedEvent;
|
|
481
|
+
"notion.meetingNote.summary.completed": NotionMeetingNoteSummaryCompletedEvent;
|
|
482
|
+
"notion.page.discussion.comment.added": NotionCommentAddedEvent;
|
|
483
|
+
"notion.agent.mentioned": NotionAgentMentionedEvent;
|
|
484
|
+
"notion.button.pressed": NotionButtonPressedEvent;
|
|
485
|
+
"notion.database.agent.updated": NotionDatabaseAgentUpdatedEvent;
|
|
486
|
+
"webhooks.webhook": WebhookEvent;
|
|
487
|
+
"googleDriveOauth.filesChanged": GoogleDriveOauthFilesChangedEvent;
|
|
488
|
+
recurrence: RecurrenceEvent;
|
|
489
|
+
};
|