@botpress/sdk 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bot/client/index.d.ts +35 -0
- package/dist/bot/client/routes.d.ts +55 -0
- package/dist/bot/client/types.d.ts +33 -0
- package/dist/bot/context.d.ts +1 -0
- package/dist/bot/generic.d.ts +7 -0
- package/dist/bot/implementation.d.ts +52 -52
- package/dist/bot/index.d.ts +2 -1
- package/dist/bot/integration-instance.d.ts +7 -0
- package/dist/bot/server.d.ts +41 -3
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/integration/client/index.d.ts +35 -0
- package/dist/integration/client/routes.d.ts +95 -0
- package/dist/integration/client/types.d.ts +22 -0
- package/dist/integration/context.d.ts +1 -0
- package/dist/integration/definition.d.ts +69 -720
- package/dist/integration/generic.d.ts +28 -0
- package/dist/integration/implementation.d.ts +22 -99
- package/dist/integration/index.d.ts +1 -2
- package/dist/integration/server.d.ts +84 -10
- package/dist/message.d.ts +20 -20
- package/dist/schema.d.ts +15 -0
- package/dist/serve.d.ts +1 -0
- package/dist/type-utils.d.ts +9 -0
- package/package.json +2 -3
- package/dist/bot/client.d.ts +0 -25
- package/dist/bot/state.d.ts +0 -29
- package/dist/error.d.ts +0 -18
- package/dist/integration/client.d.ts +0 -39
- package/dist/integration/error.d.ts +0 -14
- package/dist/integration/schema.d.ts +0 -16
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type BaseIntegration = {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
configuration: any;
|
|
5
|
+
actions: Record<string, Record<'input' | 'output', any>>;
|
|
6
|
+
channels: Record<string, {
|
|
7
|
+
messages: Record<string, any>;
|
|
8
|
+
message: {
|
|
9
|
+
tags: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
conversation: {
|
|
12
|
+
tags: Record<string, any>;
|
|
13
|
+
creation: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
requiredTags: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
events: Record<string, any>;
|
|
20
|
+
states: Record<string, any>;
|
|
21
|
+
user: {
|
|
22
|
+
tags: Record<string, any>;
|
|
23
|
+
creation: {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
requiredTags: string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,102 +1,25 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { Client, Conversation, Message, User } from '@botpress/client';
|
|
3
1
|
import type { Server } from 'node:http';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export type EventPayload<E> = {
|
|
27
|
-
event: E;
|
|
28
|
-
};
|
|
29
|
-
export type CreateUserPayload = {
|
|
30
|
-
tags: Tags;
|
|
31
|
-
};
|
|
32
|
-
export type CreateConversationPayload = {
|
|
33
|
-
channel: string;
|
|
34
|
-
tags: Tags;
|
|
35
|
-
};
|
|
36
|
-
type Tags = {
|
|
37
|
-
[key: string]: string;
|
|
38
|
-
};
|
|
39
|
-
export type AckFunction = (props: {
|
|
40
|
-
tags: Tags;
|
|
41
|
-
}) => Promise<void>;
|
|
42
|
-
export type MessagePayload<P, M, C, U> = {
|
|
43
|
-
payload: P;
|
|
44
|
-
conversation: C;
|
|
45
|
-
message: M;
|
|
46
|
-
user: U;
|
|
47
|
-
type: string;
|
|
48
|
-
};
|
|
49
|
-
export type ActionDefinitions = {
|
|
50
|
-
[actionType: string]: {
|
|
51
|
-
input: any;
|
|
52
|
-
output: any;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export type ChannelDefinitions = {
|
|
56
|
-
[channelName: string]: MessageDefinitions;
|
|
57
|
-
};
|
|
58
|
-
export type EventDefinitions = {
|
|
59
|
-
[eventName: string]: any;
|
|
60
|
-
};
|
|
61
|
-
type MessageDefinitions = {
|
|
62
|
-
[messageType: string]: any;
|
|
63
|
-
};
|
|
64
|
-
type ActionFunctions<Configuration, A extends ActionDefinitions> = {
|
|
65
|
-
[actionType in keyof A]: (props: IntegrationProps<Configuration> & ActionPayload<actionType, A[actionType]['input']>) => Promise<A[actionType]['output']>;
|
|
66
|
-
};
|
|
67
|
-
type MessageHandlerProps = {
|
|
68
|
-
ack: AckFunction;
|
|
69
|
-
};
|
|
70
|
-
export type ChannelFunctions<Configuration, C extends ChannelDefinitions> = {
|
|
71
|
-
[channelName in keyof C]: {
|
|
72
|
-
messages: {
|
|
73
|
-
[messageType in keyof C[channelName]]: (props: IntegrationProps<Configuration> & MessagePayload<C[channelName][messageType], Message, Conversation, User> & MessageHandlerProps) => Promise<void>;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
type BaseConfig = any;
|
|
78
|
-
type BaseActions = ActionDefinitions;
|
|
79
|
-
type BaseChannels = ChannelDefinitions;
|
|
80
|
-
type BaseEvents = EventDefinitions;
|
|
81
|
-
export type IntegrationImplementationProps<Configuration extends any = BaseConfig, Actions extends ActionDefinitions = BaseActions, Channels extends ChannelDefinitions = BaseChannels, _Events extends EventDefinitions = BaseEvents> = {
|
|
82
|
-
register: (props: IntegrationProps<Configuration> & RegisterPayload) => Promise<void>;
|
|
83
|
-
unregister: (props: IntegrationProps<Configuration> & UnregisterPayload) => Promise<void>;
|
|
84
|
-
handler: (props: IntegrationProps<Configuration> & WebhookPayload) => Promise<Response | void>;
|
|
85
|
-
createUser?: (props: IntegrationProps<Configuration> & CreateUserPayload) => Promise<Response | void>;
|
|
86
|
-
createConversation?: (props: IntegrationProps<Configuration> & CreateConversationPayload) => Promise<Response | void>;
|
|
87
|
-
actions: ActionFunctions<Configuration, Actions>;
|
|
88
|
-
channels: ChannelFunctions<Configuration, Channels>;
|
|
89
|
-
};
|
|
90
|
-
export declare class IntegrationImplementation<Configuration extends any = BaseConfig, Actions extends ActionDefinitions = BaseActions, Channels extends ChannelDefinitions = BaseChannels, Events extends EventDefinitions = BaseEvents> {
|
|
91
|
-
readonly props: IntegrationImplementationProps<Configuration, Actions, Channels, Events>;
|
|
92
|
-
readonly actions: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['actions'];
|
|
93
|
-
readonly channels: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['channels'];
|
|
94
|
-
readonly register: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['register'];
|
|
95
|
-
readonly unregister: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['unregister'];
|
|
96
|
-
readonly createUser: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['createUser'];
|
|
97
|
-
readonly createConversation: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['createConversation'];
|
|
98
|
-
readonly handler: ReturnType<typeof integrationHandler>;
|
|
2
|
+
import { BaseIntegration } from './generic';
|
|
3
|
+
import { RegisterFunction, UnregisterFunction, WebhookFunction, CreateUserFunction, CreateConversationFunction, ActionFunctions, ChannelFunctions } from './server';
|
|
4
|
+
export type IntegrationImplementationProps<TIntegration extends BaseIntegration = BaseIntegration> = {
|
|
5
|
+
register: RegisterFunction<TIntegration>;
|
|
6
|
+
unregister: UnregisterFunction<TIntegration>;
|
|
7
|
+
handler: WebhookFunction<TIntegration>;
|
|
8
|
+
createUser?: CreateUserFunction<TIntegration>;
|
|
9
|
+
createConversation?: CreateConversationFunction<TIntegration>;
|
|
10
|
+
actions: ActionFunctions<TIntegration>;
|
|
11
|
+
channels: ChannelFunctions<TIntegration>;
|
|
12
|
+
};
|
|
13
|
+
export declare class IntegrationImplementation<TIntegration extends BaseIntegration = BaseIntegration> {
|
|
14
|
+
readonly props: IntegrationImplementationProps<TIntegration>;
|
|
15
|
+
readonly actions: IntegrationImplementationProps<TIntegration>['actions'];
|
|
16
|
+
readonly channels: IntegrationImplementationProps<TIntegration>['channels'];
|
|
17
|
+
readonly register: IntegrationImplementationProps<TIntegration>['register'];
|
|
18
|
+
readonly unregister: IntegrationImplementationProps<TIntegration>['unregister'];
|
|
19
|
+
readonly createUser: IntegrationImplementationProps<TIntegration>['createUser'];
|
|
20
|
+
readonly createConversation: IntegrationImplementationProps<TIntegration>['createConversation'];
|
|
21
|
+
readonly webhook: IntegrationImplementationProps<TIntegration>['handler'];
|
|
22
|
+
constructor(props: IntegrationImplementationProps<TIntegration>);
|
|
23
|
+
readonly handler: (req: import("../serve").Request) => Promise<void | import("../serve").Response>;
|
|
99
24
|
readonly start: (port?: number) => Promise<Server>;
|
|
100
|
-
constructor(props: IntegrationImplementationProps<Configuration, Actions, Channels, Events>);
|
|
101
25
|
}
|
|
102
|
-
export {};
|
|
@@ -1,12 +1,86 @@
|
|
|
1
|
-
import { Conversation, Message, User } from '@botpress/client';
|
|
1
|
+
import { type Conversation, type Message, type User } from '@botpress/client';
|
|
2
2
|
import { Request, Response } from '../serve';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type: string;
|
|
3
|
+
import { Cast, Merge } from '../type-utils';
|
|
4
|
+
import { IntegrationSpecificClient } from './client';
|
|
5
|
+
import { ToTags } from './client/types';
|
|
6
|
+
import { type IntegrationContext } from './context';
|
|
7
|
+
import { BaseIntegration } from './generic';
|
|
8
|
+
import { IntegrationLogger } from './logger';
|
|
9
|
+
type PrefixConfig<TIntegration extends BaseIntegration> = {
|
|
10
|
+
enforcePrefix: TIntegration['name'];
|
|
12
11
|
};
|
|
12
|
+
type CommonArgs<TIntegration extends BaseIntegration> = {
|
|
13
|
+
ctx: IntegrationContext<TIntegration['configuration']>;
|
|
14
|
+
client: IntegrationSpecificClient<TIntegration>;
|
|
15
|
+
logger: IntegrationLogger;
|
|
16
|
+
};
|
|
17
|
+
type RegisterPayload = {
|
|
18
|
+
webhookUrl: string;
|
|
19
|
+
};
|
|
20
|
+
type RegisterArgs<TIntegration extends BaseIntegration> = CommonArgs<TIntegration> & RegisterPayload;
|
|
21
|
+
type UnregisterPayload = {
|
|
22
|
+
webhookUrl: string;
|
|
23
|
+
};
|
|
24
|
+
type UnregisterArgs<TIntegration extends BaseIntegration> = CommonArgs<TIntegration> & UnregisterPayload;
|
|
25
|
+
type WebhookPayload = {
|
|
26
|
+
req: Request;
|
|
27
|
+
};
|
|
28
|
+
type WebhookArgs<TIntegration extends BaseIntegration> = CommonArgs<TIntegration> & WebhookPayload;
|
|
29
|
+
type ActionPayload<T extends string, I> = {
|
|
30
|
+
type: T;
|
|
31
|
+
input: I;
|
|
32
|
+
};
|
|
33
|
+
type ActionArgs<TIntegration extends BaseIntegration, T extends string, I> = CommonArgs<TIntegration> & ActionPayload<T, I>;
|
|
34
|
+
type CreateUserPayload<TIntegration extends BaseIntegration> = {
|
|
35
|
+
tags: ToTags<keyof TIntegration['user']['tags'], PrefixConfig<TIntegration>>;
|
|
36
|
+
};
|
|
37
|
+
type CreateUserArgs<TIntegration extends BaseIntegration> = CommonArgs<TIntegration> & CreateUserPayload<TIntegration>;
|
|
38
|
+
type CreateConversationPayload<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'] = keyof TIntegration['channels']> = {
|
|
39
|
+
channel: TChannel;
|
|
40
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['conversation']['tags'], PrefixConfig<TIntegration>>;
|
|
41
|
+
};
|
|
42
|
+
type CreateConversationArgs<TIntegration extends BaseIntegration> = CommonArgs<TIntegration> & CreateConversationPayload<TIntegration>;
|
|
43
|
+
type MessagePayload<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']> = {
|
|
44
|
+
type: TMessage;
|
|
45
|
+
payload: TIntegration['channels'][TChannel]['messages'][TMessage];
|
|
46
|
+
conversation: Merge<Conversation, {
|
|
47
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['conversation']['tags'], PrefixConfig<TIntegration>>;
|
|
48
|
+
}>;
|
|
49
|
+
message: Merge<Message, {
|
|
50
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['message']['tags'], PrefixConfig<TIntegration>>;
|
|
51
|
+
}>;
|
|
52
|
+
user: Merge<User, {
|
|
53
|
+
tags: ToTags<keyof TIntegration['user']['tags'], PrefixConfig<TIntegration>>;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
type MessageArgs<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']> = CommonArgs<TIntegration> & MessagePayload<TIntegration, TChannel, TMessage> & {
|
|
57
|
+
ack: (props: {
|
|
58
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['message']['tags'], PrefixConfig<TIntegration>>;
|
|
59
|
+
}) => Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
export type RegisterFunction<TIntegration extends BaseIntegration> = (props: RegisterArgs<TIntegration>) => Promise<void>;
|
|
62
|
+
export type UnregisterFunction<TIntegration extends BaseIntegration> = (props: UnregisterArgs<TIntegration>) => Promise<void>;
|
|
63
|
+
export type WebhookFunction<TIntegration extends BaseIntegration> = (props: WebhookArgs<TIntegration>) => Promise<Response | void>;
|
|
64
|
+
export type ActionFunctions<TIntegration extends BaseIntegration> = {
|
|
65
|
+
[ActionType in keyof TIntegration['actions']]: (props: ActionArgs<TIntegration, Cast<ActionType, string>, TIntegration['actions'][ActionType]['input']>) => Promise<TIntegration['actions'][ActionType]['output']>;
|
|
66
|
+
};
|
|
67
|
+
export type CreateUserFunction<TIntegration extends BaseIntegration> = (props: CreateUserArgs<TIntegration>) => Promise<Response | void>;
|
|
68
|
+
export type CreateConversationFunction<TIntegration extends BaseIntegration> = (props: CreateConversationArgs<TIntegration>) => Promise<Response | void>;
|
|
69
|
+
export type ChannelFunctions<TIntegration extends BaseIntegration> = {
|
|
70
|
+
[ChannelName in keyof TIntegration['channels']]: {
|
|
71
|
+
messages: {
|
|
72
|
+
[MessageType in keyof TIntegration['channels'][ChannelName]['messages']]: (props: CommonArgs<TIntegration> & MessageArgs<TIntegration, ChannelName, MessageType>) => Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export type IntegrationHandlers<TIntegration extends BaseIntegration> = {
|
|
77
|
+
register: RegisterFunction<TIntegration>;
|
|
78
|
+
unregister: UnregisterFunction<TIntegration>;
|
|
79
|
+
webhook: WebhookFunction<TIntegration>;
|
|
80
|
+
createUser?: CreateUserFunction<TIntegration>;
|
|
81
|
+
createConversation?: CreateConversationFunction<TIntegration>;
|
|
82
|
+
actions: ActionFunctions<TIntegration>;
|
|
83
|
+
channels: ChannelFunctions<TIntegration>;
|
|
84
|
+
};
|
|
85
|
+
export declare const integrationHandler: <TIntegration extends BaseIntegration>(instance: IntegrationHandlers<TIntegration>) => (req: Request) => Promise<Response | void>;
|
|
86
|
+
export {};
|
package/dist/message.d.ts
CHANGED
|
@@ -87,51 +87,51 @@ export declare const defaults: {
|
|
|
87
87
|
value: z.ZodString;
|
|
88
88
|
}, "strip", z.ZodTypeAny, {
|
|
89
89
|
value: string;
|
|
90
|
-
action: "
|
|
90
|
+
action: "postback" | "url" | "say";
|
|
91
91
|
label: string;
|
|
92
92
|
}, {
|
|
93
93
|
value: string;
|
|
94
|
-
action: "
|
|
94
|
+
action: "postback" | "url" | "say";
|
|
95
95
|
label: string;
|
|
96
96
|
}>, "many">;
|
|
97
97
|
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
title: string;
|
|
98
99
|
actions: {
|
|
99
100
|
value: string;
|
|
100
|
-
action: "
|
|
101
|
+
action: "postback" | "url" | "say";
|
|
101
102
|
label: string;
|
|
102
103
|
}[];
|
|
103
|
-
title: string;
|
|
104
104
|
subtitle?: string | undefined;
|
|
105
105
|
imageUrl?: string | undefined;
|
|
106
106
|
}, {
|
|
107
|
+
title: string;
|
|
107
108
|
actions: {
|
|
108
109
|
value: string;
|
|
109
|
-
action: "
|
|
110
|
+
action: "postback" | "url" | "say";
|
|
110
111
|
label: string;
|
|
111
112
|
}[];
|
|
112
|
-
title: string;
|
|
113
113
|
subtitle?: string | undefined;
|
|
114
114
|
imageUrl?: string | undefined;
|
|
115
115
|
}>, "many">;
|
|
116
116
|
}, "strip", z.ZodTypeAny, {
|
|
117
117
|
items: {
|
|
118
|
+
title: string;
|
|
118
119
|
actions: {
|
|
119
120
|
value: string;
|
|
120
|
-
action: "
|
|
121
|
+
action: "postback" | "url" | "say";
|
|
121
122
|
label: string;
|
|
122
123
|
}[];
|
|
123
|
-
title: string;
|
|
124
124
|
subtitle?: string | undefined;
|
|
125
125
|
imageUrl?: string | undefined;
|
|
126
126
|
}[];
|
|
127
127
|
}, {
|
|
128
128
|
items: {
|
|
129
|
+
title: string;
|
|
129
130
|
actions: {
|
|
130
131
|
value: string;
|
|
131
|
-
action: "
|
|
132
|
+
action: "postback" | "url" | "say";
|
|
132
133
|
label: string;
|
|
133
134
|
}[];
|
|
134
|
-
title: string;
|
|
135
135
|
subtitle?: string | undefined;
|
|
136
136
|
imageUrl?: string | undefined;
|
|
137
137
|
}[];
|
|
@@ -148,29 +148,29 @@ export declare const defaults: {
|
|
|
148
148
|
value: z.ZodString;
|
|
149
149
|
}, "strip", z.ZodTypeAny, {
|
|
150
150
|
value: string;
|
|
151
|
-
action: "
|
|
151
|
+
action: "postback" | "url" | "say";
|
|
152
152
|
label: string;
|
|
153
153
|
}, {
|
|
154
154
|
value: string;
|
|
155
|
-
action: "
|
|
155
|
+
action: "postback" | "url" | "say";
|
|
156
156
|
label: string;
|
|
157
157
|
}>, "many">;
|
|
158
158
|
}, "strip", z.ZodTypeAny, {
|
|
159
|
+
title: string;
|
|
159
160
|
actions: {
|
|
160
161
|
value: string;
|
|
161
|
-
action: "
|
|
162
|
+
action: "postback" | "url" | "say";
|
|
162
163
|
label: string;
|
|
163
164
|
}[];
|
|
164
|
-
title: string;
|
|
165
165
|
subtitle?: string | undefined;
|
|
166
166
|
imageUrl?: string | undefined;
|
|
167
167
|
}, {
|
|
168
|
+
title: string;
|
|
168
169
|
actions: {
|
|
169
170
|
value: string;
|
|
170
|
-
action: "
|
|
171
|
+
action: "postback" | "url" | "say";
|
|
171
172
|
label: string;
|
|
172
173
|
}[];
|
|
173
|
-
title: string;
|
|
174
174
|
subtitle?: string | undefined;
|
|
175
175
|
imageUrl?: string | undefined;
|
|
176
176
|
}>;
|
|
@@ -189,17 +189,17 @@ export declare const defaults: {
|
|
|
189
189
|
label: string;
|
|
190
190
|
}>, "many">;
|
|
191
191
|
}, "strip", z.ZodTypeAny, {
|
|
192
|
+
text: string;
|
|
192
193
|
options: {
|
|
193
194
|
value: string;
|
|
194
195
|
label: string;
|
|
195
196
|
}[];
|
|
196
|
-
text: string;
|
|
197
197
|
}, {
|
|
198
|
+
text: string;
|
|
198
199
|
options: {
|
|
199
200
|
value: string;
|
|
200
201
|
label: string;
|
|
201
202
|
}[];
|
|
202
|
-
text: string;
|
|
203
203
|
}>;
|
|
204
204
|
};
|
|
205
205
|
readonly choice: {
|
|
@@ -216,17 +216,17 @@ export declare const defaults: {
|
|
|
216
216
|
label: string;
|
|
217
217
|
}>, "many">;
|
|
218
218
|
}, "strip", z.ZodTypeAny, {
|
|
219
|
+
text: string;
|
|
219
220
|
options: {
|
|
220
221
|
value: string;
|
|
221
222
|
label: string;
|
|
222
223
|
}[];
|
|
223
|
-
text: string;
|
|
224
224
|
}, {
|
|
225
|
+
text: string;
|
|
225
226
|
options: {
|
|
226
227
|
value: string;
|
|
227
228
|
label: string;
|
|
228
229
|
}[];
|
|
229
|
-
text: string;
|
|
230
230
|
}>;
|
|
231
231
|
};
|
|
232
232
|
};
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { AnyZodObject } from './type-utils';
|
|
3
|
+
type SchemaOptions<T> = {
|
|
4
|
+
title: string;
|
|
5
|
+
examples: T[];
|
|
6
|
+
};
|
|
7
|
+
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
8
|
+
type UiDefinition<TSchema extends AnyZodObject = AnyZodObject> = IsEmptyObject<z.infer<TSchema>> extends true ? Record<string, never> : {
|
|
9
|
+
[K in keyof z.infer<TSchema>]: Partial<SchemaOptions<z.infer<TSchema>[K]>>;
|
|
10
|
+
};
|
|
11
|
+
export type SchemaDefinition<TSchema extends AnyZodObject = AnyZodObject> = {
|
|
12
|
+
schema: TSchema;
|
|
13
|
+
ui?: Partial<UiDefinition<TSchema>>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
package/dist/serve.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export type Response = {
|
|
|
17
17
|
status?: number;
|
|
18
18
|
};
|
|
19
19
|
export type Handler = (req: Request) => Promise<Response | void>;
|
|
20
|
+
export declare function parseBody<T>(req: Request): T;
|
|
20
21
|
export declare function serve(handler: Handler, port?: number, callback?: (port: number) => void): Promise<Server>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
export type AnyZodObject = z.ZodObject<any>;
|
|
3
|
+
export type Merge<A extends object, B extends object> = Omit<A, keyof B> & B;
|
|
4
|
+
export type Cast<T, U> = T extends U ? T : U;
|
|
5
|
+
export type Iof<T extends object> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
};
|
|
8
|
+
export type Join<S extends (string | number | symbol)[]> = S extends [infer H, ...infer T] ? `${Cast<H, string>}${Join<Cast<T, string[]>>}` : S extends [infer H] ? Cast<H, string> : '';
|
|
9
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Botpress SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"@botpress/client": "0.3.2",
|
|
18
18
|
"axios": "0.27.2",
|
|
19
19
|
"radash": "^9.5.0",
|
|
20
|
-
"zod": "^3.20.6"
|
|
21
|
-
"zod-to-json-schema": "^3.20.1"
|
|
20
|
+
"zod": "^3.20.6"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/node": "^18.11.17",
|
package/dist/bot/client.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Axios as AxiosInstance } from 'axios';
|
|
2
|
-
import type { Merge, Except } from 'type-fest';
|
|
3
|
-
import type { BotContext } from './context';
|
|
4
|
-
import type { RegisterBotPayload, UnregisterBotPayload, EventReceivedBotPayload } from './implementation';
|
|
5
|
-
type Props<T = any> = Merge<Except<BotContext, 'operation'>, {
|
|
6
|
-
url: string;
|
|
7
|
-
data: T;
|
|
8
|
-
}>;
|
|
9
|
-
/**
|
|
10
|
-
* @description Meant to query your bot server directly (e.g. without going through the Botpress API)
|
|
11
|
-
*/
|
|
12
|
-
export declare class BotClient {
|
|
13
|
-
private axios;
|
|
14
|
-
constructor(axiosInstance?: AxiosInstance);
|
|
15
|
-
register: (props: Props<RegisterBotPayload>) => Promise<any>;
|
|
16
|
-
unregister: (props: Props<UnregisterBotPayload>) => Promise<any>;
|
|
17
|
-
eventReceived: (props: Props<EventReceivedBotPayload>) => Promise<any>;
|
|
18
|
-
}
|
|
19
|
-
export declare function formatBotHeaders(ctx: BotContext): {
|
|
20
|
-
"x-bp-type": string;
|
|
21
|
-
"x-bot-id": string;
|
|
22
|
-
"x-bp-operation": "event_received" | "register" | "unregister" | "ping";
|
|
23
|
-
"x-bp-configuration": string;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
package/dist/bot/state.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Message, Conversation, User, Event, Client, State } from '@botpress/client';
|
|
2
|
-
import type { BotContext } from './context';
|
|
3
|
-
export type MessageHandler = (props: {
|
|
4
|
-
client: Client;
|
|
5
|
-
message: Message;
|
|
6
|
-
conversation: Conversation;
|
|
7
|
-
user: User;
|
|
8
|
-
event: Event;
|
|
9
|
-
ctx: BotContext;
|
|
10
|
-
}) => Promise<void>;
|
|
11
|
-
export type EventHandler = (props: {
|
|
12
|
-
client: Client;
|
|
13
|
-
event: Event;
|
|
14
|
-
ctx: BotContext;
|
|
15
|
-
}) => Promise<void>;
|
|
16
|
-
export type StateExpiredHandler = (props: {
|
|
17
|
-
client: Client;
|
|
18
|
-
state: State;
|
|
19
|
-
ctx: BotContext;
|
|
20
|
-
}) => Promise<void>;
|
|
21
|
-
export type RegisterHandler = () => Promise<void>;
|
|
22
|
-
export type UnregisterHandler = () => Promise<void>;
|
|
23
|
-
export type BotState = {
|
|
24
|
-
registerHandlers: RegisterHandler[];
|
|
25
|
-
unregisterHandlers: UnregisterHandler[];
|
|
26
|
-
messageHandlers: MessageHandler[];
|
|
27
|
-
eventHandlers: EventHandler[];
|
|
28
|
-
stateExpiredHandlers: StateExpiredHandler[];
|
|
29
|
-
};
|
package/dist/error.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
declare abstract class BaseError<Type extends string> extends Error {
|
|
2
|
-
readonly type: Type;
|
|
3
|
-
readonly message: string;
|
|
4
|
-
readonly error?: Error | undefined;
|
|
5
|
-
constructor(type: Type, message: string, error?: Error | undefined);
|
|
6
|
-
toJSON(): {
|
|
7
|
-
type: Type;
|
|
8
|
-
message: string;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
type BadRequestType = 'BadRequest';
|
|
12
|
-
/**
|
|
13
|
-
* A bad request error occurred
|
|
14
|
-
*/
|
|
15
|
-
export declare class BadRequestError extends BaseError<BadRequestType> {
|
|
16
|
-
constructor(message: string, error?: Error);
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Conversation, Message, User } from '@botpress/client';
|
|
2
|
-
import { Axios as AxiosInstance } from 'axios';
|
|
3
|
-
import type { IntegrationContext } from './context';
|
|
4
|
-
import type { ActionPayload, CreateConversationPayload, CreateUserPayload, MessagePayload, RegisterPayload, UnregisterPayload, WebhookPayload } from './implementation';
|
|
5
|
-
type Props<T = any> = {
|
|
6
|
-
url: string;
|
|
7
|
-
data: T;
|
|
8
|
-
} & Omit<IntegrationContext, 'operation'>;
|
|
9
|
-
/**
|
|
10
|
-
* @description Meant to query your integration server directly (e.g. without going through the Botpress API)
|
|
11
|
-
*/
|
|
12
|
-
export declare class IntegrationClient {
|
|
13
|
-
private axios;
|
|
14
|
-
constructor(axiosInstance?: AxiosInstance);
|
|
15
|
-
actionTriggered: (props: Props<ActionPayload<string, any>>) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
16
|
-
messageCreated: (props: Props<MessagePayload<any, Message, Conversation, User>>) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
17
|
-
register: (props: Props<RegisterPayload>) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
18
|
-
unregister: (props: Props<UnregisterPayload>) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
19
|
-
webhookReceived: (props: Props<WebhookPayload>) => Promise<import("axios").AxiosResponse<unknown, any>>;
|
|
20
|
-
createUser: (props: Props<CreateUserPayload>) => Promise<import("axios").AxiosResponse<{
|
|
21
|
-
user: {
|
|
22
|
-
id: User['id'];
|
|
23
|
-
};
|
|
24
|
-
}, any>>;
|
|
25
|
-
createConversation: (props: Props<CreateConversationPayload>) => Promise<import("axios").AxiosResponse<{
|
|
26
|
-
conversation: {
|
|
27
|
-
id: Conversation['id'];
|
|
28
|
-
};
|
|
29
|
-
}, any>>;
|
|
30
|
-
}
|
|
31
|
-
export declare function formatIntegrationHeaders(ctx: IntegrationContext): {
|
|
32
|
-
"x-bot-id": string;
|
|
33
|
-
"x-bp-operation": "register" | "unregister" | "ping" | "message_created" | "webhook_received" | "action_triggered" | "create_user" | "create_conversation";
|
|
34
|
-
"x-bot-user-id": string;
|
|
35
|
-
"x-integration-id": string;
|
|
36
|
-
"x-webhook-id": string;
|
|
37
|
-
"x-bp-configuration": string;
|
|
38
|
-
};
|
|
39
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const runtimeErrorSchema: z.ZodObject<{
|
|
3
|
-
code: z.ZodLiteral<400>;
|
|
4
|
-
type: z.ZodLiteral<"Runtime">;
|
|
5
|
-
message: z.ZodString;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
code: 400;
|
|
8
|
-
message: string;
|
|
9
|
-
type: "Runtime";
|
|
10
|
-
}, {
|
|
11
|
-
code: 400;
|
|
12
|
-
message: string;
|
|
13
|
-
type: "Runtime";
|
|
14
|
-
}>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
import zodToJsonSchema from 'zod-to-json-schema';
|
|
3
|
-
export type SchemaOptions<T> = {
|
|
4
|
-
title: string;
|
|
5
|
-
examples: T[];
|
|
6
|
-
};
|
|
7
|
-
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
8
|
-
export type UiDefinition<TSchema extends z.ZodObject<any>> = IsEmptyObject<z.infer<TSchema>> extends true ? Record<string, never> : {
|
|
9
|
-
[K in keyof z.infer<TSchema>]: Partial<SchemaOptions<z.infer<TSchema>[K]>>;
|
|
10
|
-
};
|
|
11
|
-
export type SchemaDefinition<TSchema extends z.ZodObject<any>> = {
|
|
12
|
-
schema: TSchema;
|
|
13
|
-
ui?: Partial<UiDefinition<TSchema>>;
|
|
14
|
-
};
|
|
15
|
-
export declare function schemaDefinitionToJsonSchema(definition: SchemaDefinition<z.ZodObject<any>>): ReturnType<typeof zodToJsonSchema>;
|
|
16
|
-
export {};
|