@botpress/sdk 4.0.0 → 4.0.1
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/.turbo/turbo-build.log +4 -4
- package/dist/bot/server/types.d.ts +0 -6
- package/dist/consts.d.ts +1 -0
- package/dist/fixtures.d.ts +26 -0
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +16 -16
- package/dist/index.mjs.map +4 -4
- package/dist/plugin/action-proxy/proxy.d.ts +2 -2
- package/dist/plugin/common/types.d.ts +6 -0
- package/dist/plugin/implementation.d.ts +2 -7
- package/dist/plugin/server/types.d.ts +3 -8
- package/dist/plugin/state-proxy/index.d.ts +2 -0
- package/dist/plugin/state-proxy/proxy.d.ts +5 -0
- package/dist/plugin/state-proxy/types.d.ts +25 -0
- package/dist/plugin/state-proxy/types.test.d.ts +1 -0
- package/dist/utils/type-utils.d.ts +4 -1
- package/package.json +2 -2
- package/readme.md +1 -48
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from '@botpress/client';
|
|
2
2
|
import { BotSpecificClient } from '../../bot';
|
|
3
|
-
import { BasePlugin,
|
|
3
|
+
import { BasePlugin, PluginRuntimeProps } from '../common';
|
|
4
4
|
import { ActionProxy } from './types';
|
|
5
|
-
export declare const proxyActions: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client,
|
|
5
|
+
export declare const proxyActions: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, props: PluginRuntimeProps<TPlugin>) => ActionProxy<TPlugin>;
|
|
@@ -38,4 +38,10 @@ export type PluginInterfaceExtension<TInterface extends BaseInterface = BaseInte
|
|
|
38
38
|
export type PluginInterfaceExtensions<TPlugin extends BasePlugin = BasePlugin> = {
|
|
39
39
|
[K in keyof TPlugin['interfaces']]: PluginInterfaceExtension<TPlugin['interfaces'][K]>;
|
|
40
40
|
};
|
|
41
|
+
export type PluginConfiguration<TPlugin extends BasePlugin> = TPlugin['configuration'];
|
|
42
|
+
export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
|
|
43
|
+
alias?: string;
|
|
44
|
+
configuration: PluginConfiguration<TPlugin>;
|
|
45
|
+
interfaces: PluginInterfaceExtensions<TPlugin>;
|
|
46
|
+
};
|
|
41
47
|
export {};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
|
|
2
2
|
import * as utils from '../utils';
|
|
3
|
-
import { BasePlugin,
|
|
4
|
-
import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap
|
|
3
|
+
import { BasePlugin, PluginRuntimeProps } from './common';
|
|
4
|
+
import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap } from './server/types';
|
|
5
5
|
export type PluginImplementationProps<TPlugin extends BasePlugin = BasePlugin> = {
|
|
6
6
|
actions: ActionHandlers<TPlugin>;
|
|
7
7
|
};
|
|
8
|
-
export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
|
|
9
|
-
alias?: string;
|
|
10
|
-
configuration: PluginConfiguration<TPlugin>;
|
|
11
|
-
interfaces: PluginInterfaceExtensions<TPlugin>;
|
|
12
|
-
};
|
|
13
8
|
export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugin> implements BotHandlers<TPlugin> {
|
|
14
9
|
readonly props: PluginImplementationProps<TPlugin>;
|
|
15
10
|
private _runtimeProps;
|
|
@@ -4,6 +4,7 @@ import * as workflowProxy from '../../bot/workflow-proxy';
|
|
|
4
4
|
import * as utils from '../../utils/type-utils';
|
|
5
5
|
import * as actionProxy from '../action-proxy';
|
|
6
6
|
import * as common from '../common';
|
|
7
|
+
import * as stateProxy from '../state-proxy';
|
|
7
8
|
type EnumeratePluginEvents<TPlugin extends common.BasePlugin> = bot.EnumerateEvents<TPlugin> & common.EnumerateInterfaceEvents<TPlugin>;
|
|
8
9
|
type _IncomingEvents<TPlugin extends common.BasePlugin> = {
|
|
9
10
|
[K in utils.StringKeys<EnumeratePluginEvents<TPlugin>>]: utils.Merge<client.Event, {
|
|
@@ -76,14 +77,14 @@ export type OutgoingCallActionResponses<TPlugin extends common.BasePlugin> = _Ou
|
|
|
76
77
|
'*': AnyOutgoingCallActionResponse<TPlugin>;
|
|
77
78
|
};
|
|
78
79
|
export type PluginClient<_TPlugin extends common.BasePlugin> = bot.BotSpecificClient<common.BasePlugin>;
|
|
79
|
-
export type PluginConfiguration<TPlugin extends common.BasePlugin> = TPlugin['configuration'];
|
|
80
80
|
export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
|
|
81
81
|
ctx: bot.BotContext;
|
|
82
82
|
logger: bot.BotLogger;
|
|
83
83
|
client: PluginClient<TPlugin>;
|
|
84
|
-
configuration: PluginConfiguration<TPlugin>;
|
|
84
|
+
configuration: common.PluginConfiguration<TPlugin>;
|
|
85
85
|
interfaces: common.PluginInterfaceExtensions<TPlugin>;
|
|
86
86
|
actions: actionProxy.ActionProxy<TPlugin>;
|
|
87
|
+
states: stateProxy.StateProxy<TPlugin>;
|
|
87
88
|
/**
|
|
88
89
|
* # EXPERIMENTAL
|
|
89
90
|
* This API is experimental and may change in the future.
|
|
@@ -96,12 +97,6 @@ export type MessagePayloads<TPlugin extends common.BasePlugin> = {
|
|
|
96
97
|
user: client.User;
|
|
97
98
|
conversation: client.Conversation;
|
|
98
99
|
event: client.Event;
|
|
99
|
-
states: {
|
|
100
|
-
[TState in utils.StringKeys<TPlugin['states']>]: {
|
|
101
|
-
type: 'user' | 'conversation' | 'bot';
|
|
102
|
-
payload: TPlugin['states'][TState];
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
100
|
};
|
|
106
101
|
};
|
|
107
102
|
export type MessageHandlers<TPlugin extends common.BasePlugin> = {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Client } from '@botpress/client';
|
|
2
|
+
import { BotSpecificClient } from '../../bot';
|
|
3
|
+
import { BasePlugin, PluginRuntimeProps } from '../common';
|
|
4
|
+
import { StateProxy } from './types';
|
|
5
|
+
export declare const proxyStates: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, props: PluginRuntimeProps<TPlugin>) => StateProxy<TPlugin>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as bot from '../../bot';
|
|
2
|
+
import * as utils from '../../utils/type-utils';
|
|
3
|
+
import { BasePlugin } from '../common';
|
|
4
|
+
type _EnumerateStates<TPlugin extends BasePlugin> = {
|
|
5
|
+
[TStateName in keyof TPlugin['states']]: TPlugin['states'][TStateName] & {
|
|
6
|
+
name: TStateName;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type _FilterStates<TPlugin extends BasePlugin, TStateType extends bot.StateType> = Extract<utils.ValueOf<_EnumerateStates<TPlugin>>, {
|
|
10
|
+
type: TStateType;
|
|
11
|
+
}>['name'];
|
|
12
|
+
type _GetStatePayload<TPlugin extends BasePlugin, TStateName extends string | number | symbol> = TPlugin['states'][utils.Cast<TStateName, keyof TPlugin['states']>]['payload'];
|
|
13
|
+
export type StateRepo<TPayload> = {
|
|
14
|
+
get: (id: string) => Promise<TPayload>;
|
|
15
|
+
set: (id: string, payload: TPayload) => Promise<void>;
|
|
16
|
+
getOrSet: (id: string, payload: TPayload) => Promise<TPayload>;
|
|
17
|
+
delete: (id: string) => Promise<void>;
|
|
18
|
+
patch: (id: string, payload: Partial<TPayload>) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export type StateProxy<TPlugin extends BasePlugin> = utils.Normalize<{
|
|
21
|
+
[TStateType in bot.StateType]: {
|
|
22
|
+
[TStateName in _FilterStates<TPlugin, TStateType>]: StateRepo<_GetStatePayload<TPlugin, TStateName>>;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -46,10 +46,13 @@ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) ex
|
|
|
46
46
|
export type ToSealedRecord<R extends Record<string, any>> = {
|
|
47
47
|
[K in keyof R as string extends K ? never : K]: R[K];
|
|
48
48
|
};
|
|
49
|
+
type NormalizeTuple<T> = T extends [...infer A] ? {
|
|
50
|
+
[K in keyof A]: Normalize<A[K]>;
|
|
51
|
+
} : never;
|
|
49
52
|
type NormalizeObject<T extends object> = T extends infer O ? {
|
|
50
53
|
[K in keyof O]: Normalize<O[K]>;
|
|
51
54
|
} : never;
|
|
52
|
-
export type Normalize<T> = T extends (...args: infer A) => infer R ? (...args:
|
|
55
|
+
export type Normalize<T> = T extends (...args: infer A) => infer R ? (...args: NormalizeTuple<A>) => Normalize<R> : T extends Array<infer E> ? Array<Normalize<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<Normalize<E>> : T extends Promise<infer R> ? Promise<Normalize<R>> : T extends Buffer ? Buffer : T extends object ? NormalizeObject<T> : T;
|
|
53
56
|
type DeepPartialObject<T extends object> = T extends infer O ? {
|
|
54
57
|
[K in keyof O]?: DeepPartial<O[K]>;
|
|
55
58
|
} : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/sdk",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Botpress SDK",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@botpress/client": "0.
|
|
19
|
+
"@botpress/client": "1.0.0",
|
|
20
20
|
"browser-or-node": "^2.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Botpress SDK
|
|
2
2
|
|
|
3
|
-
Official Botpress SDK for TypeScript. Made for building bots and integrations as code.
|
|
3
|
+
Official Botpress SDK for TypeScript. Made for building bots, plugins and integrations as code.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -9,50 +9,3 @@ npm install --save @botpress/sdk # for npm
|
|
|
9
9
|
yarn add @botpress/sdk # for yarn
|
|
10
10
|
pnpm add @botpress/sdk # for pnpm
|
|
11
11
|
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
1. First, write your bot in a TypeScript file. For example, `src/index.ts`:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { Bot, messages } from '@botpress/sdk'
|
|
19
|
-
|
|
20
|
-
const bot = new Bot({})
|
|
21
|
-
|
|
22
|
-
bot.message('', async ({ message, client, ctx }) => {
|
|
23
|
-
log.info('Received message', message)
|
|
24
|
-
|
|
25
|
-
await client.createMessage({
|
|
26
|
-
conversationId: message.conversationId,
|
|
27
|
-
userId: ctx.botId,
|
|
28
|
-
tags: {},
|
|
29
|
-
type: 'text',
|
|
30
|
-
payload: {
|
|
31
|
-
text: `I'm a stub bot. You said: ${message.payload.text}`,
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
console.log('text message sent')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
export default bot
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
2. Then, you can run it locally:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
bp serve --entry-point ./src/index.ts # using the botpress CLI
|
|
44
|
-
|
|
45
|
-
ts-node -e "import bot from './src'; void bot.serve()" # or using ts-node directly
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
3. Or, you can bundle it and deploy it to Botpress Cloud:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
bp deploy --entry-point ./src/index.ts # using the botpress CLI
|
|
52
|
-
|
|
53
|
-
# or, using esbuild and the Botpress API
|
|
54
|
-
esbuild --bundle --target=es2019 --platform=node --format=cjs --outfile=bundle.js ./src/index.ts
|
|
55
|
-
code=$(cat bundle.js)
|
|
56
|
-
# call the Botpress API using curl or any other HTTP client
|
|
57
|
-
# see https://botpress.com/docs/api/#bot-update-bot
|
|
58
|
-
```
|