@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.1

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.
Files changed (199) hide show
  1. package/dist/agent-init/agent-project-generator.d.ts +5 -1
  2. package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
  3. package/dist/agent-project/agent-project.d.ts +3 -3
  4. package/dist/agent-project/agent-project.d.ts.map +1 -1
  5. package/dist/agent-project/agent-resolver.d.ts.map +1 -1
  6. package/dist/agent-project/config-writer.d.ts +1 -1
  7. package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
  8. package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
  9. package/dist/agent-project/types.d.ts +9 -4
  10. package/dist/agent-project/types.d.ts.map +1 -1
  11. package/dist/agent0/capabilities/commands/adk-build.md +6 -5
  12. package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
  13. package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
  14. package/dist/agent0/capabilities/commands/adk-document.md +10 -2
  15. package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
  16. package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
  17. package/dist/agent0/capabilities/commands/adk-init.md +2 -2
  18. package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
  19. package/dist/agent0/capabilities/commands/adk-test.md +3 -3
  20. package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
  21. package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
  22. package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
  23. package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
  24. package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
  25. package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
  26. package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
  27. package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
  28. package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
  29. package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
  30. package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
  31. package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
  32. package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
  33. package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
  34. package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
  35. package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
  36. package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
  37. package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
  38. package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
  39. package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
  40. package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
  41. package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
  42. package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
  43. package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
  44. package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
  45. package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
  46. package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
  47. package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
  48. package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
  49. package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
  50. package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
  51. package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
  52. package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
  53. package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
  54. package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
  55. package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
  56. package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
  57. package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
  58. package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
  59. package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
  60. package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
  61. package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
  62. package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
  63. package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
  64. package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
  65. package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
  66. package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
  67. package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
  68. package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
  69. package/dist/agent0/index.js +41 -19
  70. package/dist/agent0/index.js.map +7 -7
  71. package/dist/agent0/runtime/client.d.ts +2 -0
  72. package/dist/agent0/runtime/client.d.ts.map +1 -1
  73. package/dist/agent0/runtime/engine.d.ts +2 -1
  74. package/dist/agent0/runtime/engine.d.ts.map +1 -1
  75. package/dist/agent0/runtime/process.d.ts +1 -0
  76. package/dist/agent0/runtime/process.d.ts.map +1 -1
  77. package/dist/assets/manager.d.ts +3 -0
  78. package/dist/assets/manager.d.ts.map +1 -1
  79. package/dist/auth/credentials.d.ts +1 -1
  80. package/dist/bot-generator/generator.d.ts +22 -0
  81. package/dist/bot-generator/generator.d.ts.map +1 -1
  82. package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
  83. package/dist/commands/base-command.d.ts +1 -0
  84. package/dist/commands/base-command.d.ts.map +1 -1
  85. package/dist/commands/bp-dev-command.d.ts +1 -1
  86. package/dist/commands/bp-dev-command.d.ts.map +1 -1
  87. package/dist/commands/bp-dev-stderr.d.ts +9 -0
  88. package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
  89. package/dist/commands/index.d.ts +1 -0
  90. package/dist/commands/index.d.ts.map +1 -1
  91. package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
  92. package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
  93. package/dist/dependencies/catalog/client-factory.d.ts +33 -0
  94. package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
  95. package/dist/dependencies/catalog/integration-source.d.ts +34 -0
  96. package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
  97. package/dist/dependencies/catalog/interface-source.d.ts +23 -0
  98. package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
  99. package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
  100. package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
  101. package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
  102. package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
  103. package/dist/dependencies/dependency-manager.d.ts +31 -16
  104. package/dist/dependencies/dependency-manager.d.ts.map +1 -1
  105. package/dist/dependencies/errors.d.ts +2 -2
  106. package/dist/dependencies/errors.d.ts.map +1 -1
  107. package/dist/dependencies/index.d.ts +5 -4
  108. package/dist/dependencies/index.d.ts.map +1 -1
  109. package/dist/dependencies/index.js +2089 -1670
  110. package/dist/dependencies/index.js.map +37 -30
  111. package/dist/dependencies/legacy-lock-file.d.ts +15 -0
  112. package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
  113. package/dist/dependencies/migration.d.ts +19 -0
  114. package/dist/dependencies/migration.d.ts.map +1 -1
  115. package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
  116. package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
  117. package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
  118. package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
  119. package/dist/dependencies/snapshot-store.d.ts +59 -0
  120. package/dist/dependencies/snapshot-store.d.ts.map +1 -0
  121. package/dist/dependencies/status-resolver.d.ts +36 -0
  122. package/dist/dependencies/status-resolver.d.ts.map +1 -0
  123. package/dist/dependencies/status.d.ts +214 -0
  124. package/dist/dependencies/status.d.ts.map +1 -0
  125. package/dist/dependencies/types.d.ts +380 -29
  126. package/dist/dependencies/types.d.ts.map +1 -1
  127. package/dist/file-watcher/watcher.d.ts +21 -5
  128. package/dist/file-watcher/watcher.d.ts.map +1 -1
  129. package/dist/generators/action-types.d.ts.map +1 -1
  130. package/dist/generators/client-wrapper.d.ts.map +1 -1
  131. package/dist/index.d.ts +4 -5
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +3134 -2226
  134. package/dist/index.js.map +55 -48
  135. package/dist/integrations/config-utils.d.ts +11 -7
  136. package/dist/integrations/config-utils.d.ts.map +1 -1
  137. package/dist/integrations/hub-cache.d.ts +0 -58
  138. package/dist/integrations/hub-cache.d.ts.map +1 -1
  139. package/dist/integrations/index.d.ts +1 -3
  140. package/dist/integrations/index.d.ts.map +1 -1
  141. package/dist/integrations/manager.d.ts +19 -53
  142. package/dist/integrations/manager.d.ts.map +1 -1
  143. package/dist/interfaces/enhanced-cache.d.ts +7 -7
  144. package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
  145. package/dist/interfaces/manager.d.ts +11 -17
  146. package/dist/interfaces/manager.d.ts.map +1 -1
  147. package/dist/knowledge/manager.d.ts +3 -0
  148. package/dist/knowledge/manager.d.ts.map +1 -1
  149. package/dist/plugins/index.d.ts +0 -1
  150. package/dist/plugins/index.d.ts.map +1 -1
  151. package/dist/plugins/manager.d.ts +16 -48
  152. package/dist/plugins/manager.d.ts.map +1 -1
  153. package/dist/preflight/checker.d.ts +6 -1
  154. package/dist/preflight/checker.d.ts.map +1 -1
  155. package/dist/preflight/dependency-gate.d.ts +37 -0
  156. package/dist/preflight/dependency-gate.d.ts.map +1 -0
  157. package/dist/preflight/index.d.ts +2 -1
  158. package/dist/preflight/index.d.ts.map +1 -1
  159. package/dist/preflight/types.d.ts +18 -0
  160. package/dist/preflight/types.d.ts.map +1 -1
  161. package/dist/runner/script-runner.d.ts.map +1 -1
  162. package/dist/tables/table-manager.d.ts +3 -0
  163. package/dist/tables/table-manager.d.ts.map +1 -1
  164. package/dist/templates/README.md +23 -13
  165. package/dist/templates/blank/agent.config.ts +3 -3
  166. package/dist/templates/blank/src/triggers/index.ts +1 -1
  167. package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
  168. package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
  169. package/dist/templates/crm-enrichment/README.md +3 -3
  170. package/dist/templates/crm-enrichment/agent.config.ts +2 -2
  171. package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
  172. package/dist/templates/hello-world/agent.config.ts +3 -3
  173. package/dist/templates/hello-world/src/triggers/index.ts +1 -1
  174. package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
  175. package/dist/templates/template.config.json +3 -3
  176. package/dist/utils/ids.d.ts +10 -0
  177. package/dist/utils/ids.d.ts.map +1 -1
  178. package/dist/workspace/workspace-cache.d.ts +2 -1
  179. package/dist/workspace/workspace-cache.d.ts.map +1 -1
  180. package/package.json +3 -3
  181. package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
  182. package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
  183. package/dist/dependencies/lock-file.d.ts +0 -15
  184. package/dist/dependencies/lock-file.d.ts.map +0 -1
  185. package/dist/integrations/enhanced-cache.d.ts +0 -53
  186. package/dist/integrations/enhanced-cache.d.ts.map +0 -1
  187. package/dist/plugins/enhanced-cache.d.ts +0 -53
  188. package/dist/plugins/enhanced-cache.d.ts.map +0 -1
  189. package/dist/templates/blank/package.json +0 -17
  190. package/dist/templates/blank/tsconfig.json +0 -25
  191. package/dist/templates/botpress-desk/package.json +0 -17
  192. package/dist/templates/crm-enrichment/package.json +0 -18
  193. package/dist/templates/crm-enrichment/tsconfig.json +0 -25
  194. package/dist/templates/hello-world/package.json +0 -18
  195. package/dist/templates/hello-world/tsconfig.json +0 -25
  196. package/dist/templates/knowledge-assistant/package.json +0 -18
  197. package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
  198. package/dist/templates/slack-triage/package.json +0 -18
  199. 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 "@botpress/runtime";
