@botpress/sdk 6.7.0 → 6.9.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.
@@ -36,7 +36,7 @@ export type ActionableConversation<TPlugin extends BasePlugin, TChannelName exte
36
36
  delete: () => Promise<void>;
37
37
  update: (props: typeUtils.Merge<Omit<client.ClientInputs['updateConversation'], 'id'>, {
38
38
  tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['conversation']['tags']>>;
39
- }>) => Promise<ActionableConversation<TPlugin>>;
39
+ }>) => Promise<ActionableConversation<TPlugin, TChannelName, TMessage>>;
40
40
  getMessage: (props: {
41
41
  id: string;
42
42
  }) => Promise<messageProxy.ActionableMessage<TPlugin, TMessage>>;
@@ -253,6 +253,16 @@ export type WorkflowHandlers<TPlugin extends common.BasePlugin> = {
253
253
  type BaseHookDefinition = {
254
254
  stoppable?: boolean;
255
255
  data: any;
256
+ /**
257
+ * Per-hook-type extra props injected into the hook handler input. Only set
258
+ * for hooks where the bot runtime already has the relevant context (e.g.
259
+ * incoming message hooks). The `raw` shape uses `client.User`/
260
+ * `client.Conversation`; the `injected` shape replaces them with proxies.
261
+ */
262
+ extraInputs?: {
263
+ raw: object;
264
+ injected: object;
265
+ };
256
266
  };
257
267
  type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
258
268
  /**
@@ -261,8 +271,6 @@ type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> =
261
271
  * - after_register
262
272
  * - before_state_expired
263
273
  * - after_state_expired
264
- * - before_incoming_call_action
265
- * - after_incoming_call_action
266
274
  */
267
275
  export type HookDefinitionType = keyof HookDefinitions<common.BasePlugin>;
268
276
  export type HookDefinitions<TPlugin extends common.BasePlugin> = {
@@ -277,6 +285,16 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
277
285
  data: _IncomingMessages<TPlugin> & {
278
286
  '*': AnyIncomingMessage<TPlugin>;
279
287
  };
288
+ extraInputs: {
289
+ raw: {
290
+ user?: client.User;
291
+ conversation?: client.Conversation;
292
+ };
293
+ injected: {
294
+ user?: userProxy.ActionableUser<TPlugin, string>;
295
+ conversation?: conversationProxy.ActionableConversation<TPlugin>;
296
+ };
297
+ };
280
298
  }>;
281
299
  before_outgoing_message: HookDefinition<{
282
300
  stoppable: false;
@@ -307,6 +325,16 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
307
325
  data: _IncomingMessages<TPlugin> & {
308
326
  '*': AnyIncomingMessage<TPlugin>;
309
327
  };
328
+ extraInputs: {
329
+ raw: {
330
+ user?: client.User;
331
+ conversation?: client.Conversation;
332
+ };
333
+ injected: {
334
+ user?: userProxy.ActionableUser<TPlugin, string>;
335
+ conversation?: conversationProxy.ActionableConversation<TPlugin>;
336
+ };
337
+ };
310
338
  }>;
311
339
  after_outgoing_message: HookDefinition<{
312
340
  stoppable: false;
@@ -328,22 +356,36 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
328
356
  }>;
329
357
  };
