@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,25 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const botOperationSchema: z.ZodEnum<["event_received", "register", "unregister", "ping"]>;
|
|
3
|
+
export type BotOperation = z.infer<typeof botOperationSchema>;
|
|
4
|
+
export type BotContext<Configuration = any, Type extends string = string> = {
|
|
5
|
+
botId: string;
|
|
6
|
+
type: Type;
|
|
7
|
+
operation: BotOperation;
|
|
8
|
+
configuration: Configuration;
|
|
9
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Bot as BotType, Event } from '@botpress/client';
|
|
2
|
+
import type { EventHandler, MessageHandler, RegisterHandler, StateExpiredHandler, UnregisterHandler } from './state';
|
|
3
|
+
export type RegisterBotPayload = {
|
|
4
|
+
bot: BotType;
|
|
5
|
+
};
|
|
6
|
+
export type UnregisterBotPayload = {
|
|
7
|
+
bot: BotType;
|
|
8
|
+
};
|
|
9
|
+
export type EventReceivedBotPayload = {
|
|
10
|
+
event: Event;
|
|
11
|
+
};
|
|
12
|
+
export type BotDefinitionTags = {
|
|
13
|
+
messages?: string[];
|
|
14
|
+
conversations?: string[];
|
|
15
|
+
users?: string[];
|
|
16
|
+
};
|
|
17
|
+
export type BotDefinitionStateType = 'conversation' | 'user' | 'bot';
|
|
18
|
+
export type BotDefinitionState = {
|
|
19
|
+
type: BotDefinitionStateType;
|
|
20
|
+
schema: Record<string, any>;
|
|
21
|
+
expiry: number;
|
|
22
|
+
};
|
|
23
|
+
export type IntegrationInstance = {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
id: string;
|
|
26
|
+
configuration: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type BotDefinition = {
|
|
31
|
+
tags?: BotDefinitionTags;
|
|
32
|
+
states?: Record<string, BotDefinitionState>;
|
|
33
|
+
integrations?: IntegrationInstance[];
|
|
34
|
+
};
|
|
35
|
+
export declare class Bot {
|
|
36
|
+
private _state;
|
|
37
|
+
readonly tags?: BotDefinitionTags;
|
|
38
|
+
readonly states?: Record<string, BotDefinitionState>;
|
|
39
|
+
readonly integrations?: IntegrationInstance[];
|
|
40
|
+
constructor(def?: BotDefinition);
|
|
41
|
+
register: (_handler: RegisterHandler) => void;
|
|
42
|
+
unregister: (_handler: UnregisterHandler) => void;
|
|
43
|
+
message: (_type: string, handler: MessageHandler) => void;
|
|
44
|
+
conversation: (_type: string, _handler: MessageHandler) => void;
|
|
45
|
+
user: (_type: string, _handler: MessageHandler) => void;
|
|
46
|
+
event: (_type: string, handler: EventHandler) => void;
|
|
47
|
+
stateExpired: (_type: string, handler: StateExpiredHandler) => void;
|
|
48
|
+
handler: import("../serve").Handler;
|
|
49
|
+
start: (port?: number) => Promise<void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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/const.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const botIdHeader = "x-bot-id";
|
|
2
|
+
export declare const botUserIdHeader = "x-bot-user-id";
|
|
3
|
+
export declare const integrationIdHeader = "x-integration-id";
|
|
4
|
+
export declare const webhookIdHeader = "x-webhook-id";
|
|
5
|
+
export declare const configurationHeader = "x-bp-configuration";
|
|
6
|
+
export declare const operationHeader = "x-bp-operation";
|
|
7
|
+
export declare const typeHeader = "x-bp-type";
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BotClient } from './bot';
|
|
2
|
+
import { IntegrationClient } from './integration';
|
|
3
|
+
export * as messages from './message';
|
|
4
|
+
export declare const clients: {
|
|
5
|
+
IntegrationClient: typeof IntegrationClient;
|
|
6
|
+
BotClient: typeof BotClient;
|
|
7
|
+
};
|
|
8
|
+
export { IntegrationDefinition, IntegrationDefinitionProps, IntegrationImplementation as Integration, IntegrationImplementationProps as IntegrationProps, IntegrationContext, IntegrationOperation, AckFunction, } from './integration';
|
|
9
|
+
export { Bot, BotContext, BotOperation, IntegrationInstance } from './bot';
|