Skip to content

Commit dae7c52

Browse files
feat(client): bump api version and support get or set state operation (botpress#13011)
1 parent 5493259 commit dae7c52

File tree

12 files changed

+112
-70
lines changed

12 files changed

+112
-70
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ __snapshots__
88
.ignore.me.*
99
.env
1010
.botpress
11-
.botpresshome
11+
.botpresshome
12+
.botpresshome.*

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ gen
2121
dist
2222
.botpress
2323
.botpresshome
24+
.botpresshome.*

packages/cli/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/cli",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Botpress CLI",
55
"scripts": {
66
"build": "pnpm run bundle && pnpm run template:gen",
@@ -20,7 +20,7 @@
2020
},
2121
"main": "dist/index.js",
2222
"dependencies": {
23-
"@botpress/client": "0.11.4",
23+
"@botpress/client": "0.11.5",
2424
"@bpinternal/const": "^0.0.20",
2525
"@bpinternal/tunnel": "^0.1.1",
2626
"@bpinternal/yargs-extra": "^0.0.3",
@@ -49,7 +49,7 @@
4949
"zod": "^3.20.6"
5050
},
5151
"devDependencies": {
52-
"@botpress/sdk": "0.6.0",
52+
"@botpress/sdk": "0.6.1",
5353
"@bpinternal/log4bot": "^0.0.4",
5454
"@types/bluebird": "^3.5.38",
5555
"@types/json-schema": "^7.0.11",

packages/cli/templates/echo-bot/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"author": "",
99
"license": "MIT",
1010
"dependencies": {
11-
"@botpress/client": "0.11.4",
12-
"@botpress/sdk": "0.6.0",
11+
"@botpress/client": "0.11.5",
12+
"@botpress/sdk": "0.6.1",
1313
"zod": "^3.20.6"
1414
},
1515
"devDependencies": {

packages/cli/templates/empty-integration/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"author": "",
99
"license": "MIT",
1010
"dependencies": {
11-
"@botpress/client": "0.11.4",
12-
"@botpress/sdk": "0.6.0",
11+
"@botpress/client": "0.11.5",
12+
"@botpress/sdk": "0.6.1",
1313
"zod": "^3.20.6"
1414
},
1515
"devDependencies": {

packages/client/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/client",
3-
"version": "0.11.4",
3+
"version": "0.11.5",
44
"description": "Botpress Client",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.mjs",
@@ -21,7 +21,7 @@
2121
"type-fest": "^3.4.0"
2222
},
2323
"devDependencies": {
24-
"@botpress/api": "0.17.0",
24+
"@botpress/api": "0.18.0",
2525
"esbuild": "^0.16.12"
2626
}
2727
}

packages/sdk/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/sdk",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Botpress SDK",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
1414
"author": "",
1515
"license": "MIT",
1616
"dependencies": {
17-
"@botpress/client": "0.11.4",
17+
"@botpress/client": "0.11.5",
1818
"zod": "^3.20.6"
1919
},
2020
"devDependencies": {

packages/sdk/src/bot/client/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ export class BotSpecificClient<TBot extends BaseBot> {
3434
public updateUser: routes.UpdateUser<TBot> = (x) => this.client.updateUser(x)
3535
public deleteUser: routes.DeleteUser<TBot> = (x) => this.client.deleteUser(x)
3636

37-
public getState: routes.GetState<TBot> = (x) =>
38-
this.client.getState(x).then((y) => ({ state: { ...y.state, payload: y.state.payload as any } }))
39-
public setState: routes.SetState<TBot> = (x) =>
40-
this.client.setState(x).then((y) => ({ state: { ...y.state, payload: y.state.payload as any } }))
41-
public patchState: routes.PatchState<TBot> = (x) =>
42-
this.client.patchState(x).then((y) => ({ state: { ...y.state, payload: y.state.payload as any } }))
37+
public getState: routes.GetState<TBot> = ((x) =>
38+
this.client.getState(x).then((y) => ({ state: { ...y.state, payload: y.state.payload } }))) as routes.GetState<TBot>
39+
public setState: routes.SetState<TBot> = ((x) =>
40+
this.client.setState(x).then((y) => ({ state: { ...y.state, payload: y.state.payload } }))) as routes.SetState<TBot>
41+
public getOrSetState: routes.GetOrSetState<TBot> = ((x) =>
42+
this.client
43+
.getOrSetState(x)
44+
.then((y) => ({ state: { ...y.state, payload: y.state.payload } }))) as routes.GetOrSetState<TBot>
45+
public patchState: routes.PatchState<TBot> = ((x) =>
46+
this.client
47+
.patchState(x)
48+
.then((y) => ({ state: { ...y.state, payload: y.state.payload } }))) as routes.PatchState<TBot>
4349

4450
public callAction: routes.CallAction<TBot> = (x) => this.client.callAction(x)
4551

packages/sdk/src/bot/client/routes.ts

+17
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ export type SetState<TBot extends BaseBot> = <TState extends keyof TBot['states'
9090
>
9191
}>
9292

93+
export type GetOrSetState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(
94+
x: Merge<
95+
Arg<Client['getOrSetState']>,
96+
{
97+
name: Cast<TState, string> // TODO: use state name to infer state type (cannot be done until there is a bot.definition.ts file)
98+
payload: TBot['states'][TState]
99+
}
100+
>
101+
) => Promise<{
102+
state: Merge<
103+
Awaited<Res<Client['getOrSetState']>>['state'],
104+
{
105+
payload: TBot['states'][TState]
106+
}
107+
>
108+
}>
109+
93110
export type PatchState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(
94111
x: Merge<
95112
Arg<Client['patchState']>,

packages/sdk/src/integration/client/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export class IntegrationSpecificClient<TIntegration extends BaseIntegration> {
5555

5656
public getState: routes.GetState<TIntegration> = ((x) => this.client.getState(x)) as routes.GetState<TIntegration>
5757
public setState: routes.SetState<TIntegration> = ((x) => this.client.setState(x)) as routes.SetState<TIntegration>
58+
public getOrSetState: routes.GetOrSetState<TIntegration> = ((x) =>
59+
this.client.getOrSetState(x)) as routes.GetOrSetState<TIntegration>
5860
public patchState: routes.PatchState<TIntegration> = ((x) =>
5961
this.client.patchState(x)) as routes.PatchState<TIntegration>
6062

packages/sdk/src/integration/client/routes.ts

+10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ export type SetState<TIntegration extends BaseIntegration> = <TState extends key
235235
>
236236
) => Promise<StateResponse<TIntegration, TState>>
237237

238+
export type GetOrSetState<TIntegration extends BaseIntegration> = <TState extends keyof TIntegration['states']>(
239+
x: Merge<
240+
Arg<Client['getOrSetState']>,
241+
{
242+
name: Cast<TState, string> // TODO: use state name to infer state type
243+
payload: TIntegration['states'][TState]
244+
}
245+
>
246+
) => Promise<StateResponse<TIntegration, TState>>
247+
238248
export type PatchState<TIntegration extends BaseIntegration> = <TState extends keyof TIntegration['states']>(
239249
x: Merge<
240250
Arg<Client['patchState']>,

0 commit comments

Comments
 (0)