27
+ import { Trigger } from '@botpress/runtime'
26
28
 
27
29
  export default new Trigger({
28
- name: "myTrigger",
29
- description: "Handles user creation events",
30
- events: ["user.created"], // Events to subscribe to
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); // "user.created"
34
- console.log(event.payload); // Event data
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: "userEvents",
49
- description: "Handles all user-related events",
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 "user.created":
59
- await handleUserCreated(event.payload);
60
- break;
61
- case "user.updated":
62
- await handleUserUpdated(event.payload);
63
- break;
64
- case "user.deleted":
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
- "user.created" // New user created
81
- "user.updated" // User information updated
82
- "user.deleted" // User deleted
78
+ 'user.created' // New user created
79
+ 'user.updated' // User information updated
80
+ 'user.deleted' // User deleted
83
81
 
84
82
  // Conversation events
85
- "conversation.started" // New conversation started
86
- "conversation.ended" // Conversation ended
87
- "message.created" // New message in conversation
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
- "workflow.started" // Workflow instance started
91
- "workflow.completed" // Workflow completed successfully
92
- "workflow.failed" // Workflow failed
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
- "bot.started" // Bot started
96
- "bot.stopped" // Bot stopped
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
- "intercom:conversationEvent" // Fires on create/update/delete
108
- "intercom:contactEvent" // Contact created/updated
109
- "intercom:adminEvent" // Admin changes
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
- "slack:reactionAdded"
113
- "slack:reactionRemoved"
114
- "slack:memberJoinedChannel"
115
- "slack:memberJoinedWorkspace"
116
- "slack:memberLeftChannel"
117
- "slack:workflowWebhook"
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
- "linear:issueCreated"
121
- "linear:issueUpdated"
122
- "linear:issueDeleted"
118
+ 'linear:issueCreated'
119
+ 'linear:issueUpdated'
120
+ 'linear:issueDeleted'
123
121
 
124
122
  // GitHub events (verified with adk info github --events)
125
- "github:issueOpened"
126
- "github:pullRequestOpened"
127
- "github:pullRequestMerged"
128
- "github:pullRequestReviewSubmitted"
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
- "webchat:conversationStarted"
132
- "webchat:trigger"
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 "@botpress/runtime";
156
- import { OnboardingWorkflow } from "../workflows/onboarding";
154
+ import { Trigger } from '@botpress/runtime'
155
+ import { OnboardingWorkflow } from '../workflows/onboarding'
157
156
 
158
157
  export default new Trigger({
159
- name: "userOnboarding",
160
- description: "Start onboarding when user is created",
161
- events: ["user.created"],
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 "@botpress/runtime";
185
- import { EventLogTable } from "../tables/EventLog";
183
+ import { Trigger } from '@botpress/runtime'
184
+ import { EventLogTable } from '../tables/EventLog'
186
185
 
187
186
  export default new Trigger({
188
- name: "eventLogger",
189
- description: "Log all events to database",
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
- type: event.type,
202
- payload: event.payload,
203
- timestamp: new Date(),
204
- metadata: {
205
- source: event.source || "bot",
206
- version: event.version || "1.0"
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 "@botpress/runtime";
220
- import { actions } from "@botpress/runtime";
215
+ import { Trigger } from '@botpress/runtime'
216
+ import { actions } from '@botpress/runtime'
221
217
 
222
218
  export default new Trigger({
223
- name: "notificationSender",
224
- description: "Send email notifications for important events",
225
- events: ["workflow.failed", "user.deleted"],
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: "admin@example.com",
232
- from: "bot@example.com",
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 "@botpress/runtime";
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: "onIntercomUpdate",
259
- description:
260
- "Updates the Intercom tables in realtime when conversations are created or messages are sent",
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 === "deleted") {
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
- `Failed to handle ${eventType} event for conversation ${conversationId}:`,
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 "@botpress/runtime";
295
- import { LinearIssueTable } from "../tables/LinearIssues";
282
+ import { Trigger } from '@botpress/runtime'
283
+ import { LinearIssueTable } from '../tables/LinearIssues'
296
284
 
297
285
  export default new Trigger({
298
- name: "onLinearIssueUpdate",
299
- description: "Updates the Linear Issue Table when issues change",
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 === "linear:issueDeleted") {
291
+ if (event.type === 'linear:issueDeleted') {
308
292
  await LinearIssueTable.deleteRows({
309
- linearId: event.payload.id
310
- });
311
- } else if (event.type === "linear:issueCreated") {
293
+ linearId: event.payload.id,
294
+ })
295
+ } else if (event.type === 'linear:issueCreated') {
312
296
  await LinearIssueTable.createRows({
313
- rows: [{
314
- linearId: event.payload.linearIds?.issueId,
315
- content: `# ${event.payload.title}\n\n${event.payload.description}`,
316
- issue: event.payload,
317
- linearUpdatedAt: event.payload.updatedAt
318
- }]
319
- });
320
- } else if (event.type === "linear:issueUpdated") {
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
- linearId: event.payload.linearIds?.issueId,
324
- content: `# ${event.payload.title}\n\n${event.payload.description}`,
325
- issue: event.payload,
326
- linearUpdatedAt: event.payload.updatedAt
327
- }],
328
- keyColumn: "linearId"
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 "@botpress/runtime";
339
- import { SlackActivityTable } from "../tables/SlackActivity";
326
+ import { Trigger } from '@botpress/runtime'
327
+ import { SlackActivityTable } from '../tables/SlackActivity'
340
328
 
341
329
  export default new Trigger({
342
- name: "slackActivityMonitor",
343
- description: "Monitor Slack reactions and member activity",
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 === "slack:reactionAdded") {
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 === "fire" || reaction === "star" || reaction === "eyes") {
339
+ if (reaction === 'fire' || reaction === 'star' || reaction === 'eyes') {
355
340
  await SlackActivityTable.createRows({
356
- rows: [{
357
- type: "reaction",
358
- reaction: reaction,
359
- user: user,
360
- messageId: item.ts,
361
- channelId: item.channel,
362
- timestamp: new Date()
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 === "slack:memberJoinedChannel") {
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
- type: "member_join",
375
- user: user,
376
- channelId: channel,
377
- timestamp: new Date()
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: "conditionalProcessor",
394
- events: ["user.created"],
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("@company.com")) {
401
- console.log("Skipping external user");
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 === "api") {
407
- await handleApiUser(event.payload);
408
- } else if (source === "signup") {
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 "@botpress/runtime";
426
- import { EventBatchTable } from "../tables/EventBatch";
414
+ import { Trigger } from '@botpress/runtime'
415
+ import { EventBatchTable } from '../tables/EventBatch'
427
416
 
428
417
  export default new Trigger({
429
- name: "eventAggregator",
430
- events: ["metrics.recorded"],
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
- type: event.type,
437
- data: event.payload,
438
- processed: false,
439
- timestamp: new Date()
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: "workflowOrchestrator",
471
- events: ["workflow.completed"],
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 "dataCollection":
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 "processing":
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 "validation":
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: "errorRecovery",
512
- events: ["workflow.failed", "integration:error"],
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
- type: event.type,
521
- error: error.message,
522
- stack: error.stack,
523
- context,
524
- timestamp: new Date()
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(async () => {
532
- await RetryWorkflow.start({
533
- originalEvent: event,
534
- retryCount: retryCount + 1
535
- });
536
- }, Math.pow(2, retryCount) * 1000);
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: "critical",
541
- title: "Max retries exceeded",
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: "linearIssueSync",
556
- description: "Syncs Linear issues to internal tracking"
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: "trigger1",
562
- description: "Does stuff"
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
- trigger: "myTrigger",
578
- event: event.type,
579
- error: error.message,
580
- timestamp: new Date()
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: "issueTracker",
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
- source: integration,
621
- eventType: action,
622
- data: event.payload,
623
- timestamp: new Date()
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: "userCreatedHandler",
646
- events: ["user.created"],
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: "auditTrail",
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
- eventType: event.type,
672
- payload: event.payload,
673
- userId: event.payload.userId || event.userId,
674
- timestamp: new Date()
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: "notifications",
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
- "workflow.failed": {
694
- channel: "slack",
695
- priority: "high",
696
- template: "workflow-failure"
688
+ 'workflow.failed': {
689
+ channel: 'slack',
690
+ priority: 'high',
691
+ template: 'workflow-failure',
697
692
  },
698
- "user.deleted": {
699
- channel: "email",
700
- priority: "normal",
701
- template: "user-deleted"
693
+ 'user.deleted': {
694
+ channel: 'email',
695
+ priority: 'normal',
696
+ template: 'user-deleted',
702
697
  },
703
- "integration:error": {
704
- channel: "pagerduty",
705
- priority: "critical",
706
- template: "integration-error"
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
  ```