@botpress/sdk 4.15.11 → 4.15.12

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.
@@ -1,4 +1,4 @@
1
- import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
1
+ import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlersMap as BotActionHandlersMap, BotHandlers } from '../bot';
2
2
  import * as utils from '../utils';
3
3
  import { BasePlugin, PluginRuntimeProps } from './common';
4
4
  import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap } from './server/types';
@@ -19,7 +19,7 @@ export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugi
19
19
  initialize(props: PluginRuntimeProps<TPlugin>): this;
20
20
  private get _runtime();
21
21
  private _getTools;
22
- get actionHandlers(): BotActionHandlers<TPlugin>;
22
+ get actionHandlers(): BotActionHandlersMap<TPlugin>;
23
23
  get messageHandlers(): BotMessageHandlersMap<TPlugin>;
24
24
  get eventHandlers(): BotEventHandlersMap<TPlugin>;
25
25
  get stateExpiredHandlers(): BotStateExpiredHandlersMap<TPlugin>;
@@ -111,20 +111,23 @@ export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
111
111
  ctx: bot.BotContext;
112
112
  logger: bot.BotLogger;
113
113
  client: PluginClient<TPlugin>;
114
+ };
115
+ export type InjectedHandlerProps<TPlugin extends common.BasePlugin> = {
114
116
  configuration: common.PluginConfiguration<TPlugin>;
115
117
  interfaces: common.PluginInterfaceExtensions<TPlugin>;
118
+ alias?: string;
116
119
  actions: actionProxy.ActionProxy<TPlugin>;
117
120
  states: stateProxy.StateProxy<TPlugin>;
118
121
  events: eventProxy.EventProxy<TPlugin>;
119
- alias?: string;
120
122
  /**
121
123
  * # EXPERIMENTAL
122
124
  * This API is experimental and may change in the future.
123
125
  */
124
126
  workflows: workflowProxy.WorkflowProxy<TPlugin>;
125
127
  };
