@botpress/sdk 0.0.5
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.d.ts +25 -0
- package/dist/bot/context.d.ts +9 -0
- package/dist/bot/implementation.d.ts +50 -0
- package/dist/bot/index.d.ts +3 -0
- package/dist/bot/server.d.ts +3 -0
- package/dist/bot/state.d.ts +29 -0
- package/dist/const.d.ts +7 -0
- package/dist/error.d.ts +18 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +7 -0
- package/dist/integration/client.d.ts +39 -0
- package/dist/integration/context.d.ts +11 -0
- package/dist/integration/definition.d.ts +465 -0
- package/dist/integration/implementation.d.ts +91 -0
- package/dist/integration/index.d.ts +5 -0
- package/dist/integration/server.d.ts +12 -0
- package/dist/log.d.ts +7 -0
- package/dist/message.d.ts +223 -0
- package/dist/serve.d.ts +18 -0
- package/package.json +27 -0
- package/readme.md +62 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { 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<any, 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 {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const integrationOperationSchema: z.ZodEnum<["webhook_received", "message_created", "action_triggered", "register", "unregister", "ping", "create_user", "create_conversation"]>;
|
|
3
|
+
export type IntegrationOperation = z.infer<typeof integrationOperationSchema>;
|
|
4
|
+
export type IntegrationContext<Configuration = any> = {
|
|
5
|
+
botId: string;
|
|
6
|
+
botUserId: string;
|
|
7
|
+
integrationId: string;
|
|
8
|
+
webhookId: string;
|
|
9
|
+
operation: IntegrationOperation;
|
|
10
|
+
configuration: Configuration;
|
|
11
|
+
};
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import type { Merge } from 'type-fest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const schemaSchema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
4
|
+
export declare const configurationDefinitionSchema: z.ZodObject<{
|
|
5
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
schema: {};
|
|
8
|
+
}, {
|
|
9
|
+
schema: {};
|
|
10
|
+
}>;
|
|
11
|
+
export declare const eventDefinitionSchema: z.ZodObject<{
|
|
12
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
schema: {};
|
|
15
|
+
}, {
|
|
16
|
+
schema: {};
|
|
17
|
+
}>;
|
|
18
|
+
export declare const actionDefinitionSchema: z.ZodObject<{
|
|
19
|
+
input: z.ZodObject<{
|
|
20
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
schema: {};
|
|
23
|
+
}, {
|
|
24
|
+
schema: {};
|
|
25
|
+
}>;
|
|
26
|
+
output: z.ZodObject<{
|
|
27
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
schema: {};
|
|
30
|
+
}, {
|
|
31
|
+
schema: {};
|
|
32
|
+
}>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
input: {
|
|
35
|
+
schema: {};
|
|
36
|
+
};
|
|
37
|
+
output: {
|
|
38
|
+
schema: {};
|
|
39
|
+
};
|
|
40
|
+
}, {
|
|
41
|
+
input: {
|
|
42
|
+
schema: {};
|
|
43
|
+
};
|
|
44
|
+
output: {
|
|
45
|
+
schema: {};
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
export declare const messageDefinitionSchema: z.ZodObject<{
|
|
49
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
schema: {};
|
|
52
|
+
}, {
|
|
53
|
+
schema: {};
|
|
54
|
+
}>;
|
|
55
|
+
export declare const tagsDefinitionSchema: z.ZodObject<{
|
|
56
|
+
conversations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
57
|
+
users: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
58
|
+
messages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
conversations?: string[] | undefined;
|
|
61
|
+
users?: string[] | undefined;
|
|
62
|
+
messages?: string[] | undefined;
|
|
63
|
+
}, {
|
|
64
|
+
conversations?: string[] | undefined;
|
|
65
|
+
users?: string[] | undefined;
|
|
66
|
+
messages?: string[] | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
export declare const channelDefinitionSchema: z.ZodObject<{
|
|
69
|
+
tags: z.ZodOptional<z.ZodObject<Omit<{
|
|
70
|
+
conversations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
71
|
+
users: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
72
|
+
messages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
73
|
+
}, "users">, "strip", z.ZodTypeAny, {
|
|
74
|
+
conversations?: string[] | undefined;
|
|
75
|
+
messages?: string[] | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
conversations?: string[] | undefined;
|
|
78
|
+
messages?: string[] | undefined;
|
|
79
|
+
}>>;
|
|
80
|
+
messages: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
81
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
schema: {};
|
|
84
|
+
}, {
|
|
85
|
+
schema: {};
|
|
86
|
+
}>>, Record<string, {
|
|
87
|
+
schema: {};
|
|
88
|
+
}>, Record<string, {
|
|
89
|
+
schema: {};
|
|
90
|
+
}>>;
|
|
91
|
+
conversation: z.ZodOptional<z.ZodObject<{
|
|
92
|
+
creation: z.ZodObject<{
|
|
93
|
+
enabled: z.ZodBoolean;
|
|
94
|
+
requiredTags: z.ZodArray<z.ZodString, "many">;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
requiredTags: string[];
|
|
98
|
+
}, {
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
requiredTags: string[];
|
|
101
|
+
}>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
creation: {
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
requiredTags: string[];
|
|
106
|
+
};
|
|
107
|
+
}, {
|
|
108
|
+
creation: {
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
requiredTags: string[];
|
|
111
|
+
};
|
|
112
|
+
}>>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
conversation?: {
|
|
115
|
+
creation: {
|
|
116
|
+
enabled: boolean;
|
|
117
|
+
requiredTags: string[];
|
|
118
|
+
};
|
|
119
|
+
} | undefined;
|
|
120
|
+
tags?: {
|
|
121
|
+
conversations?: string[] | undefined;
|
|
122
|
+
messages?: string[] | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
messages: Record<string, {
|
|
125
|
+
schema: {};
|
|
126
|
+
}>;
|
|
127
|
+
}, {
|
|
128
|
+
conversation?: {
|
|
129
|
+
creation: {
|
|
130
|
+
enabled: boolean;
|
|
131
|
+
requiredTags: string[];
|
|
132
|
+
};
|
|
133
|
+
} | undefined;
|
|
134
|
+
tags?: {
|
|
135
|
+
conversations?: string[] | undefined;
|
|
136
|
+
messages?: string[] | undefined;
|
|
137
|
+
} | undefined;
|
|
138
|
+
messages: Record<string, {
|
|
139
|
+
schema: {};
|
|
140
|
+
}>;
|
|
141
|
+
}>;
|
|
142
|
+
export declare const stateDefinitionSchema: z.ZodObject<{
|
|
143
|
+
type: z.ZodUnion<[z.ZodLiteral<"integration">, z.ZodLiteral<"conversation">, z.ZodLiteral<"user">]>;
|
|
144
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
145
|
+
}, "strip", z.ZodTypeAny, {
|
|
146
|
+
type: "user" | "conversation" | "integration";
|
|
147
|
+
schema: {};
|
|
148
|
+
}, {
|
|
149
|
+
type: "user" | "conversation" | "integration";
|
|
150
|
+
schema: {};
|
|
151
|
+
}>;
|
|
152
|
+
export declare const integrationDefinitionSchema: z.ZodObject<{
|
|
153
|
+
name: z.ZodString;
|
|
154
|
+
version: z.ZodString;
|
|
155
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
156
|
+
title: z.ZodOptional<z.ZodString>;
|
|
157
|
+
description: z.ZodOptional<z.ZodString>;
|
|
158
|
+
tags: z.ZodOptional<z.ZodObject<Pick<{
|
|
159
|
+
conversations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
160
|
+
users: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
161
|
+
messages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
162
|
+
}, "users">, "strip", z.ZodTypeAny, {
|
|
163
|
+
users?: string[] | undefined;
|
|
164
|
+
}, {
|
|
165
|
+
users?: string[] | undefined;
|
|
166
|
+
}>>;
|
|
167
|
+
configuration: z.ZodOptional<z.ZodObject<{
|
|
168
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
schema: {};
|
|
171
|
+
}, {
|
|
172
|
+
schema: {};
|
|
173
|
+
}>>;
|
|
174
|
+
events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
175
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
schema: {};
|
|
178
|
+
}, {
|
|
179
|
+
schema: {};
|
|
180
|
+
}>>>;
|
|
181
|
+
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
182
|
+
input: z.ZodObject<{
|
|
183
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
184
|
+
}, "strip", z.ZodTypeAny, {
|
|
185
|
+
schema: {};
|
|
186
|
+
}, {
|
|
187
|
+
schema: {};
|
|
188
|
+
}>;
|
|
189
|
+
output: z.ZodObject<{
|
|
190
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
191
|
+
}, "strip", z.ZodTypeAny, {
|
|
192
|
+
schema: {};
|
|
193
|
+
}, {
|
|
194
|
+
schema: {};
|
|
195
|
+
}>;
|
|
196
|
+
}, "strip", z.ZodTypeAny, {
|
|
197
|
+
input: {
|
|
198
|
+
schema: {};
|
|
199
|
+
};
|
|
200
|
+
output: {
|
|
201
|
+
schema: {};
|
|
202
|
+
};
|
|
203
|
+
}, {
|
|
204
|
+
input: {
|
|
205
|
+
schema: {};
|
|
206
|
+
};
|
|
207
|
+
output: {
|
|
208
|
+
schema: {};
|
|
209
|
+
};
|
|
210
|
+
}>>>;
|
|
211
|
+
channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
212
|
+
tags: z.ZodOptional<z.ZodObject<Omit<{
|
|
213
|
+
conversations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
214
|
+
users: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
215
|
+
messages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
216
|
+
}, "users">, "strip", z.ZodTypeAny, {
|
|
217
|
+
conversations?: string[] | undefined;
|
|
218
|
+
messages?: string[] | undefined;
|
|
219
|
+
}, {
|
|
220
|
+
conversations?: string[] | undefined;
|
|
221
|
+
messages?: string[] | undefined;
|
|
222
|
+
}>>;
|
|
223
|
+
messages: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
224
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
225
|
+
}, "strip", z.ZodTypeAny, {
|
|
226
|
+
schema: {};
|
|
227
|
+
}, {
|
|
228
|
+
schema: {};
|
|
229
|
+
}>>, Record<string, {
|
|
230
|
+
schema: {};
|
|
231
|
+
}>, Record<string, {
|
|
232
|
+
schema: {};
|
|
233
|
+
}>>;
|
|
234
|
+
conversation: z.ZodOptional<z.ZodObject<{
|
|
235
|
+
creation: z.ZodObject<{
|
|
236
|
+
enabled: z.ZodBoolean;
|
|
237
|
+
requiredTags: z.ZodArray<z.ZodString, "many">;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
enabled: boolean;
|
|
240
|
+
requiredTags: string[];
|
|
241
|
+
}, {
|
|
242
|
+
enabled: boolean;
|
|
243
|
+
requiredTags: string[];
|
|
244
|
+
}>;
|
|
245
|
+
}, "strip", z.ZodTypeAny, {
|
|
246
|
+
creation: {
|
|
247
|
+
enabled: boolean;
|
|
248
|
+
requiredTags: string[];
|
|
249
|
+
};
|
|
250
|
+
}, {
|
|
251
|
+
creation: {
|
|
252
|
+
enabled: boolean;
|
|
253
|
+
requiredTags: string[];
|
|
254
|
+
};
|
|
255
|
+
}>>;
|
|
256
|
+
}, "strip", z.ZodTypeAny, {
|
|
257
|
+
conversation?: {
|
|
258
|
+
creation: {
|
|
259
|
+
enabled: boolean;
|
|
260
|
+
requiredTags: string[];
|
|
261
|
+
};
|
|
262
|
+
} | undefined;
|
|
263
|
+
tags?: {
|
|
264
|
+
conversations?: string[] | undefined;
|
|
265
|
+
messages?: string[] | undefined;
|
|
266
|
+
} | undefined;
|
|
267
|
+
messages: Record<string, {
|
|
268
|
+
schema: {};
|
|
269
|
+
}>;
|
|
270
|
+
}, {
|
|
271
|
+
conversation?: {
|
|
272
|
+
creation: {
|
|
273
|
+
enabled: boolean;
|
|
274
|
+
requiredTags: string[];
|
|
275
|
+
};
|
|
276
|
+
} | undefined;
|
|
277
|
+
tags?: {
|
|
278
|
+
conversations?: string[] | undefined;
|
|
279
|
+
messages?: string[] | undefined;
|
|
280
|
+
} | undefined;
|
|
281
|
+
messages: Record<string, {
|
|
282
|
+
schema: {};
|
|
283
|
+
}>;
|
|
284
|
+
}>>>;
|
|
285
|
+
states: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
286
|
+
type: z.ZodUnion<[z.ZodLiteral<"integration">, z.ZodLiteral<"conversation">, z.ZodLiteral<"user">]>;
|
|
287
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, {}, {}>;
|
|
288
|
+
}, "strip", z.ZodTypeAny, {
|
|
289
|
+
type: "user" | "conversation" | "integration";
|
|
290
|
+
schema: {};
|
|
291
|
+
}, {
|
|
292
|
+
type: "user" | "conversation" | "integration";
|
|
293
|
+
schema: {};
|
|
294
|
+
}>>>;
|
|
295
|
+
user: z.ZodOptional<z.ZodObject<{
|
|
296
|
+
creation: z.ZodObject<{
|
|
297
|
+
enabled: z.ZodBoolean;
|
|
298
|
+
requiredTags: z.ZodArray<z.ZodString, "many">;
|
|
299
|
+
}, "strip", z.ZodTypeAny, {
|
|
300
|
+
enabled: boolean;
|
|
301
|
+
requiredTags: string[];
|
|
302
|
+
}, {
|
|
303
|
+
enabled: boolean;
|
|
304
|
+
requiredTags: string[];
|
|
305
|
+
}>;
|
|
306
|
+
}, "strip", z.ZodTypeAny, {
|
|
307
|
+
creation: {
|
|
308
|
+
enabled: boolean;
|
|
309
|
+
requiredTags: string[];
|
|
310
|
+
};
|
|
311
|
+
}, {
|
|
312
|
+
creation: {
|
|
313
|
+
enabled: boolean;
|
|
314
|
+
requiredTags: string[];
|
|
315
|
+
};
|
|
316
|
+
}>>;
|
|
317
|
+
public: z.ZodOptional<z.ZodBoolean>;
|
|
318
|
+
}, "strip", z.ZodTypeAny, {
|
|
319
|
+
user?: {
|
|
320
|
+
creation: {
|
|
321
|
+
enabled: boolean;
|
|
322
|
+
requiredTags: string[];
|
|
323
|
+
};
|
|
324
|
+
} | undefined;
|
|
325
|
+
configuration?: {
|
|
326
|
+
schema: {};
|
|
327
|
+
} | undefined;
|
|
328
|
+
tags?: {
|
|
329
|
+
users?: string[] | undefined;
|
|
330
|
+
} | undefined;
|
|
331
|
+
actions?: Record<string, {
|
|
332
|
+
input: {
|
|
333
|
+
schema: {};
|
|
334
|
+
};
|
|
335
|
+
output: {
|
|
336
|
+
schema: {};
|
|
337
|
+
};
|
|
338
|
+
}> | undefined;
|
|
339
|
+
channels?: Record<string, {
|
|
340
|
+
conversation?: {
|
|
341
|
+
creation: {
|
|
342
|
+
enabled: boolean;
|
|
343
|
+
requiredTags: string[];
|
|
344
|
+
};
|
|
345
|
+
} | undefined;
|
|
346
|
+
tags?: {
|
|
347
|
+
conversations?: string[] | undefined;
|
|
348
|
+
messages?: string[] | undefined;
|
|
349
|
+
} | undefined;
|
|
350
|
+
messages: Record<string, {
|
|
351
|
+
schema: {};
|
|
352
|
+
}>;
|
|
353
|
+
}> | undefined;
|
|
354
|
+
icon?: string | undefined;
|
|
355
|
+
title?: string | undefined;
|
|
356
|
+
description?: string | undefined;
|
|
357
|
+
events?: Record<string, {
|
|
358
|
+
schema: {};
|
|
359
|
+
}> | undefined;
|
|
360
|
+
states?: Record<string, {
|
|
361
|
+
type: "user" | "conversation" | "integration";
|
|
362
|
+
schema: {};
|
|
363
|
+
}> | undefined;
|
|
364
|
+
public?: boolean | undefined;
|
|
365
|
+
name: string;
|
|
366
|
+
version: string;
|
|
367
|
+
}, {
|
|
368
|
+
user?: {
|
|
369
|
+
creation: {
|
|
370
|
+
enabled: boolean;
|
|
371
|
+
requiredTags: string[];
|
|
372
|
+
};
|
|
373
|
+
} | undefined;
|
|
374
|
+
configuration?: {
|
|
375
|
+
schema: {};
|
|
376
|
+
} | undefined;
|
|
377
|
+
tags?: {
|
|
378
|
+
users?: string[] | undefined;
|
|
379
|
+
} | undefined;
|
|
380
|
+
actions?: Record<string, {
|
|
381
|
+
input: {
|
|
382
|
+
schema: {};
|
|
383
|
+
};
|
|
384
|
+
output: {
|
|
385
|
+
schema: {};
|
|
386
|
+
};
|
|
387
|
+
}> | undefined;
|
|
388
|
+
channels?: Record<string, {
|
|
389
|
+
conversation?: {
|
|
390
|
+
creation: {
|
|
391
|
+
enabled: boolean;
|
|
392
|
+
requiredTags: string[];
|
|
393
|
+
};
|
|
394
|
+
} | undefined;
|
|
395
|
+
tags?: {
|
|
396
|
+
conversations?: string[] | undefined;
|
|
397
|
+
messages?: string[] | undefined;
|
|
398
|
+
} | undefined;
|
|
399
|
+
messages: Record<string, {
|
|
400
|
+
schema: {};
|
|
401
|
+
}>;
|
|
402
|
+
}> | undefined;
|
|
403
|
+
icon?: string | undefined;
|
|
404
|
+
title?: string | undefined;
|
|
405
|
+
description?: string | undefined;
|
|
406
|
+
events?: Record<string, {
|
|
407
|
+
schema: {};
|
|
408
|
+
}> | undefined;
|
|
409
|
+
states?: Record<string, {
|
|
410
|
+
type: "user" | "conversation" | "integration";
|
|
411
|
+
schema: {};
|
|
412
|
+
}> | undefined;
|
|
413
|
+
public?: boolean | undefined;
|
|
414
|
+
name: string;
|
|
415
|
+
version: string;
|
|
416
|
+
}>;
|
|
417
|
+
export type ConfigurationDefinition = z.infer<typeof configurationDefinitionSchema>;
|
|
418
|
+
export type EventDefinition = z.infer<typeof eventDefinitionSchema>;
|
|
419
|
+
export type TagDefinition = z.infer<typeof tagsDefinitionSchema>;
|
|
420
|
+
export type ChannelDefinition = z.infer<typeof channelDefinitionSchema>;
|
|
421
|
+
export type ActionDefinition = z.infer<typeof actionDefinitionSchema>;
|
|
422
|
+
export type MessageDefinition = z.infer<typeof messageDefinitionSchema>;
|
|
423
|
+
export type StateDefinition = z.infer<typeof stateDefinitionSchema>;
|
|
424
|
+
type IntegrationDefinitionOutput = z.infer<typeof integrationDefinitionSchema>;
|
|
425
|
+
export type IntegrationDefinitionProps<T = z.ZodSchema<any>> = Omit<IntegrationDefinitionOutput, 'configuration' | 'events' | 'actions' | 'channels' | 'states'> & {
|
|
426
|
+
configuration?: Merge<ConfigurationDefinition, {
|
|
427
|
+
schema: T;
|
|
428
|
+
}>;
|
|
429
|
+
events?: Record<string, Merge<EventDefinition, {
|
|
430
|
+
schema: T;
|
|
431
|
+
}>>;
|
|
432
|
+
actions?: Record<string, Merge<ActionDefinition, {
|
|
433
|
+
input: {
|
|
434
|
+
schema: T;
|
|
435
|
+
};
|
|
436
|
+
output: {
|
|
437
|
+
schema: T;
|
|
438
|
+
};
|
|
439
|
+
}>>;
|
|
440
|
+
channels?: Record<string, Merge<ChannelDefinition, {
|
|
441
|
+
messages: Record<string, Merge<MessageDefinition, {
|
|
442
|
+
schema: T;
|
|
443
|
+
}>>;
|
|
444
|
+
}>>;
|
|
445
|
+
states?: Record<string, Merge<StateDefinition, {
|
|
446
|
+
schema: T;
|
|
447
|
+
}>>;
|
|
448
|
+
};
|
|
449
|
+
export declare class IntegrationDefinition {
|
|
450
|
+
readonly name: IntegrationDefinitionOutput['name'];
|
|
451
|
+
readonly version: IntegrationDefinitionOutput['version'];
|
|
452
|
+
readonly icon: IntegrationDefinitionOutput['icon'];
|
|
453
|
+
readonly title: IntegrationDefinitionOutput['title'];
|
|
454
|
+
readonly description: IntegrationDefinitionOutput['description'];
|
|
455
|
+
readonly tags: IntegrationDefinitionOutput['tags'];
|
|
456
|
+
readonly configuration: IntegrationDefinitionOutput['configuration'];
|
|
457
|
+
readonly events: IntegrationDefinitionOutput['events'];
|
|
458
|
+
readonly actions: IntegrationDefinitionOutput['actions'];
|
|
459
|
+
readonly channels: IntegrationDefinitionOutput['channels'];
|
|
460
|
+
readonly states: IntegrationDefinitionOutput['states'];
|
|
461
|
+
readonly user: IntegrationDefinitionOutput['user'];
|
|
462
|
+
readonly public: IntegrationDefinitionOutput['public'];
|
|
463
|
+
constructor(props: IntegrationDefinitionProps);
|
|
464
|
+
}
|
|
465
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Client, Conversation, Message, User } from '@botpress/client';
|
|
2
|
+
import { Request, Response } from '../serve';
|
|
3
|
+
import type { IntegrationContext } from './context';
|
|
4
|
+
import { integrationHandler } from './server';
|
|
5
|
+
type IntegrationProps<Configuration> = {
|
|
6
|
+
ctx: IntegrationContext<Configuration>;
|
|
7
|
+
client: Client;
|
|
8
|
+
};
|
|
9
|
+
export type RegisterPayload = {
|
|
10
|
+
webhookUrl: string;
|
|
11
|
+
};
|
|
12
|
+
export type UnregisterPayload = {
|
|
13
|
+
webhookUrl: string;
|
|
14
|
+
};
|
|
15
|
+
export type WebhookPayload = {
|
|
16
|
+
req: Request;
|
|
17
|
+
};
|
|
18
|
+
export type ActionPayload<T, I> = {
|
|
19
|
+
type: T;
|
|
20
|
+
input: I;
|
|
21
|
+
};
|
|
22
|
+
export type EventPayload<E> = {
|
|
23
|
+
event: E;
|
|
24
|
+
};
|
|
25
|
+
export type CreateUserPayload = {
|
|
26
|
+
tags: Tags;
|
|
27
|
+
};
|
|
28
|
+
export type CreateConversationPayload = {
|
|
29
|
+
channel: string;
|
|
30
|
+
tags: Tags;
|
|
31
|
+
};
|
|
32
|
+
type Tags = {
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
};
|
|
35
|
+
export type AckFunction = (props: {
|
|
36
|
+
tags: Tags;
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
export type MessagePayload<P, M, C, U> = {
|
|
39
|
+
payload: P;
|
|
40
|
+
conversation: C;
|
|
41
|
+
message: M;
|
|
42
|
+
user: U;
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
45
|
+
type ActionDefinitions = {
|
|
46
|
+
[actionType: string]: {
|
|
47
|
+
input: any;
|
|
48
|
+
output: any;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
type ChannelDefinitions = {
|
|
52
|
+
[channelName: string]: MessageDefinitions;
|
|
53
|
+
};
|
|
54
|
+
type EventDefinitions = {
|
|
55
|
+
[eventName: string]: any;
|
|
56
|
+
};
|
|
57
|
+
type MessageDefinitions = {
|
|
58
|
+
[messageType: string]: any;
|
|
59
|
+
};
|
|
60
|
+
type ActionFunctions<Configuration, A extends ActionDefinitions> = {
|
|
61
|
+
[actionType in keyof A]: (props: IntegrationProps<Configuration> & ActionPayload<actionType, A[actionType]['input']>) => Promise<A[actionType]['output']>;
|
|
62
|
+
};
|
|
63
|
+
type MessageHandlerProps = {
|
|
64
|
+
ack: AckFunction;
|
|
65
|
+
};
|
|
66
|
+
export type ChannelFunctions<Configuration, C extends ChannelDefinitions> = {
|
|
67
|
+
[channelName in keyof C]: {
|
|
68
|
+
messages: {
|
|
69
|
+
[messageType in keyof C[channelName]]: (props: IntegrationProps<Configuration> & MessagePayload<C[channelName][messageType], Message, Conversation, User> & MessageHandlerProps) => Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export type IntegrationImplementationProps<Configuration = any, Actions extends ActionDefinitions = any, Channels extends ChannelDefinitions = any, _Events extends EventDefinitions = any> = {
|
|
74
|
+
register: (props: IntegrationProps<Configuration> & RegisterPayload) => Promise<void>;
|
|
75
|
+
unregister: (props: IntegrationProps<Configuration> & UnregisterPayload) => Promise<void>;
|
|
76
|
+
handler: (props: IntegrationProps<Configuration> & WebhookPayload) => Promise<Response | void>;
|
|
77
|
+
createUser?: (props: IntegrationProps<Configuration> & CreateUserPayload) => Promise<Response | void>;
|
|
78
|
+
createConversation?: (props: IntegrationProps<Configuration> & CreateConversationPayload) => Promise<Response | void>;
|
|
79
|
+
actions: ActionFunctions<Configuration, Actions>;
|
|
80
|
+
channels: ChannelFunctions<Configuration, Channels>;
|
|
81
|
+
};
|
|
82
|
+
export declare class IntegrationImplementation<Configuration = any, Actions extends ActionDefinitions = any, Channels extends ChannelDefinitions = any, Events extends EventDefinitions = any> {
|
|
83
|
+
readonly actions: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['actions'];
|
|
84
|
+
readonly channels: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['channels'];
|
|
85
|
+
readonly register: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['register'];
|
|
86
|
+
readonly unregister: IntegrationImplementationProps<Configuration, Actions, Channels, Events>['unregister'];
|
|
87
|
+
readonly handler: ReturnType<typeof integrationHandler>;
|
|
88
|
+
readonly start: (port?: number) => Promise<void>;
|
|
89
|
+
constructor(props: IntegrationImplementationProps<Configuration, Actions, Channels, Events>);
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Conversation, Message, User } from '@botpress/client';
|
|
2
|
+
import { Request, Response } from '../serve';
|
|
3
|
+
import type { IntegrationImplementationProps as Integration } from './implementation';
|
|
4
|
+
export declare const serveIntegration: (integration: Integration, port?: number) => Promise<void>;
|
|
5
|
+
export declare const integrationHandler: (integration: Integration) => (req: Request) => Promise<Response | void>;
|
|
6
|
+
export type MessageCreatedPayload = {
|
|
7
|
+
conversation: Conversation;
|
|
8
|
+
user: User;
|
|
9
|
+
message: Message;
|
|
10
|
+
payload: any;
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
package/dist/log.d.ts
ADDED