@botpress/sdk 2.0.3 → 2.0.4

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 (64) hide show
  1. package/package.json +2 -2
  2. package/.turbo/turbo-build.log +0 -12
  3. package/dist/bot/client/index.d.ts +0 -62
  4. package/dist/bot/client/types.d.ts +0 -141
  5. package/dist/bot/client/types.test.d.ts +0 -1
  6. package/dist/bot/definition.d.ts +0 -111
  7. package/dist/bot/implementation.d.ts +0 -39
  8. package/dist/bot/index.d.ts +0 -5
  9. package/dist/bot/merge-bots.d.ts +0 -2
  10. package/dist/bot/server/context.d.ts +0 -2
  11. package/dist/bot/server/index.d.ts +0 -5
  12. package/dist/bot/server/types.d.ts +0 -252
  13. package/dist/bot/server/types.test.d.ts +0 -1
  14. package/dist/bot/types/common.d.ts +0 -50
  15. package/dist/bot/types/common.test.d.ts +0 -1
  16. package/dist/bot/types/generic.d.ts +0 -31
  17. package/dist/bot/types/generic.test.d.ts +0 -1
  18. package/dist/bot/types/index.d.ts +0 -2
  19. package/dist/const.d.ts +0 -8
  20. package/dist/fixtures.d.ts +0 -108
  21. package/dist/index.d.ts +0 -15
  22. package/dist/index.js +0 -2
  23. package/dist/index.js.map +0 -7
  24. package/dist/integration/client/index.d.ts +0 -47
  25. package/dist/integration/client/types.d.ts +0 -177
  26. package/dist/integration/client/types.test.d.ts +0 -1
  27. package/dist/integration/definition/branded-schema.d.ts +0 -21
  28. package/dist/integration/definition/generic.d.ts +0 -9
  29. package/dist/integration/definition/index.d.ts +0 -76
  30. package/dist/integration/definition/types.d.ts +0 -106
  31. package/dist/integration/implementation.d.ts +0 -31
  32. package/dist/integration/index.d.ts +0 -5
  33. package/dist/integration/server/action-metadata.d.ts +0 -9
  34. package/dist/integration/server/context.d.ts +0 -3
  35. package/dist/integration/server/index.d.ts +0 -6
  36. package/dist/integration/server/logger.d.ts +0 -12
  37. package/dist/integration/server/types.d.ts +0 -102
  38. package/dist/integration/types/common.d.ts +0 -11
  39. package/dist/integration/types/generic.d.ts +0 -52
  40. package/dist/integration/types/generic.test.d.ts +0 -1
  41. package/dist/integration/types/index.d.ts +0 -2
  42. package/dist/interface/definition.d.ts +0 -70
  43. package/dist/interface/index.d.ts +0 -1
  44. package/dist/interface/types/generic.d.ts +0 -34
  45. package/dist/interface/types/generic.test.d.ts +0 -1
  46. package/dist/log.d.ts +0 -7
  47. package/dist/message.d.ts +0 -474
  48. package/dist/package.d.ts +0 -58
  49. package/dist/plugin/definition.d.ts +0 -50
  50. package/dist/plugin/implementation.d.ts +0 -39
  51. package/dist/plugin/index.d.ts +0 -3
  52. package/dist/plugin/server/types.d.ts +0 -1
  53. package/dist/plugin/server/types.test.d.ts +0 -1
  54. package/dist/plugin/types/generic.d.ts +0 -30
  55. package/dist/plugin/types/generic.test.d.ts +0 -1
  56. package/dist/retry.d.ts +0 -2
  57. package/dist/schema.d.ts +0 -18
  58. package/dist/serve.d.ts +0 -20
  59. package/dist/utils/array-utils.d.ts +0 -1
  60. package/dist/utils/index.d.ts +0 -3
  61. package/dist/utils/record-utils.d.ts +0 -3
  62. package/dist/utils/type-utils.d.ts +0 -33
  63. package/dist/utils/type-utils.test.d.ts +0 -1
  64. package/dist/zui.d.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "author": "",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@botpress/client": "0.37.1",
17
+ "@botpress/client": "0.38.0",
18
18
  "@bpinternal/zui": "0.12.0"
19
19
  },