128
+ export type ExtendedHandlerProps<TPlugin extends common.BasePlugin> = CommonHandlerProps<TPlugin> & InjectedHandlerProps<TPlugin>;
126
129
  export type MessagePayloads<TPlugin extends common.BasePlugin> = {
127
- [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: CommonHandlerProps<TPlugin> & {
130
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
128
131
  message: IncomingMessages<TPlugin>[TMessageName];
129
132
  user: client.User;
130
133
  conversation: client.Conversation;
@@ -135,7 +138,7 @@ export type MessageHandlers<TPlugin extends common.BasePlugin> = {
135
138
  [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args: MessagePayloads<TPlugin>[TMessageName]) => Promise<void>;
136
139
  };
137
140
  export type EventPayloads<TPlugin extends common.BasePlugin> = {
138
- [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: CommonHandlerProps<TPlugin> & {
141
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
139
142
  event: IncomingEvents<TPlugin>[TEventName];
140
143
  };
141
144
  };
@@ -143,7 +146,7 @@ export type EventHandlers<TPlugin extends common.BasePlugin> = {
143
146
  [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: (args: EventPayloads<TPlugin>[TEventName]) => Promise<void>;
144
147
  };
145
148
  export type StateExpiredPayloads<TPlugin extends common.BasePlugin> = {
146
- [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: CommonHandlerProps<TPlugin> & {
149
+ [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
147
150
  state: IncomingStates<TPlugin>[TSateName];
148
151
  };
149
152
  };
@@ -151,7 +154,7 @@ export type StateExpiredHandlers<TPlugin extends common.BasePlugin> = {
151
154
  [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: (args: StateExpiredPayloads<TPlugin>[TSateName]) => Promise<void>;
152
155
  };
153
156
  export type ActionHandlerPayloads<TPlugin extends common.BasePlugin> = {
154
- [TActionName in utils.StringKeys<TPlugin['actions']>]: CommonHandlerProps<TPlugin> & {
157
+ [TActionName in utils.StringKeys<TPlugin['actions']>]: ExtendedHandlerProps<TPlugin> & {
155
158
  type?: TActionName;
156
159
  input: TPlugin['actions'][TActionName]['input'];
157
160
  };
@@ -160,7 +163,7 @@ export type ActionHandlers<TPlugin extends common.BasePlugin> = {
160
163
  [TActionName in utils.StringKeys<TPlugin['actions']>]: (props: ActionHandlerPayloads<TPlugin>[TActionName]) => Promise<TPlugin['actions'][TActionName]['output']>;
161
164
  };
162
165
  export type WorkflowPayloads<TPlugin extends common.BasePlugin> = {
163
- [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: CommonHandlerProps<TPlugin> & {
166
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: ExtendedHandlerProps<TPlugin> & {
164
167
  conversation?: client.Conversation;
165
168
  user?: client.User;
166
169
  event: bot.WorkflowUpdateEvent;
@@ -258,7 +261,7 @@ export type HookData<TPlugin extends common.BasePlugin> = {
258
261
  };
259
262
  export type HookInputs<TPlugin extends common.BasePlugin> = {
260
263
  [THookType in utils.StringKeys<HookData<TPlugin>>]: {
261
- [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & {
264
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: ExtendedHandlerProps<TPlugin> & {
262
265
  data: HookData<TPlugin>[THookType][THookDataName];
263
266
  };
264
267
  };
@@ -277,24 +280,29 @@ export type HookHandlers<TPlugin extends common.BasePlugin> = {
277
280
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputs<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
278
281
  };
279
282
  };
283
+ export type ActionHandlersMap<TPlugin extends common.BasePlugin> = {
284
+ [TActionName in utils.StringKeys<TPlugin['actions']>]?: (props: Omit<Parameters<ActionHandlers<TPlugin>[TActionName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<Awaited<ReturnType<ActionHandlers<TPlugin>[TActionName]>>>;
285
+ };
280
286
  export type MessageHandlersMap<TPlugin extends common.BasePlugin> = {
281
- [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlers<TPlugin>[TMessageName][];
287
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: ((props: Omit<Parameters<MessageHandlers<TPlugin>[TMessageName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
282
288
  };
283
289
  export type EventHandlersMap<TPlugin extends common.BasePlugin> = {
284
- [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlers<TPlugin>[TEventName][];
290
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: ((props: Omit<Parameters<EventHandlers<TPlugin>[TEventName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
285
291
  };
286
292
  export type StateExpiredHandlersMap<TPlugin extends common.BasePlugin> = {
287
- [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
293
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: ((props: Omit<Parameters<StateExpiredHandlers<TPlugin>[TStateName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
288
294
  };
289
295
  export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
290
296
  [THookType in utils.StringKeys<HookData<TPlugin>>]: {
291
- [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
297
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: ((props: Omit<Parameters<HookHandlers<TPlugin>[THookType][THookDataName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<Awaited<ReturnType<HookHandlers<TPlugin>[THookType][THookDataName]>>>)[];
292
298
  };
293
299
  };
294
300
  export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
295
301
  [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
296
302
  [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
297
- handler: WorkflowHandlers<TPlugin>[TWorkflowName];
303
+ handler: (props: Omit<Parameters<WorkflowHandlers<TPlugin>[TWorkflowName]>[0], keyof InjectedHandlerProps<TPlugin> | 'workflow'> & {
304
+ workflow: client.Workflow;
305
+ }) => Promise<client.Workflow>;
298
306
  order: number;
299
307
  }[];
300
308
  };
@@ -333,12 +341,39 @@ export type OrderedWorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
333
341
  }[];
334
342
  };
335
343
  };
344
+ /** Plugin handlers without InjectedHandlerProps */
336
345
  export type PluginHandlers<TPlugin extends common.BasePlugin> = {
337
- actionHandlers: ActionHandlers<TPlugin>;
346
+ actionHandlers: ActionHandlersMap<TPlugin>;
338
347
  messageHandlers: MessageHandlersMap<TPlugin>;
339
348
  eventHandlers: EventHandlersMap<TPlugin>;
340
349
  stateExpiredHandlers: StateExpiredHandlersMap<TPlugin>;
341
350
  hookHandlers: HookHandlersMap<TPlugin>;
342
351
  workflowHandlers: WorkflowHandlersMap<TPlugin>;
343
352
  };
353
+ /** identical to PluginHandlers, but contains the injected properties */
354
+ export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
355
+ actionHandlers: ActionHandlers<TPlugin>;
356
+ messageHandlers: {
357
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlers<TPlugin>[TMessageName][];
358
+ };
359
+ eventHandlers: {
360
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlers<TPlugin>[TEventName][];
361
+ };
362
+ stateExpiredHandlers: {
363
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
364
+ };
365
+ hookHandlers: {
366
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
367
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
368
+ };
369
+ };
370
+ workflowHandlers: {
371
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
372
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
373
+ handler: WorkflowHandlers<TPlugin>[TWorkflowName];
374
+ order: number;
375
+ }[];
376
+ };
377
+ };
378
+ };
344
379
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "4.15.11",
3
+ "version": "4.15.12",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",