330
358
  export type HookData<TPlugin extends common.BasePlugin> = {
331
- [THookType in utils.StringKeys<HookDefinitions<TPlugin>>]: {
359
+ [THookType in HookDefinitionType]: {
332
360
  [THookDataName in utils.StringKeys<HookDefinitions<TPlugin>[THookType]['data']>]: HookDefinitions<TPlugin>[THookType]['data'][THookDataName];
333
361
  };
334
362
  };
363
+ type _HookExtraInputsRaw<TPlugin extends common.BasePlugin> = {
364
+ [THookType in HookDefinitionType]: HookDefinitions<TPlugin>[THookType] extends {
365
+ extraInputs: {
366
+ raw: infer T;
367
+ };
368
+ } ? T : {};
369
+ };
370
+ type _HookExtraInputsInjected<TPlugin extends common.BasePlugin> = {
371
+ [THookType in HookDefinitionType]: HookDefinitions<TPlugin>[THookType] extends {
372
+ extraInputs: {
373
+ injected: infer T;
374
+ };
375
+ } ? T : {};
376
+ };
335
377
  export type HookInputsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
336
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
337
- [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & {
378
+ [THookType in HookDefinitionType]: {
379
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & _HookExtraInputsRaw<TPlugin>[THookType] & {
338
380
  data: HookData<TPlugin>[THookType][THookDataName];
339
381
  };
340
382
  };
341
383
  };
342
384
  export type HookInputs<TPlugin extends common.BasePlugin> = {
343
- [THookType in utils.StringKeys<HookData<TPlugin>>]: _WithInjectedProps<HookInputsWithoutInjectedProps<TPlugin>[THookType], TPlugin>;
385
+ [THookType in HookDefinitionType]: _WithInjectedProps<HookInputsWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
344
386
  };
345
387
  export type HookOutputs<TPlugin extends common.BasePlugin> = {
346
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
388
+ [THookType in HookDefinitionType]: {
347
389
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: {
348
390
  data?: HookData<TPlugin>[THookType][THookDataName];
349
391
  } & (HookDefinitions<TPlugin>[THookType]['stoppable'] extends true ? {
@@ -352,15 +394,21 @@ export type HookOutputs<TPlugin extends common.BasePlugin> = {
352
394
  };
353
395
  };
354
396
  export type HookHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
355
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
397
+ [THookType in HookDefinitionType]: {
356
398
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputsWithoutInjectedProps<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
357
399
  };
358
400
  };
359
401
  export type HookHandlers<TPlugin extends common.BasePlugin> = {
360
- [THookType in utils.StringKeys<HookData<TPlugin>>]: _WithInjectedPropsFn<HookHandlersWithoutInjectedProps<TPlugin>[THookType], TPlugin>;
402
+ [THookType in HookDefinitionType]: _WithInjectedPropsFn<HookHandlersWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
361
403
  };
404
+ export type AnyHookHandler<TPlugin extends common.BasePlugin> = (input: CommonHandlerProps<TPlugin> & {
405
+ data: any;
406
+ } & InjectedHandlerProps<TPlugin>) => Promise<{
407
+ data?: any;
408
+ stop?: boolean;
409
+ } | undefined>;
362
410
  export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
363
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
411
+ [THookType in HookDefinitionType]: {
364
412
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
365
413
  };
366
414
  };
@@ -374,36 +422,36 @@ export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
374
422
  }[];
375
423
  };
376
424
  };
377
- export type OrderedMessageHandlersMap<TPlugin extends common.BasePlugin> = {
378
- [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: {
379
- handler: MessageHandlers<TPlugin>[TMessageName];
425
+ export type OrderedMessageHandlersMap = {
426
+ [TMessageName in string]?: {
427
+ handler: MessageHandlers<common.BasePlugin>[TMessageName];
380
428
  order: number;
381
429
  }[];
382
430
  };
383
- export type OrderedEventHandlersMap<TPlugin extends common.BasePlugin> = {
384
- [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: {
385
- handler: EventHandlers<TPlugin>[TEventName];
431
+ export type OrderedEventHandlersMap = {
432
+ [TEventName in string]?: {
433
+ handler: EventHandlers<common.BasePlugin>['*'];
386
434
  order: number;
387
435
  }[];
388
436
  };
389
- export type OrderedStateExpiredHandlersMap<TPlugin extends common.BasePlugin> = {
390
- [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: {
391
- handler: StateExpiredHandlers<TPlugin>[TStateName];
437
+ export type OrderedStateExpiredHandlersMap = {
438
+ [TStateName in string]?: {
439
+ handler: StateExpiredHandlers<common.BasePlugin>['*'];
392
440
  order: number;
393
441
  }[];
394
442
  };
395
- export type OrderedHookHandlersMap<TPlugin extends common.BasePlugin> = {
396
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
397
- [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: {
398
- handler: HookHandlers<TPlugin>[THookType][THookDataName];
443
+ export type OrderedHookHandlersMap = {
444
+ [THookType in HookDefinitionType]: {
445
+ [THookDataName in string]?: {
446
+ handler: AnyHookHandler<common.BasePlugin>;
399
447
  order: number;
400
448
  }[];
401
449
  };
402
450
  };
403
- export type OrderedWorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
451
+ export type OrderedWorkflowHandlersMap = {
404
452
  [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
405
- [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
406
- handler: WorkflowHandlers<TPlugin>[TWorkflowName];
453
+ [TWorkflowName in string]?: {
454
+ handler: WorkflowHandlers<common.BasePlugin>['*'];
407
455
  order: number;
408
456
  }[];
409
457
  };
@@ -421,7 +469,7 @@ export type PluginHandlers<TPlugin extends common.BasePlugin> = {
421
469
  [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlersWithoutInjectedProps<TPlugin>[TStateName][];
422
470
  };
423
471
  hookHandlers: {
424
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
472
+ [THookType in HookDefinitionType]: {
425
473
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
426
474
  };
427
475
  };
@@ -444,7 +492,7 @@ export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
444
492
  [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
445
493
  };
446
494
  hookHandlers: {
447
- [THookType in utils.StringKeys<HookData<TPlugin>>]: {
495
+ [THookType in HookDefinitionType]: {
448
496
  [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
449
497
  };
450
498
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "6.7.0",
3
+ "version": "6.9.0",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "author": "",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@botpress/client": "1.42.0",
23
+ "@botpress/client": "1.43.0",
24
24
  "browser-or-node": "^2.1.1",
25
25
  "semver": "^7.3.8"
26
26
  },