@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.
@@ -0,0 +1,223 @@
1
+ import { z } from 'zod';
2
+ export declare const defaults: {
3
+ readonly text: {
4
+ readonly schema: z.ZodObject<{
5
+ text: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ text: string;
8
+ }, {
9
+ text: string;
10
+ }>;
11
+ };
12
+ readonly markdown: {
13
+ readonly schema: z.ZodObject<{
14
+ markdown: z.ZodString;
15
+ }, "strip", z.ZodTypeAny, {
16
+ markdown: string;
17
+ }, {
18
+ markdown: string;
19
+ }>;
20
+ };
21
+ readonly image: {
22
+ readonly schema: z.ZodObject<{
23
+ imageUrl: z.ZodString;
24
+ }, "strip", z.ZodTypeAny, {
25
+ imageUrl: string;
26
+ }, {
27
+ imageUrl: string;
28
+ }>;
29
+ };
30
+ readonly audio: {
31
+ readonly schema: z.ZodObject<{
32
+ audioUrl: z.ZodString;
33
+ }, "strip", z.ZodTypeAny, {
34
+ audioUrl: string;
35
+ }, {
36
+ audioUrl: string;
37
+ }>;
38
+ };
39
+ readonly video: {
40
+ readonly schema: z.ZodObject<{
41
+ videoUrl: z.ZodString;
42
+ }, "strip", z.ZodTypeAny, {
43
+ videoUrl: string;
44
+ }, {
45
+ videoUrl: string;
46
+ }>;
47
+ };
48
+ readonly file: {
49
+ readonly schema: z.ZodObject<{
50
+ fileUrl: z.ZodString;
51
+ }, "strip", z.ZodTypeAny, {
52
+ fileUrl: string;
53
+ }, {
54
+ fileUrl: string;
55
+ }>;
56
+ };
57
+ readonly location: {
58
+ readonly schema: z.ZodObject<{
59
+ latitude: z.ZodNumber;
60
+ longitude: z.ZodNumber;
61
+ }, "strip", z.ZodTypeAny, {
62
+ latitude: number;
63
+ longitude: number;
64
+ }, {
65
+ latitude: number;
66
+ longitude: number;
67
+ }>;
68
+ };
69
+ readonly carousel: {
70
+ readonly schema: z.ZodObject<{
71
+ items: z.ZodArray<z.ZodObject<{
72
+ title: z.ZodString;
73
+ subtitle: z.ZodOptional<z.ZodString>;
74
+ imageUrl: z.ZodOptional<z.ZodString>;
75
+ actions: z.ZodArray<z.ZodObject<{
76
+ action: z.ZodEnum<["postback", "url", "say"]>;
77
+ label: z.ZodString;
78
+ value: z.ZodString;
79
+ }, "strip", z.ZodTypeAny, {
80
+ value: string;
81
+ action: "url" | "postback" | "say";
82
+ label: string;
83
+ }, {
84
+ value: string;
85
+ action: "url" | "postback" | "say";
86
+ label: string;
87
+ }>, "many">;
88
+ }, "strip", z.ZodTypeAny, {
89
+ imageUrl?: string | undefined;
90
+ subtitle?: string | undefined;
91
+ actions: {
92
+ value: string;
93
+ action: "url" | "postback" | "say";
94
+ label: string;
95
+ }[];
96
+ title: string;
97
+ }, {
98
+ imageUrl?: string | undefined;
99
+ subtitle?: string | undefined;
100
+ actions: {
101
+ value: string;
102
+ action: "url" | "postback" | "say";
103
+ label: string;
104
+ }[];
105
+ title: string;
106
+ }>, "many">;
107
+ }, "strip", z.ZodTypeAny, {
108
+ items: {
109
+ imageUrl?: string | undefined;
110
+ subtitle?: string | undefined;
111
+ actions: {
112
+ value: string;
113
+ action: "url" | "postback" | "say";
114
+ label: string;
115
+ }[];
116
+ title: string;
117
+ }[];
118
+ }, {
119
+ items: {
120
+ imageUrl?: string | undefined;
121
+ subtitle?: string | undefined;
122
+ actions: {
123
+ value: string;
124
+ action: "url" | "postback" | "say";
125
+ label: string;
126
+ }[];
127
+ title: string;
128
+ }[];
129
+ }>;
130
+ };
131
+ readonly card: {
132
+ readonly schema: z.ZodObject<{
133
+ title: z.ZodString;
134
+ subtitle: z.ZodOptional<z.ZodString>;
135
+ imageUrl: z.ZodOptional<z.ZodString>;
136
+ actions: z.ZodArray<z.ZodObject<{
137
+ action: z.ZodEnum<["postback", "url", "say"]>;
138
+ label: z.ZodString;
139
+ value: z.ZodString;
140
+ }, "strip", z.ZodTypeAny, {
141
+ value: string;
142
+ action: "url" | "postback" | "say";
143
+ label: string;
144
+ }, {
145
+ value: string;
146
+ action: "url" | "postback" | "say";
147
+ label: string;
148
+ }>, "many">;
149
+ }, "strip", z.ZodTypeAny, {
150
+ imageUrl?: string | undefined;
151
+ subtitle?: string | undefined;
152
+ actions: {
153
+ value: string;
154
+ action: "url" | "postback" | "say";
155
+ label: string;
156
+ }[];
157
+ title: string;
158
+ }, {
159
+ imageUrl?: string | undefined;
160
+ subtitle?: string | undefined;
161
+ actions: {
162
+ value: string;
163
+ action: "url" | "postback" | "say";
164
+ label: string;
165
+ }[];
166
+ title: string;
167
+ }>;
168
+ };
169
+ readonly dropdown: {
170
+ readonly schema: z.ZodObject<{
171
+ text: z.ZodString;
172
+ options: z.ZodArray<z.ZodObject<{
173
+ label: z.ZodString;
174
+ value: z.ZodString;
175
+ }, "strip", z.ZodTypeAny, {
176
+ value: string;
177
+ label: string;
178
+ }, {
179
+ value: string;
180
+ label: string;
181
+ }>, "many">;
182
+ }, "strip", z.ZodTypeAny, {
183
+ options: {
184
+ value: string;
185
+ label: string;
186
+ }[];
187
+ text: string;
188
+ }, {
189
+ options: {
190
+ value: string;
191
+ label: string;
192
+ }[];
193
+ text: string;
194
+ }>;
195
+ };
196
+ readonly choice: {
197
+ readonly schema: z.ZodObject<{
198
+ text: z.ZodString;
199
+ options: z.ZodArray<z.ZodObject<{
200
+ label: z.ZodString;
201
+ value: z.ZodString;
202
+ }, "strip", z.ZodTypeAny, {
203
+ value: string;
204
+ label: string;
205
+ }, {
206
+ value: string;
207
+ label: string;
208
+ }>, "many">;
209
+ }, "strip", z.ZodTypeAny, {
210
+ options: {
211
+ value: string;
212
+ label: string;
213
+ }[];
214
+ text: string;
215
+ }, {
216
+ options: {
217
+ value: string;
218
+ label: string;
219
+ }[];
220
+ text: string;
221
+ }>;
222
+ };
223
+ };
@@ -0,0 +1,18 @@
1
+ export type Request = {
2
+ body?: string;
3
+ path: string;
4
+ query: string;
5
+ method: string;
6
+ headers: {
7
+ [key: string]: string | undefined;
8
+ };
9
+ };
10
+ export type Response = {
11
+ body?: string;
12
+ headers?: {
13
+ [key: string]: string;
14
+ };
15
+ status?: number;
16
+ };
17
+ export type Handler = (req: Request) => Promise<Response | void>;
18
+ export declare function serve(handler: Handler, port?: number, callback?: (port: number) => void): Promise<void>;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@botpress/sdk",
3
+ "version": "0.0.5",
4
+ "description": "",
5
+ "main": "./src/index.ts",
6
+ "scripts": {
7
+ "build:type": "tsc --emitDeclarationOnly --declaration --target es2019 --module commonjs --moduleResolution node --lib es2019",
8
+ "build:index": "esbuild --bundle --platform=node --minify --sourcemap --outfile=dist/index.js src/index.ts",
9
+ "build": "pnpm build:type && pnpm build:index"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "@botpress/client": "0.0.6",
16
+ "axios": "0.27.2",
17
+ "radash": "^9.5.0",
18
+ "zod": "^3.20.6",
19
+ "zod-to-json-schema": "^3.20.1"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^18.11.17",
23
+ "type-fest": "^3.4.0",
24
+ "esbuild": "^0.16.10",
25
+ "typescript": "^4.9.4"
26
+ }
27
+ }
package/readme.md ADDED
@@ -0,0 +1,62 @@
1
+ # Botpress SDK
2
+
3
+ Official Botpress SDK for TypeScript. Made for building bots and integrations as code.
4
+
5
+ ## Disclaimer ⚠️
6
+
7
+ This package is still in development and is not ready for production use. Use it at your own risk.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install --save @botpress/sdk # for npm
13
+ yarn add @botpress/sdk # for yarn
14
+ pnpm add @botpress/sdk # for pnpm
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ 1. First, write your bot in a TypeScript file. For example, `src/index.ts`:
20
+
21
+ ```ts
22
+ import { Bot, messages } from '@botpress/sdk'
23
+
24
+ const bot = new Bot({})
25
+
26
+ bot.message('', async ({ message, client, ctx }) => {
27
+ log.info('Received message', message)
28
+
29
+ await client.createMessage({
30
+ conversationId: message.conversationId,
31
+ userId: ctx.botId,
32
+ tags: {},
33
+ type: 'text',
34
+ payload: {
35
+ text: `I'm a stub bot. You said: ${message.payload.text}`,
36
+ },
37
+ })
38
+ console.log('text message sent')
39
+ })
40
+
41
+ export default bot
42
+ ```
43
+
44
+ 2. Then, you can run it locally:
45
+
46
+ ```bash
47
+ bp serve --entry-point ./src/index.ts # using the botpress CLI
48
+
49
+ ts-node -e "import bot from './src'; void bot.serve()" # or using ts-node directly
50
+ ```
51
+
52
+ 3. Or, you can bundle it and deploy it to Botpress Cloud:
53
+
54
+ ```bash
55
+ bp deploy --entry-point ./src/index.ts # using the botpress CLI
56
+
57
+ # or, using esbuild and the Botpress API
58
+ esbuild --bundle --target=es2019 --platform=node --format=cjs --outfile=bundle.js ./src/index.ts
59
+ code=$(cat bundle.js)
60
+ # call the Botpress API using curl or any other HTTP client
61
+ # see https://botpress.com/docs/api/#bot-update-bot
62
+ ```