@botpress/adk 1.19.0-beta.7 → 2.0.0-alpha.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/agent-init/agent-project-generator.d.ts +5 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +3 -3
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/agent-resolver.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/config-writer.d.ts.map +1 -1
- package/dist/agent-project/dependencies-parser.d.ts.map +1 -1
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/file-watcher.d.ts.map +1 -1
- package/dist/agent-project/types.d.ts +9 -4
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +6 -5
- package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
- package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
- package/dist/agent0/capabilities/commands/adk-document.md +10 -2
- package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
- package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
- package/dist/agent0/capabilities/commands/adk-init.md +2 -2
- package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
- package/dist/agent0/capabilities/commands/adk-test.md +3 -3
- package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
- package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
- package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
- package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
- package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
- package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
- package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
- package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
- package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
- package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
- package/dist/agent0/config/schema.d.ts.map +1 -1
- package/dist/agent0/config/store.d.ts +8 -3
- package/dist/agent0/config/store.d.ts.map +1 -1
- package/dist/agent0/index.js +214 -59
- package/dist/agent0/index.js.map +17 -15
- package/dist/agent0/providers/catalog.d.ts.map +1 -1
- package/dist/agent0/providers/registry.d.ts.map +1 -1
- package/dist/agent0/providers/source.d.ts +8 -3
- package/dist/agent0/providers/source.d.ts.map +1 -1
- package/dist/agent0/runtime/client.d.ts +4 -3
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +7 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/manager.d.ts +2 -3
- package/dist/agent0/runtime/manager.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +10 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/auth/credentials.d.ts.map +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/service.d.ts.map +1 -1
- package/dist/bot-generator/generator.d.ts +22 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/integration-sync.d.ts +2 -0
- package/dist/bot-generator/integration-sync.d.ts.map +1 -1
- package/dist/bot-generator/interface-sync.d.ts +2 -0
- package/dist/bot-generator/interface-sync.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts +2 -0
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/cognitive/models.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-cli.d.ts.map +1 -1
- package/dist/commands/bp-cli.js +147 -0
- package/dist/commands/bp-cli.js.map +12 -0
- package/dist/commands/bp-dev-command.d.ts +3 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +9 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/bp-dev-worker-env.d.ts +7 -0
- package/dist/commands/bp-dev-worker-env.d.ts.map +1 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/config/manager.d.ts.map +1 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
- package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
- package/dist/dependencies/catalog/client-factory.d.ts +33 -0
- package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
- package/dist/dependencies/catalog/integration-source.d.ts +34 -0
- package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/interface-source.d.ts +23 -0
- package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
- package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
- package/dist/dependencies/dependency-manager.d.ts +31 -16
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +9 -6
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +5 -4
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +2309 -1697
- package/dist/dependencies/index.js.map +41 -32
- package/dist/dependencies/legacy-lock-file.d.ts +15 -0
- package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +19 -0
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/snapshot-store.d.ts +59 -0
- package/dist/dependencies/snapshot-store.d.ts.map +1 -0
- package/dist/dependencies/status-resolver.d.ts +36 -0
- package/dist/dependencies/status-resolver.d.ts.map +1 -0
- package/dist/dependencies/status.d.ts +214 -0
- package/dist/dependencies/status.d.ts.map +1 -0
- package/dist/dependencies/types.d.ts +388 -37
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts +21 -5
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/generators/action-types.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3643 -2345
- package/dist/index.js.map +68 -58
- package/dist/integrations/config-utils.d.ts +11 -7
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +1 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +19 -53
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/interfaces/enhanced-cache.d.ts +7 -7
- package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
- package/dist/interfaces/manager.d.ts +11 -17
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/interfaces/parser.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +16 -48
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/dependency-gate.d.ts +37 -0
- package/dist/preflight/dependency-gate.d.ts.map +1 -0
- package/dist/preflight/index.d.ts +2 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +18 -0
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/secrets/manager.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/templates/README.md +23 -13
- package/dist/templates/blank/agent.config.ts +3 -3
- package/dist/templates/blank/src/triggers/index.ts +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
- package/dist/templates/crm-enrichment/README.md +3 -3
- package/dist/templates/crm-enrichment/agent.config.ts +2 -2
- package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
- package/dist/templates/hello-world/agent.config.ts +3 -3
- package/dist/templates/hello-world/src/triggers/index.ts +1 -1
- package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/test-utils/mock-module.d.ts +29 -0
- package/dist/test-utils/mock-module.d.ts.map +1 -0
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/utils/require-chat.d.ts.map +1 -1
- package/dist/utils/source-map-optimizer.d.ts +10 -11
- package/dist/utils/source-map-optimizer.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +8 -4
- package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
- package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/lock-file.d.ts +0 -15
- package/dist/dependencies/lock-file.d.ts.map +0 -1
- package/dist/integrations/enhanced-cache.d.ts +0 -53
- package/dist/integrations/enhanced-cache.d.ts.map +0 -1
- package/dist/plugins/enhanced-cache.d.ts +0 -53
- package/dist/plugins/enhanced-cache.d.ts.map +0 -1
- package/dist/templates/blank/package.json +0 -17
- package/dist/templates/blank/tsconfig.json +0 -25
- package/dist/templates/botpress-desk/package.json +0 -17
- package/dist/templates/crm-enrichment/package.json +0 -18
- package/dist/templates/crm-enrichment/tsconfig.json +0 -25
- package/dist/templates/hello-world/package.json +0 -18
- package/dist/templates/hello-world/tsconfig.json +0 -25
- package/dist/templates/knowledge-assistant/package.json +0 -18
- package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
- package/dist/templates/slack-triage/package.json +0 -18
- package/dist/templates/slack-triage/tsconfig.json +0 -25
|
@@ -9,11 +9,13 @@ Triggers allow your bot to react to events from the bot itself or integrated ser
|
|
|
9
9
|
## Basic Concepts
|
|
10
10
|
|
|
11
11
|
### What are Triggers?
|
|
12
|
+
|
|
12
13
|
- **Event handlers**: React to bot or integration events
|
|
13
14
|
- **Automated**: Execute automatically when events occur
|
|
14
15
|
- **Flexible**: Can start workflows, update tables, or perform any action
|
|
15
16
|
|
|
16
17
|
### File Location
|
|
18
|
+
|
|
17
19
|
- **Location**: `src/triggers/*.ts`
|
|
18
20
|
- **Auto-registration**: Files automatically subscribe to specified events
|
|
19
21
|
|
|
@@ -22,21 +24,21 @@ Triggers allow your bot to react to events from the bot itself or integrated ser
|
|
|
22
24
|
### Basic Structure
|
|
23
25
|
|
|
24
26
|
```typescript
|
|
25
|
-
import { Trigger } from
|
|
27
|
+
import { Trigger } from '@botpress/runtime'
|
|
26
28
|
|
|
27
29
|
export default new Trigger({
|
|
28
|
-
name:
|
|
29
|
-
description:
|
|
30
|
-
events: [
|
|
30
|
+
name: 'myTrigger',
|
|
31
|
+
description: 'Handles user creation events',
|
|
32
|
+
events: ['user.created'], // Events to subscribe to
|
|
31
33
|
|
|
32
34
|
handler: async ({ event }) => {
|
|
33
|
-
console.log(event.type)
|
|
34
|
-
console.log(event.payload)
|
|
35
|
+
console.log(event.type) // "user.created"
|
|
36
|
+
console.log(event.payload) // Event data
|
|
35
37
|
|
|
36
38
|
// React to the event
|
|
37
|
-
await handleUserCreated(event.payload)
|
|
38
|
-
}
|
|
39
|
-
})
|
|
39
|
+
await handleUserCreated(event.payload)
|
|
40
|
+
},
|
|
41
|
+
})
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
### Multiple Events
|
|
@@ -45,28 +47,24 @@ Subscribe to multiple events in one trigger:
|
|
|
45
47
|
|
|
46
48
|
```typescript
|
|
47
49
|
export default new Trigger({
|
|
48
|
-
name:
|
|
49
|
-
description:
|
|
50
|
-
events: [
|
|
51
|
-
"user.created",
|
|
52
|
-
"user.updated",
|
|
53
|
-
"user.deleted"
|
|
54
|
-
],
|
|
50
|
+
name: 'userEvents',
|
|
51
|
+
description: 'Handles all user-related events',
|
|
52
|
+
events: ['user.created', 'user.updated', 'user.deleted'],
|
|
55
53
|
|
|
56
54
|
handler: async ({ event }) => {
|
|
57
55
|
switch (event.type) {
|
|
58
|
-
case
|
|
59
|
-
await handleUserCreated(event.payload)
|
|
60
|
-
break
|
|
61
|
-
case
|
|
62
|
-
await handleUserUpdated(event.payload)
|
|
63
|
-
break
|
|
64
|
-
case
|
|
65
|
-
await handleUserDeleted(event.payload)
|
|
66
|
-
break
|
|
56
|
+
case 'user.created':
|
|
57
|
+
await handleUserCreated(event.payload)
|
|
58
|
+
break
|
|
59
|
+
case 'user.updated':
|
|
60
|
+
await handleUserUpdated(event.payload)
|
|
61
|
+
break
|
|
62
|
+
case 'user.deleted':
|
|
63
|
+
await handleUserDeleted(event.payload)
|
|
64
|
+
break
|
|
67
65
|
}
|
|
68
|
-
}
|
|
69
|
-
})
|
|
66
|
+
},
|
|
67
|
+
})
|
|
70
68
|
```
|
|
71
69
|
|
|
72
70
|
## Event Types
|
|
@@ -77,23 +75,23 @@ Standard events emitted by the bot:
|
|
|
77
75
|
|
|
78
76
|
```typescript
|
|
79
77
|
// User events
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
'user.created' // New user created
|
|
79
|
+
'user.updated' // User information updated
|
|
80
|
+
'user.deleted' // User deleted
|
|
83
81
|
|
|
84
82
|
// Conversation events
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
'conversation.started' // New conversation started
|
|
84
|
+
'conversation.ended' // Conversation ended
|
|
85
|
+
'message.created' // New message in conversation
|
|
88
86
|
|
|
89
87
|
// Workflow events
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
'workflow.started' // Workflow instance started
|
|
89
|
+
'workflow.completed' // Workflow completed successfully
|
|
90
|
+
'workflow.failed' // Workflow failed
|
|
93
91
|
|
|
94
92
|
// Bot lifecycle events
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
'bot.started' // Bot started
|
|
94
|
+
'bot.stopped' // Bot stopped
|
|
97
95
|
```
|
|
98
96
|
|
|
99
97
|
### Integration Events
|
|
@@ -104,35 +102,36 @@ Events from integrated services use the pattern `integrationName:eventName`.
|
|
|
104
102
|
|
|
105
103
|
```typescript
|
|
106
104
|
// Intercom events (real events from vertical-one)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
'intercom:conversationEvent' // Fires on create/update/delete
|
|
106
|
+
'intercom:contactEvent' // Contact created/updated
|
|
107
|
+
'intercom:adminEvent' // Admin changes
|
|
110
108
|
|
|
111
109
|
// Slack events (verified with adk info slack --events)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
'slack:reactionAdded'
|
|
111
|
+
'slack:reactionRemoved'
|
|
112
|
+
'slack:memberJoinedChannel'
|
|
113
|
+
'slack:memberJoinedWorkspace'
|
|
114
|
+
'slack:memberLeftChannel'
|
|
115
|
+
'slack:workflowWebhook'
|
|
118
116
|
|
|
119
117
|
// Linear events (verified with adk info linear --events)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
'linear:issueCreated'
|
|
119
|
+
'linear:issueUpdated'
|
|
120
|
+
'linear:issueDeleted'
|
|
123
121
|
|
|
124
122
|
// GitHub events (verified with adk info github --events)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
'github:issueOpened'
|
|
124
|
+
'github:pullRequestOpened'
|
|
125
|
+
'github:pullRequestMerged'
|
|
126
|
+
'github:pullRequestReviewSubmitted'
|
|
129
127
|
|
|
130
128
|
// Webchat events (verified with adk info webchat --events)
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
'webchat:conversationStarted'
|
|
130
|
+
'webchat:trigger'
|
|
133
131
|
```
|
|
134
132
|
|
|
135
133
|
**How to discover events:**
|
|
134
|
+
|
|
136
135
|
```bash
|
|
137
136
|
# Search for an integration
|
|
138
137
|
adk search email
|
|
@@ -152,28 +151,28 @@ Checking `adk info <integration> --events` confirms the event exists, but it doe
|
|
|
152
151
|
Common pattern: Start a workflow when an event occurs:
|
|
153
152
|
|
|
154
153
|
```typescript
|
|
155
|
-
import { Trigger } from
|
|
156
|
-
import { OnboardingWorkflow } from
|
|
154
|
+
import { Trigger } from '@botpress/runtime'
|
|
155
|
+
import { OnboardingWorkflow } from '../workflows/onboarding'
|
|
157
156
|
|
|
158
157
|
export default new Trigger({
|
|
159
|
-
name:
|
|
160
|
-
description:
|
|
161
|
-
events: [
|
|
158
|
+
name: 'userOnboarding',
|
|
159
|
+
description: 'Start onboarding when user is created',
|
|
160
|
+
events: ['user.created'],
|
|
162
161
|
|
|
163
162
|
handler: async ({ event }) => {
|
|
164
|
-
const { userId, email, name } = event.payload
|
|
163
|
+
const { userId, email, name } = event.payload
|
|
165
164
|
|
|
166
165
|
// Start onboarding workflow
|
|
167
166
|
const instance = await OnboardingWorkflow.start({
|
|
168
167
|
userId,
|
|
169
168
|
email,
|
|
170
169
|
name,
|
|
171
|
-
createdAt: new Date()
|
|
172
|
-
})
|
|
170
|
+
createdAt: new Date(),
|
|
171
|
+
})
|
|
173
172
|
|
|
174
|
-
console.log(`Started onboarding for ${userId}: ${instance.id}`)
|
|
175
|
-
}
|
|
176
|
-
})
|
|
173
|
+
console.log(`Started onboarding for ${userId}: ${instance.id}`)
|
|
174
|
+
},
|
|
175
|
+
})
|
|
177
176
|
```
|
|
178
177
|
|
|
179
178
|
### Updating Tables
|
|
@@ -181,34 +180,31 @@ export default new Trigger({
|
|
|
181
180
|
Store event data in tables:
|
|
182
181
|
|
|
183
182
|
```typescript
|
|
184
|
-
import { Trigger } from
|
|
185
|
-
import { EventLogTable } from
|
|
183
|
+
import { Trigger } from '@botpress/runtime'
|
|
184
|
+
import { EventLogTable } from '../tables/EventLog'
|
|
186
185
|
|
|
187
186
|
export default new Trigger({
|
|
188
|
-
name:
|
|
189
|
-
description:
|
|
190
|
-
events: [
|
|
191
|
-
"user.created",
|
|
192
|
-
"user.updated",
|
|
193
|
-
"conversation.started",
|
|
194
|
-
"workflow.completed"
|
|
195
|
-
],
|
|
187
|
+
name: 'eventLogger',
|
|
188
|
+
description: 'Log all events to database',
|
|
189
|
+
events: ['user.created', 'user.updated', 'conversation.started', 'workflow.completed'],
|
|
196
190
|
|
|
197
191
|
handler: async ({ event }) => {
|
|
198
192
|
// Store event in table
|
|
199
193
|
await EventLogTable.createRows({
|
|
200
|
-
rows: [
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
})
|
|
194
|
+
rows: [
|
|
195
|
+
{
|
|
196
|
+
type: event.type,
|
|
197
|
+
payload: event.payload,
|
|
198
|
+
timestamp: new Date(),
|
|
199
|
+
metadata: {
|
|
200
|
+
source: event.source || 'bot',
|
|
201
|
+
version: event.version || '1.0',
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
})
|
|
212
208
|
```
|
|
213
209
|
|
|
214
210
|
### Calling Actions
|
|
@@ -216,28 +212,29 @@ export default new Trigger({
|
|
|
216
212
|
Execute bot actions or integration actions in response to events:
|
|
217
213
|
|
|
218
214
|
```typescript
|
|
219
|
-
import { Trigger } from
|
|
220
|
-
import { actions } from
|
|
215
|
+
import { Trigger } from '@botpress/runtime'
|
|
216
|
+
import { actions } from '@botpress/runtime'
|
|
221
217
|
|
|
222
218
|
export default new Trigger({
|
|
223
|
-
name:
|
|
224
|
-
description:
|
|
225
|
-
events: [
|
|
219
|
+
name: 'notificationSender',
|
|
220
|
+
description: 'Send email notifications for important events',
|
|
221
|
+
events: ['workflow.failed', 'user.deleted'],
|
|
226
222
|
|
|
227
223
|
handler: async ({ event }) => {
|
|
228
224
|
// Call integration action (e.g., SendGrid)
|
|
229
225
|
// First add the integration: adk add sendgrid
|
|
230
226
|
await actions.sendgrid.sendEmail({
|
|
231
|
-
to:
|
|
232
|
-
from:
|
|
227
|
+
to: 'admin@example.com',
|
|
228
|
+
from: 'bot@example.com',
|
|
233
229
|
subject: `Alert: ${event.type}`,
|
|
234
|
-
content: `Event occurred: ${JSON.stringify(event.payload)}
|
|
235
|
-
})
|
|
236
|
-
}
|
|
237
|
-
})
|
|
230
|
+
content: `Event occurred: ${JSON.stringify(event.payload)}`,
|
|
231
|
+
})
|
|
232
|
+
},
|
|
233
|
+
})
|
|
238
234
|
```
|
|
239
235
|
|
|
240
236
|
**Note:** The `actions` object provides access to:
|
|
237
|
+
|
|
241
238
|
- **Bot actions**: `actions.myAction()` - your custom actions from `src/actions/`
|
|
242
239
|
- **Integration actions**: `actions.integrationName.actionName()` - actions from installed integrations
|
|
243
240
|
|
|
@@ -248,42 +245,33 @@ export default new Trigger({
|
|
|
248
245
|
Real-world example from vertical-one bot:
|
|
249
246
|
|
|
250
247
|
```typescript
|
|
251
|
-
import { Trigger } from
|
|
252
|
-
import {
|
|
253
|
-
syncSingleConversation,
|
|
254
|
-
deleteConversation,
|
|
255
|
-
} from "../utils/syncConversation";
|
|
248
|
+
import { Trigger } from '@botpress/runtime'
|
|
249
|
+
import { syncSingleConversation, deleteConversation } from '../utils/syncConversation'
|
|
256
250
|
|
|
257
251
|
export default new Trigger({
|
|
258
|
-
name:
|
|
259
|
-
description:
|
|
260
|
-
|
|
261
|
-
events: ["intercom:conversationEvent"],
|
|
252
|
+
name: 'onIntercomUpdate',
|
|
253
|
+
description: 'Updates the Intercom tables in realtime when conversations are created or messages are sent',
|
|
254
|
+
events: ['intercom:conversationEvent'],
|
|
262
255
|
|
|
263
256
|
handler: async ({ event }) => {
|
|
264
|
-
const { eventType, conversationId } = event.payload
|
|
257
|
+
const { eventType, conversationId } = event.payload
|
|
265
258
|
|
|
266
|
-
console.log(
|
|
267
|
-
`Intercom event: ${eventType} for conversation ${conversationId}`
|
|
268
|
-
);
|
|
259
|
+
console.log(`Intercom event: ${eventType} for conversation ${conversationId}`)
|
|
269
260
|
|
|
270
261
|
try {
|
|
271
|
-
if (eventType ===
|
|
262
|
+
if (eventType === 'deleted') {
|
|
272
263
|
// Delete the conversation and its messages
|
|
273
|
-
await deleteConversation(conversationId)
|
|
264
|
+
await deleteConversation(conversationId)
|
|
274
265
|
} else {
|
|
275
266
|
// Sync the conversation with all its data
|
|
276
|
-
await syncSingleConversation(conversationId)
|
|
267
|
+
await syncSingleConversation(conversationId)
|
|
277
268
|
}
|
|
278
269
|
} catch (error) {
|
|
279
|
-
console.error(
|
|
280
|
-
|
|
281
|
-
error
|
|
282
|
-
);
|
|
283
|
-
throw error;
|
|
270
|
+
console.error(`Failed to handle ${eventType} event for conversation ${conversationId}:`, error)
|
|
271
|
+
throw error
|
|
284
272
|
}
|
|
285
273
|
},
|
|
286
|
-
})
|
|
274
|
+
})
|
|
287
275
|
```
|
|
288
276
|
|
|
289
277
|
### Linear Integration
|
|
@@ -291,95 +279,96 @@ export default new Trigger({
|
|
|
291
279
|
Real example from ADK source code:
|
|
292
280
|
|
|
293
281
|
```typescript
|
|
294
|
-
import { Trigger } from
|
|
295
|
-
import { LinearIssueTable } from
|
|
282
|
+
import { Trigger } from '@botpress/runtime'
|
|
283
|
+
import { LinearIssueTable } from '../tables/LinearIssues'
|
|
296
284
|
|
|
297
285
|
export default new Trigger({
|
|
298
|
-
name:
|
|
299
|
-
description:
|
|
300
|
-
events: [
|
|
301
|
-
"linear:issueCreated",
|
|
302
|
-
"linear:issueUpdated",
|
|
303
|
-
"linear:issueDeleted"
|
|
304
|
-
],
|
|
286
|
+
name: 'onLinearIssueUpdate',
|
|
287
|
+
description: 'Updates the Linear Issue Table when issues change',
|
|
288
|
+
events: ['linear:issueCreated', 'linear:issueUpdated', 'linear:issueDeleted'],
|
|
305
289
|
|
|
306
290
|
handler: async ({ event }) => {
|
|
307
|
-
if (event.type ===
|
|
291
|
+
if (event.type === 'linear:issueDeleted') {
|
|
308
292
|
await LinearIssueTable.deleteRows({
|
|
309
|
-
linearId: event.payload.id
|
|
310
|
-
})
|
|
311
|
-
} else if (event.type ===
|
|
293
|
+
linearId: event.payload.id,
|
|
294
|
+
})
|
|
295
|
+
} else if (event.type === 'linear:issueCreated') {
|
|
312
296
|
await LinearIssueTable.createRows({
|
|
313
|
-
rows: [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
297
|
+
rows: [
|
|
298
|
+
{
|
|
299
|
+
linearId: event.payload.linearIds?.issueId,
|
|
300
|
+
content: `# ${event.payload.title}\n\n${event.payload.description}`,
|
|
301
|
+
issue: event.payload,
|
|
302
|
+
linearUpdatedAt: event.payload.updatedAt,
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
})
|
|
306
|
+
} else if (event.type === 'linear:issueUpdated') {
|
|
321
307
|
await LinearIssueTable.upsertRows({
|
|
322
|
-
rows: [
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
308
|
+
rows: [
|
|
309
|
+
{
|
|
310
|
+
linearId: event.payload.linearIds?.issueId,
|
|
311
|
+
content: `# ${event.payload.title}\n\n${event.payload.description}`,
|
|
312
|
+
issue: event.payload,
|
|
313
|
+
linearUpdatedAt: event.payload.updatedAt,
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
keyColumn: 'linearId',
|
|
317
|
+
})
|
|
330
318
|
}
|
|
331
|
-
}
|
|
332
|
-
})
|
|
319
|
+
},
|
|
320
|
+
})
|
|
333
321
|
```
|
|
334
322
|
|
|
335
323
|
### Slack Integration
|
|
336
324
|
|
|
337
325
|
```typescript
|
|
338
|
-
import { Trigger } from
|
|
339
|
-
import { SlackActivityTable } from
|
|
326
|
+
import { Trigger } from '@botpress/runtime'
|
|
327
|
+
import { SlackActivityTable } from '../tables/SlackActivity'
|
|
340
328
|
|
|
341
329
|
export default new Trigger({
|
|
342
|
-
name:
|
|
343
|
-
description:
|
|
344
|
-
events: [
|
|
345
|
-
"slack:reactionAdded",
|
|
346
|
-
"slack:memberJoinedChannel"
|
|
347
|
-
],
|
|
330
|
+
name: 'slackActivityMonitor',
|
|
331
|
+
description: 'Monitor Slack reactions and member activity',
|
|
332
|
+
events: ['slack:reactionAdded', 'slack:memberJoinedChannel'],
|
|
348
333
|
|
|
349
334
|
handler: async ({ event }) => {
|
|
350
|
-
if (event.type ===
|
|
351
|
-
const { reaction, user, item } = event.payload
|
|
335
|
+
if (event.type === 'slack:reactionAdded') {
|
|
336
|
+
const { reaction, user, item } = event.payload
|
|
352
337
|
|
|
353
338
|
// Log important reactions to table
|
|
354
|
-
if (reaction ===
|
|
339
|
+
if (reaction === 'fire' || reaction === 'star' || reaction === 'eyes') {
|
|
355
340
|
await SlackActivityTable.createRows({
|
|
356
|
-
rows: [
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
341
|
+
rows: [
|
|
342
|
+
{
|
|
343
|
+
type: 'reaction',
|
|
344
|
+
reaction: reaction,
|
|
345
|
+
user: user,
|
|
346
|
+
messageId: item.ts,
|
|
347
|
+
channelId: item.channel,
|
|
348
|
+
timestamp: new Date(),
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
})
|
|
365
352
|
}
|
|
366
353
|
}
|
|
367
354
|
|
|
368
|
-
if (event.type ===
|
|
369
|
-
const { user, channel } = event.payload
|
|
355
|
+
if (event.type === 'slack:memberJoinedChannel') {
|
|
356
|
+
const { user, channel } = event.payload
|
|
370
357
|
|
|
371
358
|
// Log new member joins
|
|
372
359
|
await SlackActivityTable.createRows({
|
|
373
|
-
rows: [
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
360
|
+
rows: [
|
|
361
|
+
{
|
|
362
|
+
type: 'member_join',
|
|
363
|
+
user: user,
|
|
364
|
+
channelId: channel,
|
|
365
|
+
timestamp: new Date(),
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
})
|
|
380
369
|
}
|
|
381
|
-
}
|
|
382
|
-
})
|
|
370
|
+
},
|
|
371
|
+
})
|
|
383
372
|
```
|
|
384
373
|
|
|
385
374
|
## Advanced Patterns
|
|
@@ -390,31 +379,31 @@ Process events based on conditions:
|
|
|
390
379
|
|
|
391
380
|
```typescript
|
|
392
381
|
export default new Trigger({
|
|
393
|
-
name:
|
|
394
|
-
events: [
|
|
382
|
+
name: 'conditionalProcessor',
|
|
383
|
+
events: ['user.created'],
|
|
395
384
|
|
|
396
385
|
handler: async ({ event }) => {
|
|
397
|
-
const { email, source, metadata } = event.payload
|
|
386
|
+
const { email, source, metadata } = event.payload
|
|
398
387
|
|
|
399
388
|
// Only process certain users
|
|
400
|
-
if (!email.endsWith(
|
|
401
|
-
console.log(
|
|
402
|
-
return
|
|
389
|
+
if (!email.endsWith('@company.com')) {
|
|
390
|
+
console.log('Skipping external user')
|
|
391
|
+
return
|
|
403
392
|
}
|
|
404
393
|
|
|
405
394
|
// Different handling based on source
|
|
406
|
-
if (source ===
|
|
407
|
-
await handleApiUser(event.payload)
|
|
408
|
-
} else if (source ===
|
|
409
|
-
await handleSignupUser(event.payload)
|
|
395
|
+
if (source === 'api') {
|
|
396
|
+
await handleApiUser(event.payload)
|
|
397
|
+
} else if (source === 'signup') {
|
|
398
|
+
await handleSignupUser(event.payload)
|
|
410
399
|
}
|
|
411
400
|
|
|
412
401
|
// Check metadata flags
|
|
413
402
|
if (metadata?.requiresApproval) {
|
|
414
|
-
await startApprovalWorkflow(event.payload)
|
|
403
|
+
await startApprovalWorkflow(event.payload)
|
|
415
404
|
}
|
|
416
|
-
}
|
|
417
|
-
})
|
|
405
|
+
},
|
|
406
|
+
})
|
|
418
407
|
```
|
|
419
408
|
|
|
420
409
|
### Event Aggregation
|
|
@@ -422,43 +411,45 @@ export default new Trigger({
|
|
|
422
411
|
Collect and batch process events:
|
|
423
412
|
|
|
424
413
|
```typescript
|
|
425
|
-
import { Trigger } from
|
|
426
|
-
import { EventBatchTable } from
|
|
414
|
+
import { Trigger } from '@botpress/runtime'
|
|
415
|
+
import { EventBatchTable } from '../tables/EventBatch'
|
|
427
416
|
|
|
428
417
|
export default new Trigger({
|
|
429
|
-
name:
|
|
430
|
-
events: [
|
|
418
|
+
name: 'eventAggregator',
|
|
419
|
+
events: ['metrics.recorded'],
|
|
431
420
|
|
|
432
421
|
handler: async ({ event }) => {
|
|
433
422
|
// Store event for batching
|
|
434
423
|
await EventBatchTable.createRows({
|
|
435
|
-
rows: [
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
424
|
+
rows: [
|
|
425
|
+
{
|
|
426
|
+
type: event.type,
|
|
427
|
+
data: event.payload,
|
|
428
|
+
processed: false,
|
|
429
|
+
timestamp: new Date(),
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
})
|
|
442
433
|
|
|
443
434
|
// Check if we should process batch
|
|
444
435
|
const { rows } = await EventBatchTable.findRows({
|
|
445
436
|
where: { processed: false },
|
|
446
|
-
limit: 100
|
|
447
|
-
})
|
|
437
|
+
limit: 100,
|
|
438
|
+
})
|
|
448
439
|
|
|
449
440
|
if (rows.length >= 100) {
|
|
450
441
|
// Process batch
|
|
451
|
-
await processBatch(rows)
|
|
442
|
+
await processBatch(rows)
|
|
452
443
|
|
|
453
444
|
// Mark as processed
|
|
454
|
-
const ids = rows.map(r => r.id)
|
|
445
|
+
const ids = rows.map((r) => r.id)
|
|
455
446
|
await EventBatchTable.updateRows({
|
|
456
447
|
where: { id: { $in: ids } },
|
|
457
|
-
updates: { processed: true }
|
|
458
|
-
})
|
|
448
|
+
updates: { processed: true },
|
|
449
|
+
})
|
|
459
450
|
}
|
|
460
|
-
}
|
|
461
|
-
})
|
|
451
|
+
},
|
|
452
|
+
})
|
|
462
453
|
```
|
|
463
454
|
|
|
464
455
|
### Workflow Orchestration
|
|
@@ -467,39 +458,39 @@ Chain workflows based on events:
|
|
|
467
458
|
|
|
468
459
|
```typescript
|
|
469
460
|
export default new Trigger({
|
|
470
|
-
name:
|
|
471
|
-
events: [
|
|
461
|
+
name: 'workflowOrchestrator',
|
|
462
|
+
events: ['workflow.completed'],
|
|
472
463
|
|
|
473
464
|
handler: async ({ event }) => {
|
|
474
|
-
const { workflowName, output } = event.payload
|
|
465
|
+
const { workflowName, output } = event.payload
|
|
475
466
|
|
|
476
467
|
// Chain workflows based on completion
|
|
477
468
|
switch (workflowName) {
|
|
478
|
-
case
|
|
469
|
+
case 'dataCollection':
|
|
479
470
|
// Start processing workflow
|
|
480
471
|
await ProcessingWorkflow.start({
|
|
481
|
-
data: output.collectedData
|
|
482
|
-
})
|
|
483
|
-
break
|
|
472
|
+
data: output.collectedData,
|
|
473
|
+
})
|
|
474
|
+
break
|
|
484
475
|
|
|
485
|
-
case
|
|
476
|
+
case 'processing':
|
|
486
477
|
// Start validation workflow
|
|
487
478
|
await ValidationWorkflow.start({
|
|
488
|
-
processedData: output.result
|
|
489
|
-
})
|
|
490
|
-
break
|
|
479
|
+
processedData: output.result,
|
|
480
|
+
})
|
|
481
|
+
break
|
|
491
482
|
|
|
492
|
-
case
|
|
483
|
+
case 'validation':
|
|
493
484
|
// Start final reporting workflow
|
|
494
485
|
if (output.isValid) {
|
|
495
486
|
await ReportingWorkflow.start({
|
|
496
|
-
data: output.validatedData
|
|
497
|
-
})
|
|
487
|
+
data: output.validatedData,
|
|
488
|
+
})
|
|
498
489
|
}
|
|
499
|
-
break
|
|
490
|
+
break
|
|
500
491
|
}
|
|
501
|
-
}
|
|
502
|
-
})
|
|
492
|
+
},
|
|
493
|
+
})
|
|
503
494
|
```
|
|
504
495
|
|
|
505
496
|
### Error Recovery
|
|
@@ -508,78 +499,87 @@ Handle failed events:
|
|
|
508
499
|
|
|
509
500
|
```typescript
|
|
510
501
|
export default new Trigger({
|
|
511
|
-
name:
|
|
512
|
-
events: [
|
|
502
|
+
name: 'errorRecovery',
|
|
503
|
+
events: ['workflow.failed', 'integration:error'],
|
|
513
504
|
|
|
514
505
|
handler: async ({ event }) => {
|
|
515
|
-
const { error, context, retryCount = 0 } = event.payload
|
|
506
|
+
const { error, context, retryCount = 0 } = event.payload
|
|
516
507
|
|
|
517
508
|
// Log error
|
|
518
509
|
await ErrorLogTable.createRows({
|
|
519
|
-
rows: [
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
510
|
+
rows: [
|
|
511
|
+
{
|
|
512
|
+
type: event.type,
|
|
513
|
+
error: error.message,
|
|
514
|
+
stack: error.stack,
|
|
515
|
+
context,
|
|
516
|
+
timestamp: new Date(),
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
})
|
|
527
520
|
|
|
528
521
|
// Attempt recovery
|
|
529
522
|
if (retryCount < 3) {
|
|
530
523
|
// Retry with backoff
|
|
531
|
-
setTimeout(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
524
|
+
setTimeout(
|
|
525
|
+
async () => {
|
|
526
|
+
await RetryWorkflow.start({
|
|
527
|
+
originalEvent: event,
|
|
528
|
+
retryCount: retryCount + 1,
|
|
529
|
+
})
|
|
530
|
+
},
|
|
531
|
+
Math.pow(2, retryCount) * 1000
|
|
532
|
+
)
|
|
537
533
|
} else {
|
|
538
534
|
// Send alert after max retries
|
|
539
535
|
await actions.sendAlert({
|
|
540
|
-
severity:
|
|
541
|
-
title:
|
|
542
|
-
details: { event, error }
|
|
543
|
-
})
|
|
536
|
+
severity: 'critical',
|
|
537
|
+
title: 'Max retries exceeded',
|
|
538
|
+
details: { event, error },
|
|
539
|
+
})
|
|
544
540
|
}
|
|
545
|
-
}
|
|
546
|
-
})
|
|
541
|
+
},
|
|
542
|
+
})
|
|
547
543
|
```
|
|
548
544
|
|
|
549
545
|
## Best Practices
|
|
550
546
|
|
|
551
547
|
### 1. Use Descriptive Names
|
|
548
|
+
|
|
552
549
|
```typescript
|
|
553
550
|
// ✅ Good
|
|
554
551
|
export default new Trigger({
|
|
555
|
-
name:
|
|
556
|
-
description:
|
|
557
|
-
})
|
|
552
|
+
name: 'linearIssueSync',
|
|
553
|
+
description: 'Syncs Linear issues to internal tracking',
|
|
554
|
+
})
|
|
558
555
|
|
|
559
556
|
// ❌ Bad
|
|
560
557
|
export default new Trigger({
|
|
561
|
-
name:
|
|
562
|
-
description:
|
|
563
|
-
})
|
|
558
|
+
name: 'trigger1',
|
|
559
|
+
description: 'Does stuff',
|
|
560
|
+
})
|
|
564
561
|
```
|
|
565
562
|
|
|
566
563
|
### 2. Handle Errors Gracefully
|
|
564
|
+
|
|
567
565
|
```typescript
|
|
568
566
|
handler: async ({ event }) => {
|
|
569
567
|
try {
|
|
570
|
-
await processEvent(event)
|
|
568
|
+
await processEvent(event)
|
|
571
569
|
} catch (error) {
|
|
572
|
-
console.error(`Failed to process ${event.type}:`, error)
|
|
570
|
+
console.error(`Failed to process ${event.type}:`, error)
|
|
573
571
|
|
|
574
572
|
// Store error for debugging
|
|
575
573
|
await ErrorTable.createRows({
|
|
576
|
-
rows: [
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
574
|
+
rows: [
|
|
575
|
+
{
|
|
576
|
+
trigger: 'myTrigger',
|
|
577
|
+
event: event.type,
|
|
578
|
+
error: error.message,
|
|
579
|
+
timestamp: new Date(),
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
})
|
|
583
583
|
|
|
584
584
|
// Don't re-throw unless you want to retry
|
|
585
585
|
}
|
|
@@ -587,12 +587,13 @@ handler: async ({ event }) => {
|
|
|
587
587
|
```
|
|
588
588
|
|
|
589
589
|
### 3. Avoid Heavy Processing
|
|
590
|
+
|
|
590
591
|
```typescript
|
|
591
592
|
handler: async ({ event }) => {
|
|
592
593
|
// ✅ Good: Start async workflow
|
|
593
594
|
await HeavyProcessingWorkflow.start({
|
|
594
|
-
eventData: event.payload
|
|
595
|
-
})
|
|
595
|
+
eventData: event.payload,
|
|
596
|
+
})
|
|
596
597
|
|
|
597
598
|
// ❌ Bad: Long-running synchronous processing
|
|
598
599
|
// const result = await performHeavyComputation(event.payload);
|
|
@@ -600,34 +601,33 @@ handler: async ({ event }) => {
|
|
|
600
601
|
```
|
|
601
602
|
|
|
602
603
|
### 4. Use Event Patterns
|
|
604
|
+
|
|
603
605
|
```typescript
|
|
604
606
|
// Group related events from multiple integrations
|
|
605
607
|
export default new Trigger({
|
|
606
|
-
name:
|
|
607
|
-
events: [
|
|
608
|
-
"linear:issueCreated",
|
|
609
|
-
"linear:issueUpdated",
|
|
610
|
-
"github:issueOpened",
|
|
611
|
-
"github:pullRequestOpened"
|
|
612
|
-
],
|
|
608
|
+
name: 'issueTracker',
|
|
609
|
+
events: ['linear:issueCreated', 'linear:issueUpdated', 'github:issueOpened', 'github:pullRequestOpened'],
|
|
613
610
|
|
|
614
611
|
handler: async ({ event }) => {
|
|
615
|
-
const [integration, action] = event.type.split(
|
|
612
|
+
const [integration, action] = event.type.split(':')
|
|
616
613
|
|
|
617
614
|
// Common processing for all issue-related events
|
|
618
615
|
await IssueTrackingTable.createRows({
|
|
619
|
-
rows: [
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
})
|
|
616
|
+
rows: [
|
|
617
|
+
{
|
|
618
|
+
source: integration,
|
|
619
|
+
eventType: action,
|
|
620
|
+
data: event.payload,
|
|
621
|
+
timestamp: new Date(),
|
|
622
|
+
},
|
|
623
|
+
],
|
|
624
|
+
})
|
|
625
|
+
},
|
|
626
|
+
})
|
|
628
627
|
```
|
|
629
628
|
|
|
630
629
|
### 5. Document Event Payloads
|
|
630
|
+
|
|
631
631
|
```typescript
|
|
632
632
|
/**
|
|
633
633
|
* Handles user creation events
|
|
@@ -642,78 +642,73 @@ export default new Trigger({
|
|
|
642
642
|
* }
|
|
643
643
|
*/
|
|
644
644
|
export default new Trigger({
|
|
645
|
-
name:
|
|
646
|
-
events: [
|
|
645
|
+
name: 'userCreatedHandler',
|
|
646
|
+
events: ['user.created'],
|
|
647
647
|
|
|
648
648
|
handler: async ({ event }) => {
|
|
649
|
-
const { userId, email, name, source } = event.payload
|
|
649
|
+
const { userId, email, name, source } = event.payload
|
|
650
650
|
// Process with confidence in payload structure
|
|
651
|
-
}
|
|
652
|
-
})
|
|
651
|
+
},
|
|
652
|
+
})
|
|
653
653
|
```
|
|
654
654
|
|
|
655
655
|
## Common Patterns
|
|
656
656
|
|
|
657
657
|
### Audit Trail
|
|
658
|
+
|
|
658
659
|
```typescript
|
|
659
660
|
export default new Trigger({
|
|
660
|
-
name:
|
|
661
|
-
events: [
|
|
662
|
-
"user.created",
|
|
663
|
-
"user.updated",
|
|
664
|
-
"user.deleted",
|
|
665
|
-
"conversation.started"
|
|
666
|
-
],
|
|
661
|
+
name: 'auditTrail',
|
|
662
|
+
events: ['user.created', 'user.updated', 'user.deleted', 'conversation.started'],
|
|
667
663
|
|
|
668
664
|
handler: async ({ event }) => {
|
|
669
665
|
await AuditTable.createRows({
|
|
670
|
-
rows: [
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
})
|
|
666
|
+
rows: [
|
|
667
|
+
{
|
|
668
|
+
eventType: event.type,
|
|
669
|
+
payload: event.payload,
|
|
670
|
+
userId: event.payload.userId || event.userId,
|
|
671
|
+
timestamp: new Date(),
|
|
672
|
+
},
|
|
673
|
+
],
|
|
674
|
+
})
|
|
675
|
+
},
|
|
676
|
+
})
|
|
679
677
|
```
|
|
680
678
|
|
|
681
679
|
### Notification System
|
|
680
|
+
|
|
682
681
|
```typescript
|
|
683
682
|
export default new Trigger({
|
|
684
|
-
name:
|
|
685
|
-
events: [
|
|
686
|
-
"workflow.failed",
|
|
687
|
-
"user.deleted",
|
|
688
|
-
"integration:error"
|
|
689
|
-
],
|
|
683
|
+
name: 'notifications',
|
|
684
|
+
events: ['workflow.failed', 'user.deleted', 'integration:error'],
|
|
690
685
|
|
|
691
686
|
handler: async ({ event }) => {
|
|
692
687
|
const notifications = {
|
|
693
|
-
|
|
694
|
-
channel:
|
|
695
|
-
priority:
|
|
696
|
-
template:
|
|
688
|
+
'workflow.failed': {
|
|
689
|
+
channel: 'slack',
|
|
690
|
+
priority: 'high',
|
|
691
|
+
template: 'workflow-failure',
|
|
697
692
|
},
|
|
698
|
-
|
|
699
|
-
channel:
|
|
700
|
-
priority:
|
|
701
|
-
template:
|
|
693
|
+
'user.deleted': {
|
|
694
|
+
channel: 'email',
|
|
695
|
+
priority: 'normal',
|
|
696
|
+
template: 'user-deleted',
|
|
702
697
|
},
|
|
703
|
-
|
|
704
|
-
channel:
|
|
705
|
-
priority:
|
|
706
|
-
template:
|
|
707
|
-
}
|
|
708
|
-
}
|
|
698
|
+
'integration:error': {
|
|
699
|
+
channel: 'pagerduty',
|
|
700
|
+
priority: 'critical',
|
|
701
|
+
template: 'integration-error',
|
|
702
|
+
},
|
|
703
|
+
}
|
|
709
704
|
|
|
710
|
-
const config = notifications[event.type]
|
|
705
|
+
const config = notifications[event.type]
|
|
711
706
|
if (config) {
|
|
712
707
|
await actions.sendNotification({
|
|
713
708
|
...config,
|
|
714
|
-
data: event.payload
|
|
715
|
-
})
|
|
709
|
+
data: event.payload,
|
|
710
|
+
})
|
|
716
711
|
}
|
|
717
|
-
}
|
|
718
|
-
})
|
|
712
|
+
},
|
|
713
|
+
})
|
|
719
714
|
```
|