20
20
  "devDependencies": {
@@ -1,12 +0,0 @@
1
-
2
- > @botpress/sdk@2.0.3 build /home/runner/work/botpress/botpress/packages/sdk
3
- > pnpm build:type && pnpm build:node
4
-
5
-
6
- > @botpress/sdk@2.0.3 build:type /home/runner/work/botpress/botpress/packages/sdk
7
- > tsc --emitDeclarationOnly --declaration
8
-
9
-
10
- > @botpress/sdk@2.0.3 build:node /home/runner/work/botpress/botpress/packages/sdk
11
- > ts-node -T build.ts
12
-
@@ -1,62 +0,0 @@
1
- import * as client from '@botpress/client';
2
- import * as common from '../types';
3
- import * as types from './types';
4
- export * from './types';
5
- /**
6
- * Just like the regular botpress client, but typed with the bot's properties.
7
- */
8
- export declare class BotSpecificClient<TBot extends common.BaseBot> implements types.ClientOperations<TBot> {
9
- private _client;
10
- private _hooks;
11
- constructor(_client: client.Client, _hooks?: types.ClientHooks);
12
- getConversation: types.GetConversation<TBot>;
13
- listConversations: types.ListConversations<TBot>;
14
- updateConversation: types.UpdateConversation<TBot>;
15
- deleteConversation: types.DeleteConversation<TBot>;
16
- listParticipants: types.ListParticipants<TBot>;
17
- addParticipant: types.AddParticipant<TBot>;
18
- getParticipant: types.GetParticipant<TBot>;
19
- removeParticipant: types.RemoveParticipant<TBot>;
20
- getEvent: types.GetEvent<TBot>;
21
- listEvents: types.ListEvents<TBot>;
22
- createMessage: types.CreateMessage<TBot>;
23
- getOrCreateMessage: types.GetOrCreateMessage<TBot>;
24
- getMessage: types.GetMessage<TBot>;
25
- updateMessage: types.UpdateMessage<TBot>;
26
- listMessages: types.ListMessages<TBot>;
27
- deleteMessage: types.DeleteMessage<TBot>;
28
- getUser: types.GetUser<TBot>;
29
- listUsers: types.ListUsers<TBot>;
30
- updateUser: types.UpdateUser<TBot>;
31
- deleteUser: types.DeleteUser<TBot>;
32
- getState: types.GetState<TBot>;
33
- setState: types.SetState<TBot>;
34
- getOrSetState: types.GetOrSetState<TBot>;
35
- patchState: types.PatchState<TBot>;
36
- callAction: types.CallAction<TBot>;
37
- uploadFile: types.UploadFile<TBot>;
38
- upsertFile: types.UpsertFile<TBot>;
39
- deleteFile: types.DeleteFile<TBot>;
40
- listFiles: types.ListFiles<TBot>;
41
- getFile: types.GetFile<TBot>;
42
- updateFileMetadata: types.UpdateFileMetadata<TBot>;
43
- searchFiles: types.SearchFiles<TBot>;
44
- trackAnalytics: types.TrackAnalytics<TBot>;
45
- /**
46
- * @deprecated Use `callAction` to delegate the conversation creation to an integration.
47
- */
48
- createConversation: types.CreateConversation<TBot>;
49
- /**
50
- * @deprecated Use `callAction` to delegate the conversation creation to an integration.
51
- */
52
- getOrCreateConversation: types.GetOrCreateConversation<TBot>;
53
- /**
54
- * @deprecated Use `callAction` to delegate the user creation to an integration.
55
- */
56
- createUser: types.CreateUser<TBot>;
57
- /**
58
- * @deprecated Use `callAction` to delegate the user creation to an integration.
59
- */
60
- getOrCreateUser: types.GetOrCreateUser<TBot>;
61
- private _run;
62
- }
@@ -1,141 +0,0 @@
1
- import * as client from '@botpress/client';
2
- import * as utils from '../../utils/type-utils';
3
- import * as common from '../types';
4
- type Arg<F extends (...args: any[]) => any> = Parameters<F>[number];
5
- type Res<F extends (...args: any[]) => any> = ReturnType<F>;
6
- type EventResponse<TBot extends common.BaseBot> = {
7
- event: {
8
- [K in keyof common.EnumerateEvents<TBot>]: utils.Merge<client.Event, {
9
- type: K;
10
- payload: common.EnumerateEvents<TBot>[K];
11
- }>;
12
- }[keyof common.EnumerateEvents<TBot>];
13
- };
14
- type MessageResponse<TBot extends common.BaseBot, TMessage extends keyof common.GetMessages<TBot> = keyof common.GetMessages<TBot>> = {
15
- message: utils.ValueOf<{
16
- [K in keyof common.GetMessages<TBot> as K extends TMessage ? K : never]: utils.Merge<client.Message, {
17
- type: K;
18
- payload: common.GetMessages<TBot>[K];
19
- }>;
20
- }>;
21
- };
22
- type StateResponse<TBot extends common.BaseBot, TState extends keyof TBot['states'] = keyof TBot['states']> = utils.Merge<Awaited<Res<client.Client['getState']>>, {
23
- state: utils.Merge<Awaited<Res<client.Client['getState']>>['state'], {
24
- payload: TBot['states'][TState];
25
- }>;
26
- }>;
27
- export type CreateConversation<_TBot extends common.BaseBot> = client.Client['createConversation'];
28
- export type GetConversation<_TBot extends common.BaseBot> = client.Client['getConversation'];
29
- export type ListConversations<_TBot extends common.BaseBot> = client.Client['listConversations'];
30
- export type GetOrCreateConversation<_TBot extends common.BaseBot> = client.Client['getOrCreateConversation'];
31
- export type UpdateConversation<_TBot extends common.BaseBot> = client.Client['updateConversation'];
32
- export type DeleteConversation<_TBot extends common.BaseBot> = client.Client['deleteConversation'];
33
- export type ListParticipants<_TBot extends common.BaseBot> = client.Client['listParticipants'];
34
- export type AddParticipant<_TBot extends common.BaseBot> = client.Client['addParticipant'];
35
- export type GetParticipant<_TBot extends common.BaseBot> = client.Client['getParticipant'];
36
- export type RemoveParticipant<_TBot extends common.BaseBot> = client.Client['removeParticipant'];
37
- export type GetEvent<TBot extends common.BaseBot> = (x: Arg<client.Client['getEvent']>) => Promise<EventResponse<TBot>>;
38
- export type ListEvents<_TBot extends common.BaseBot> = client.Client['listEvents'];
39
- export type CreateMessage<TBot extends common.BaseBot> = <TMessage extends keyof common.GetMessages<TBot>>(x: utils.Merge<Arg<client.Client['createMessage']>, {
40
- type: utils.Cast<TMessage, string>;
41
- payload: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>;
42
- }>) => Promise<MessageResponse<TBot, TMessage>>;
43
- export type GetOrCreateMessage<TBot extends common.BaseBot> = <TMessage extends keyof common.GetMessages<TBot>>(x: utils.Merge<Arg<client.Client['getOrCreateMessage']>, {
44
- type: utils.Cast<TMessage, string>;
45
- payload: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>;
46
- }>) => Promise<MessageResponse<TBot, TMessage>>;
47
- export type GetMessage<TBot extends common.BaseBot> = (x: Arg<client.Client['getMessage']>) => Promise<MessageResponse<TBot>>;
48
- export type UpdateMessage<TBot extends common.BaseBot> = (x: Arg<client.Client['updateMessage']>) => Promise<MessageResponse<TBot>>;
49
- export type ListMessages<_TBot extends common.BaseBot> = client.Client['listMessages'];
50
- export type DeleteMessage<_TBot extends common.BaseBot> = client.Client['deleteMessage'];
51
- export type CreateUser<_TBot extends common.BaseBot> = client.Client['createUser'];
52
- export type GetUser<_TBot extends common.BaseBot> = client.Client['getUser'];
53
- export type ListUsers<_TBot extends common.BaseBot> = client.Client['listUsers'];
54
- export type GetOrCreateUser<_TBot extends common.BaseBot> = client.Client['getOrCreateUser'];
55
- export type UpdateUser<_TBot extends common.BaseBot> = client.Client['updateUser'];
56
- export type DeleteUser<_TBot extends common.BaseBot> = client.Client['deleteUser'];
57
- export type GetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['getState']>, {
58
- name: utils.Cast<TState, string>;
59
- }>) => Promise<StateResponse<TBot, TState>>;
60
- export type SetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['setState']>, {
61
- name: utils.Cast<TState, string>;
62
- payload: TBot['states'][TState] | null;
63
- }>) => Promise<StateResponse<TBot, TState>>;
64
- export type GetOrSetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['getOrSetState']>, {
65
- name: utils.Cast<TState, string>;
66
- payload: TBot['states'][TState];
67
- }>) => Promise<StateResponse<TBot, TState>>;
68
- export type PatchState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['patchState']>, {
69
- name: utils.Cast<TState, string>;
70
- payload: Partial<TBot['states'][TState]>;
71
- }>) => Promise<{
72
- state: utils.Merge<Awaited<Res<client.Client['patchState']>>['state'], {
73
- payload: TBot['states'][TState];
74
- }>;
75
- }>;
76
- export type CallAction<TBot extends common.BaseBot> = <ActionType extends keyof common.EnumerateActions<TBot>>(x: utils.Merge<Arg<client.Client['callAction']>, {
77
- type: utils.Cast<ActionType, string>;
78
- input: utils.Cast<common.EnumerateActions<TBot>[ActionType], common.IntegrationInstanceActionDefinition>['input'];
79
- }>) => Promise<utils.Merge<Awaited<Res<client.Client['callAction']>>, {
80
- output: utils.Cast<common.EnumerateActions<TBot>[ActionType], common.IntegrationInstanceActionDefinition>['output'];
81
- }>>;
82
- export type UploadFile<_TBot extends common.BaseBot> = client.Client['uploadFile'];
83
- export type UpsertFile<_TBot extends common.BaseBot> = client.Client['upsertFile'];
84
- export type DeleteFile<_TBot extends common.BaseBot> = client.Client['deleteFile'];
85
- export type ListFiles<_TBot extends common.BaseBot> = client.Client['listFiles'];
86
- export type GetFile<_TBot extends common.BaseBot> = client.Client['getFile'];
87
- export type UpdateFileMetadata<_TBot extends common.BaseBot> = client.Client['updateFileMetadata'];
88
- export type SearchFiles<_TBot extends common.BaseBot> = client.Client['searchFiles'];
89
- export type TrackAnalytics<_TBot extends common.BaseBot> = client.Client['trackAnalytics'];
90
- export type ClientOperations<TBot extends common.BaseBot> = {
91
- getConversation: GetConversation<TBot>;
92
- listConversations: ListConversations<TBot>;
93
- updateConversation: UpdateConversation<TBot>;
94
- deleteConversation: DeleteConversation<TBot>;
95
- listParticipants: ListParticipants<TBot>;
96
- addParticipant: AddParticipant<TBot>;
97
- getParticipant: GetParticipant<TBot>;
98
- removeParticipant: RemoveParticipant<TBot>;
99
- getEvent: GetEvent<TBot>;
100
- listEvents: ListEvents<TBot>;
101
- createMessage: CreateMessage<TBot>;
102
- getOrCreateMessage: GetOrCreateMessage<TBot>;
103
- getMessage: GetMessage<TBot>;
104
- updateMessage: UpdateMessage<TBot>;
105
- listMessages: ListMessages<TBot>;
106
- deleteMessage: DeleteMessage<TBot>;
107
- getUser: GetUser<TBot>;
108
- listUsers: ListUsers<TBot>;
109
- updateUser: UpdateUser<TBot>;
110
- deleteUser: DeleteUser<TBot>;
111
- getState: GetState<TBot>;
112
- setState: SetState<TBot>;
113
- getOrSetState: GetOrSetState<TBot>;
114
- patchState: PatchState<TBot>;
115
- callAction: CallAction<TBot>;
116
- uploadFile: UploadFile<TBot>;
117
- upsertFile: UpsertFile<TBot>;
118
- deleteFile: DeleteFile<TBot>;
119
- listFiles: ListFiles<TBot>;
120
- getFile: GetFile<TBot>;
121
- updateFileMetadata: UpdateFileMetadata<TBot>;
122
- searchFiles: SearchFiles<TBot>;
123
- trackAnalytics: TrackAnalytics<TBot>;
124
- };
125
- export type ClientInputs<TBot extends common.BaseBot> = {
126
- [K in keyof ClientOperations<TBot>]: Arg<ClientOperations<TBot>[K]>;
127
- };
128
- export type ClientOutputs<TBot extends common.BaseBot> = {
129
- [K in keyof ClientOperations<TBot>]: Awaited<Res<ClientOperations<TBot>[K]>>;
130
- };
131
- type ClientHooksBefore = {
132
- [K in client.Operation]?: (x: client.ClientInputs[K]) => Promise<client.ClientInputs[K]>;
133
- };
134
- type ClientHooksAfter = {
135
- [K in client.Operation]?: (x: client.ClientOutputs[K]) => Promise<client.ClientOutputs[K]>;
136
- };
137
- export type ClientHooks = {
138
- before: ClientHooksBefore;
139
- after: ClientHooksAfter;
140
- };
141
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,111 +0,0 @@
1
- import { IntegrationPackage, PluginPackage } from '../package';
2
- import { SchemaDefinition } from '../schema';
3
- import { ValueOf } from '../utils/type-utils';
4
- import z, { ZuiObjectSchema } from '../zui';
5
- type BaseConfig = ZuiObjectSchema;
6
- type BaseStates = Record<string, ZuiObjectSchema>;
7
- type BaseEvents = Record<string, ZuiObjectSchema>;
8
- type BaseActions = Record<string, ZuiObjectSchema>;
9
- export type TagDefinition = {
10
- title?: string;
11
- description?: string;
12
- };
13
- export type StateType = 'conversation' | 'user' | 'bot';
14
- export type StateDefinition<TState extends BaseStates[string] = BaseStates[string]> = SchemaDefinition<TState> & {
15
- type: StateType;
16
- expiry?: number;
17
- };
18
- export type RecurringEventDefinition<TEvents extends BaseEvents = BaseEvents> = {
19
- [K in keyof TEvents]: {
20
- type: K;
21
- payload: z.infer<TEvents[K]>;
22
- schedule: {
23
- cron: string;
24
- };
25
- };
26
- }[keyof TEvents];
27
- export type EventDefinition<TEvent extends BaseEvents[string] = BaseEvents[string]> = SchemaDefinition<TEvent>;
28
- export type ConfigurationDefinition<TConfig extends BaseConfig = BaseConfig> = SchemaDefinition<TConfig>;
29
- export type UserDefinition = {
30
- tags?: Record<string, TagDefinition>;
31
- };
32
- export type ConversationDefinition = {
33
- tags?: Record<string, TagDefinition>;
34
- };
35
- export type MessageDefinition = {
36
- tags?: Record<string, TagDefinition>;
37
- };
38
- export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[string]> = {
39
- title?: string;
40
- description?: string;
41
- input: SchemaDefinition<TAction>;
42
- output: SchemaDefinition<ZuiObjectSchema>;
43
- };
44
- export type IntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = {
45
- enabled: boolean;
46
- } & ({
47
- configurationType?: null;
48
- configuration: z.infer<NonNullable<I['definition']['configuration']>['schema']>;
49
- } | ValueOf<{
50
- [K in keyof NonNullable<I['definition']['configurations']>]: {
51
- configurationType: K;
52
- configuration: z.infer<NonNullable<I['definition']['configurations']>[K]['schema']>;
53
- };
54
- }>);
55
- export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
56
- configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
57
- interfaces: {
58
- [I in keyof NonNullable<P['definition']['interfaces']>]: {
59
- name: string;
60
- version: string;
61
- };
62
- };
63
- };
64
- export type IntegrationInstance = IntegrationPackage & IntegrationConfigInstance;
65
- export type PluginInstance = PluginPackage & PluginConfigInstance;
66
- export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> = {
67
- integrations?: {
68
- [K: string]: IntegrationInstance;
69
- };
70
- plugins?: {
71
- [K: string]: PluginInstance;
72
- };
73
- user?: UserDefinition;
74
- conversation?: ConversationDefinition;
75
- message?: MessageDefinition;
76
- states?: {
77
- [K in keyof TStates]: StateDefinition<TStates[K]>;
78
- };
79
- configuration?: ConfigurationDefinition;
80
- events?: {
81
- [K in keyof TEvents]: EventDefinition<TEvents[K]>;
82
- };
83
- recurringEvents?: Record<string, RecurringEventDefinition<TEvents>>;
84
- actions?: {
85
- [K in keyof TActions]: ActionDefinition<TActions[K]>;
86
- };
87
- };
88
- export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> {
89
- readonly props: BotDefinitionProps<TStates, TEvents, TActions>;
90
- readonly integrations: this['props']['integrations'];
91
- readonly plugins: this['props']['plugins'];
92
- readonly user: this['props']['user'];
93
- readonly conversation: this['props']['conversation'];
94
- readonly message: this['props']['message'];
95
- readonly states: this['props']['states'];
96
- readonly configuration: this['props']['configuration'];
97
- readonly events: this['props']['events'];
98
- readonly recurringEvents: this['props']['recurringEvents'];
99
- readonly actions: this['props']['actions'];
100
- constructor(props: BotDefinitionProps<TStates, TEvents, TActions>);
101
- addIntegration<I extends IntegrationPackage>(integrationPkg: I, config: IntegrationConfigInstance<I>): this;
102
- addPlugin<P extends PluginPackage>(pluginPkg: P, config: PluginConfigInstance<P>): this;
103
- private _mergeUser;
104
- private _mergeConversation;
105
- private _mergeMessage;
106
- private _mergeStates;
107
- private _mergeEvents;
108
- private _mergeRecurringEvents;
109
- private _mergeActions;
110
- }
111
- export {};
@@ -1,39 +0,0 @@
1
- import type { Server } from 'node:http';
2
- import { BasePlugin, PluginImplementation } from '../plugin';
3
- import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookHandlersMap, HookData, HookHandlers, ActionHandlers, BotHandlers, UnimplementedActionHandlers } from './server';
4
- import { BaseBot } from './types';
5
- export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> = {
6
- actions: UnimplementedActionHandlers<TBot, TPlugins>;
7
- plugins: {
8
- [K in keyof TPlugins]: PluginImplementation<TPlugins[K]>;
9
- };
10
- };
11
- export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements BotHandlers<TBot> {
12
- readonly props: BotImplementationProps<TBot, TPlugins>;
13
- readonly actionHandlers: ActionHandlers<TBot>;
14
- readonly messageHandlers: MessageHandlersMap<TBot>;
15
- readonly eventHandlers: EventHandlersMap<TBot>;
16
- readonly stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
17
- readonly hookHandlers: HookHandlersMap<TBot>;
18
- /**
19
- * alias for actionHandlers
20
- */
21
- get actions(): ActionHandlers<TBot>;
22
- constructor(props: BotImplementationProps<TBot, TPlugins>);
23
- readonly on: {
24
- message: <T extends keyof MessageHandlersMap<TBot>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
25
- event: <T extends keyof EventHandlersMap<TBot>>(type: T, handler: EventHandlers<TBot>[T]) => void;
26
- stateExpired: <T extends keyof StateExpiredHandlersMap<TBot>>(type: T, handler: StateExpiredHandlers<TBot>[T]) => void;
27
- beforeIncomingEvent: <T extends keyof HookData<TBot>["before_incoming_event"]>(type: T, handler: HookHandlers<TBot>["before_incoming_event"][T]) => void;
28
- beforeIncomingMessage: <T extends keyof HookData<TBot>["before_incoming_message"]>(type: T, handler: HookHandlers<TBot>["before_incoming_message"][T]) => void;
29
- beforeOutgoingMessage: <T extends keyof HookData<TBot>["before_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_message"][T]) => void;
30
- beforeOutgoingCallAction: <T extends keyof HookData<TBot>["before_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_call_action"][T]) => void;
31
- afterIncomingEvent: <T extends keyof HookData<TBot>["after_incoming_event"]>(type: T, handler: HookHandlers<TBot>["after_incoming_event"][T]) => void;
32
- afterIncomingMessage: <T extends keyof HookData<TBot>["after_incoming_message"]>(type: T, handler: HookHandlers<TBot>["after_incoming_message"][T]) => void;
33
- afterOutgoingMessage: <T extends keyof HookData<TBot>["after_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_message"][T]) => void;
34
- afterOutgoingCallAction: <T extends keyof HookData<TBot>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_call_action"][T]) => void;
35
- };
36
- private readonly _use;
37
- readonly handler: (req: import("../serve").Request) => Promise<import("../serve").Response | void>;
38
- readonly start: (port?: number) => Promise<Server>;
39
- }
@@ -1,5 +0,0 @@
1
- export * from './definition';
2
- export * from './implementation';
3
- export * from './client';
4
- export * from './server';
5
- export * from './types/generic';
@@ -1,2 +0,0 @@
1
- import { BotHandlers } from './server';
2
- export declare const mergeBots: (dest: BotHandlers<any>, src: BotHandlers<any>) => void;
@@ -1,2 +0,0 @@
1
- import { BotContext } from './types';
2
- export declare const extractContext: (headers: Record<string, string | undefined>) => BotContext;
@@ -1,5 +0,0 @@
1
- import { Request, Response } from '../../serve';
2
- import * as common from '../types';
3
- import * as types from './types';
4
- export * from './types';
5
- export declare const botHandler: (bot: types.BotHandlers<common.BaseBot>) => (req: Request) => Promise<Response | void>;
@@ -1,252 +0,0 @@
1
- import * as client from '@botpress/client';
2
- import * as plugin from '../../plugin';
3
- import * as utils from '../../utils/type-utils';
4
- import { BotSpecificClient } from '../client';
5
- import * as types from '../types';
6
- export type BotOperation = 'event_received' | 'register' | 'unregister' | 'ping' | 'action_triggered';
7
- export type BotContext = {
8
- botId: string;
9
- type: string;
10
- operation: BotOperation;
11
- configuration: {
12
- payload: string;
13
- };
14
- };
15
- type _IncomingEvents<TBot extends types.BaseBot> = {
16
- [K in keyof types.EnumerateEvents<TBot>]: utils.Merge<client.Event, {
17
- type: K;
18
- payload: types.EnumerateEvents<TBot>[K];
19
- }>;
20
- };
21
- type _IncomingMessages<TBot extends types.BaseBot> = {
22
- [K in keyof types.GetMessages<TBot>]: utils.Merge<client.Message, {
23
- type: K;
24
- payload: types.GetMessages<TBot>[K];
25
- }>;
26
- };
27
- type _OutgoingMessageRequests<TBot extends types.BaseBot> = {
28
- [K in keyof types.GetMessages<TBot>]: utils.Merge<client.ClientInputs['createMessage'], {
29
- type: K;
30
- payload: types.GetMessages<TBot>[K];
31
- }>;
32
- };
33
- type _OutgoingMessageResponses<TBot extends types.BaseBot> = {
34
- [K in keyof types.GetMessages<TBot>]: utils.Merge<client.ClientOutputs['createMessage'], {
35
- message: utils.Merge<client.Message, {
36
- type: K;
37
- payload: types.GetMessages<TBot>[K];
38
- }>;
39
- }>;
40
- };
41
- type _OutgoingCallActionRequests<TBot extends types.BaseBot> = {
42
- [K in keyof types.EnumerateActionInputs<TBot>]: utils.Merge<client.ClientInputs['callAction'], {
43
- type: K;
44
- input: types.EnumerateActionInputs<TBot>[K];
45
- }>;
46
- };
47
- type _OutgoingCallActionResponses<TBot extends types.BaseBot> = {
48
- [K in keyof types.EnumerateActionOutputs<TBot>]: utils.Merge<client.ClientOutputs['callAction'], {
49
- output: types.EnumerateActionOutputs<TBot>[K];
50
- }>;
51
- };
52
- export type AnyIncomingEvent<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.Event : utils.ValueOf<_IncomingEvents<TBot>>;
53
- export type AnyIncomingMessage<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.Message : utils.ValueOf<_IncomingMessages<TBot>>;
54
- export type AnyOutgoingMessageRequest<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientInputs['createMessage'] : utils.ValueOf<_OutgoingMessageRequests<TBot>>;
55
- export type AnyOutgoingMessageResponse<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientOutputs['createMessage'] : utils.ValueOf<_OutgoingMessageResponses<TBot>>;
56
- export type AnyOutgoingCallActionRequest<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientInputs['callAction'] : utils.ValueOf<_OutgoingCallActionRequests<TBot>>;
57
- export type AnyOutgoingCallActionResponse<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientOutputs['callAction'] : utils.ValueOf<_OutgoingCallActionResponses<TBot>>;
58
- export type IncomingEvents<TBot extends types.BaseBot> = _IncomingEvents<TBot> & {
59
- '*': AnyIncomingEvent<TBot>;
60
- };
61
- export type IncomingMessages<TBot extends types.BaseBot> = _IncomingMessages<TBot> & {
62
- '*': AnyIncomingMessage<TBot>;
63
- };
64
- export type IncomingStates<_TBot extends types.BaseBot> = {
65
- '*': client.State;
66
- };
67
- export type OutgoingMessageRequests<TBot extends types.BaseBot> = _OutgoingMessageRequests<TBot> & {
68
- '*': AnyOutgoingMessageRequest<TBot>;
69
- };
70
- export type OutgoingMessageResponses<TBot extends types.BaseBot> = _OutgoingMessageResponses<TBot> & {
71
- '*': AnyOutgoingMessageResponse<TBot>;
72
- };
73
- export type OutgoingCallActionRequests<TBot extends types.BaseBot> = _OutgoingCallActionRequests<TBot> & {
74
- '*': AnyOutgoingCallActionRequest<TBot>;
75
- };
76
- export type OutgoingCallActionResponses<TBot extends types.BaseBot> = _OutgoingCallActionResponses<TBot> & {
77
- '*': AnyOutgoingCallActionResponse<TBot>;
78
- };
79
- export type BotClient<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? BotSpecificClient<types.BaseBot> : BotSpecificClient<TBot>;
80
- export type CommonHandlerProps<TBot extends types.BaseBot> = {
81
- ctx: BotContext;
82
- client: BotClient<TBot>;
83
- };
84
- export type MessagePayloads<TBot extends types.BaseBot> = {
85
- [K in keyof IncomingMessages<TBot>]: {
86
- message: IncomingMessages<TBot>[K];
87
- user: client.User;
88
- conversation: client.Conversation;
89
- event: client.Event;
90
- states: {
91
- [TState in keyof TBot['states']]: {
92
- type: 'user' | 'conversation' | 'bot';
93
- payload: TBot['states'][TState];
94
- };
95
- };
96
- };
97
- };
98
- export type MessageHandlers<TBot extends types.BaseBot> = {
99
- [K in keyof IncomingMessages<TBot>]: (args: CommonHandlerProps<TBot> & MessagePayloads<TBot>[K]) => Promise<void>;
100
- };
101
- export type EventPayloads<TBot extends types.BaseBot> = {
102
- [K in keyof IncomingEvents<TBot>]: {
103
- event: IncomingEvents<TBot>[K];
104
- };
105
- };
106
- export type EventHandlers<TBot extends types.BaseBot> = {
107
- [K in keyof IncomingEvents<TBot>]: (args: CommonHandlerProps<TBot> & EventPayloads<TBot>[K]) => Promise<void>;
108
- };
109
- export type StateExpiredPayloads<TBot extends types.BaseBot> = {
110
- [K in keyof IncomingStates<TBot>]: {
111
- state: IncomingStates<TBot>[K];
112
- };
113
- };
114
- export type StateExpiredHandlers<TBot extends types.BaseBot> = {
115
- [K in keyof IncomingStates<TBot>]: (args: CommonHandlerProps<TBot> & StateExpiredPayloads<TBot>[K]) => Promise<void>;
116
- };
117
- export type ActionHandlerPayloads<TBot extends types.BaseBot> = {
118
- [K in keyof TBot['actions']]: {
119
- type?: K;
120
- input: TBot['actions'][K]['input'];
121
- };
122
- };
123
- export type ActionHandlers<TBot extends types.BaseBot> = {
124
- [K in keyof TBot['actions']]: (props: CommonHandlerProps<TBot> & ActionHandlerPayloads<TBot>[K]) => Promise<TBot['actions'][K]['output']>;
125
- };
126
- type BaseHookDefinition = {
127
- stoppable?: boolean;
128
- data: any;
129
- };
130
- type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
131
- /**
132
- * TODO: add hooks for:
133
- * - before_register
134
- * - after_register
135
- * - before_state_expired
136
- * - after_state_expired
137
- * - before_incoming_call_action
138
- * - after_incoming_call_action
139
- */
140
- export type HookDefinitions<TBot extends types.BaseBot> = {
141
- before_incoming_event: HookDefinition<{
142
- stoppable: true;
143
- data: _IncomingEvents<TBot> & {
144
- '*': AnyIncomingEvent<TBot>;
145
- };
146
- }>;
147
- before_incoming_message: HookDefinition<{
148
- stoppable: true;
149
- data: _IncomingMessages<TBot> & {
150
- '*': AnyIncomingMessage<TBot>;
151
- };
152
- }>;
153
- before_outgoing_message: HookDefinition<{
154
- stoppable: false;
155
- data: _OutgoingMessageRequests<TBot> & {
156
- '*': AnyOutgoingMessageRequest<TBot>;
157
- };
158
- }>;
159
- before_outgoing_call_action: HookDefinition<{
160
- stoppable: false;
161
- data: _OutgoingCallActionRequests<TBot> & {
162
- '*': AnyOutgoingCallActionRequest<TBot>;
163
- };
164
- }>;
165
- after_incoming_event: HookDefinition<{
166
- stoppable: true;
167
- data: _IncomingEvents<TBot> & {
168
- '*': AnyIncomingEvent<TBot>;
169
- };
170
- }>;
171
- after_incoming_message: HookDefinition<{
172
- stoppable: true;
173
- data: _IncomingMessages<TBot> & {
174
- '*': AnyIncomingMessage<TBot>;
175
- };
176
- }>;
177
- after_outgoing_message: HookDefinition<{
178
- stoppable: false;
179
- data: _OutgoingMessageResponses<TBot> & {
180
- '*': AnyOutgoingMessageResponse<TBot>;
181
- };
182
- }>;
183
- after_outgoing_call_action: HookDefinition<{
184
- stoppable: false;
185
- data: _OutgoingCallActionResponses<TBot> & {
186
- '*': AnyOutgoingCallActionResponse<TBot>;
187
- };
188
- }>;
189
- };
190
- export type HookData<TBot extends types.BaseBot> = {
191
- [H in keyof HookDefinitions<TBot>]: {
192
- [T in keyof HookDefinitions<TBot>[H]['data']]: HookDefinitions<TBot>[H]['data'][T];
193
- };
194
- };
195
- export type HookInputs<TBot extends types.BaseBot> = {
196
- [H in keyof HookData<TBot>]: {
197
- [T in keyof HookData<TBot>[H]]: CommonHandlerProps<TBot> & {
198
- data: HookData<TBot>[H][T];
199
- };
200
- };
201
- };
202
- export type HookOutputs<TBot extends types.BaseBot> = {
203
- [H in keyof HookData<TBot>]: {
204
- [T in keyof HookData<TBot>[H]]: {
205
- data?: HookData<TBot>[H][T];
206
- } & (HookDefinitions<TBot>[H]['stoppable'] extends true ? {
207
- stop?: boolean;
208
- } : {});
209
- };
210
- };
211
- export type HookHandlers<TBot extends types.BaseBot> = {
212
- [H in keyof HookData<TBot>]: {
213
- [T in keyof HookData<TBot>[H]]: (input: HookInputs<TBot>[H][T]) => Promise<HookOutputs<TBot>[H][T] | undefined>;
214
- };
215
- };
216
- export type MessageHandlersMap<TBot extends types.BaseBot> = {
217
- [T in keyof IncomingMessages<TBot>]?: MessageHandlers<TBot>[T][];
218
- };
219
- export type EventHandlersMap<TBot extends types.BaseBot> = {
220
- [T in keyof IncomingEvents<TBot>]?: EventHandlers<TBot>[T][];
221
- };
222
- export type StateExpiredHandlersMap<TBot extends types.BaseBot> = {
223
- [T in keyof IncomingStates<TBot>]?: StateExpiredHandlers<TBot>[T][];
224
- };
225
- export type HookHandlersMap<TBot extends types.BaseBot> = {
226
- [H in keyof HookData<TBot>]: {
227
- [T in keyof HookData<TBot>[H]]?: HookHandlers<TBot>[H][T][];
228
- };
229
- };
230
- export type BotActionHandlers<TBot extends types.BaseBot> = ActionHandlers<TBot>;
231
- export type BotMessageHandlers<TBot extends types.BaseBot> = MessageHandlersMap<TBot>;
232
- export type BotEventHandlers<TBot extends types.BaseBot> = EventHandlersMap<TBot>;
233
- export type BotStateExpiredHandlers<TBot extends types.BaseBot> = StateExpiredHandlersMap<TBot>;
234
- export type BotHookHandlers<TBot extends types.BaseBot> = HookHandlersMap<TBot>;
235
- export type BotHandlers<TBot extends types.BaseBot> = {
236
- actionHandlers: BotActionHandlers<TBot>;
237
- messageHandlers: BotMessageHandlers<TBot>;
238
- eventHandlers: BotEventHandlers<TBot>;
239
- stateExpiredHandlers: BotStateExpiredHandlers<TBot>;
240
- hookHandlers: BotHookHandlers<TBot>;
241
- };
242
- type ImplementedActions<_TBot extends types.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
243
- [K in keyof TPlugins]: TPlugins[K]['actions'];
244
- }>>;
245
- type UnimplementedActions<TBot extends types.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = Omit<TBot['actions'], keyof ImplementedActions<TBot, TPlugins>>;
246
- export type ImplementedActionHandlers<TBot extends types.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
247
- [K in keyof ImplementedActions<TBot, TPlugins>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
248
- };
249
- export type UnimplementedActionHandlers<TBot extends types.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
250
- [K in keyof UnimplementedActions<TBot, TPlugins>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
251
- };
252
- export {};