@botpress/sdk 1.2.0 → 1.2.2
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 +3 -3
- package/dist/bot/client/index.d.ts +42 -41
- package/dist/bot/client/types.d.ts +127 -74
- package/dist/bot/client/types.test.d.ts +1 -0
- package/dist/bot/implementation.d.ts +1 -1
- package/dist/bot/index.d.ts +1 -1
- package/dist/bot/server/context.d.ts +2 -0
- package/dist/bot/server/index.d.ts +5 -0
- package/dist/bot/server/types.d.ts +59 -0
- package/dist/bot/types/common.d.ts +56 -0
- package/dist/bot/types/common.test.d.ts +1 -0
- package/dist/bot/types/generic.d.ts +15 -0
- package/dist/bot/types/index.d.ts +2 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/integration/client/index.d.ts +42 -41
- package/dist/integration/client/types.d.ts +127 -21
- package/dist/integration/implementation.d.ts +2 -2
- package/dist/integration/index.d.ts +1 -2
- package/dist/integration/server/context.d.ts +3 -0
- package/dist/integration/server/index.d.ts +6 -0
- package/dist/integration/server/types.d.ts +102 -0
- package/dist/integration/types/common.d.ts +11 -0
- package/dist/integration/types/generic.d.ts +54 -0
- package/dist/integration/types/index.d.ts +2 -0
- package/dist/message.d.ts +1 -1
- package/dist/utils/type-utils.d.ts +19 -3
- package/dist/utils/type-utils.test.d.ts +1 -0
- package/package.json +1 -1
- package/dist/bot/client/routes.d.ts +0 -81
- package/dist/bot/context.d.ts +0 -12
- package/dist/bot/generic.d.ts +0 -7
- package/dist/bot/server.d.ts +0 -40
- package/dist/integration/client/routes.d.ts +0 -128
- package/dist/integration/context.d.ts +0 -23
- package/dist/integration/generic.d.ts +0 -30
- package/dist/integration/server.d.ts +0 -88
- /package/dist/integration/{action-metadata.d.ts → server/action-metadata.d.ts} +0 -0
- /package/dist/integration/{logger.d.ts → server/logger.d.ts} +0 -0
|
@@ -1,22 +1,128 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import * as client from '@botpress/client';
|
|
2
|
+
import * as utils from '../../utils/type-utils';
|
|
3
|
+
import * as common from '../types';
|
|
4
|
+
type GetChannelByName<TIntegration extends common.BaseIntegration, TChannelName extends keyof TIntegration['channels']> = utils.Cast<TIntegration['channels'][TChannelName], common.ChannelDefinition>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Integration's should no longer use tag prefixes
|
|
7
|
+
*/
|
|
8
|
+
type WithPrefix<TTags extends string, TPrefix extends string> = TTags | utils.Join<[TPrefix, ':', TTags]>;
|
|
9
|
+
type Arg<F extends (...args: any[]) => any> = Parameters<F>[number];
|
|
10
|
+
type Res<F extends (...args: any[]) => any> = ReturnType<F>;
|
|
11
|
+
type AllChannels<TIntegration extends common.BaseIntegration> = utils.ValueOf<TIntegration['channels']>;
|
|
12
|
+
type ConversationResponse<TIntegration extends common.BaseIntegration, ChannelName extends keyof TIntegration['channels'] = keyof TIntegration['channels']> = {
|
|
13
|
+
conversation: utils.Merge<Awaited<Res<client.Client['getConversation']>>['conversation'], {
|
|
14
|
+
channel: ChannelName;
|
|
15
|
+
tags: common.ToTags<keyof TIntegration['channels'][ChannelName]['conversation']['tags']>;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
export type CreateConversation<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels']>(x: {
|
|
19
|
+
channel: utils.Cast<ChannelName, string>;
|
|
20
|
+
tags: common.ToTags<keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>;
|
|
21
|
+
}) => Promise<ConversationResponse<TIntegration, ChannelName>>;
|
|
22
|
+
export type GetConversation<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getConversation']>) => Promise<ConversationResponse<TIntegration>>;
|
|
23
|
+
export type ListConversations<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels']>(x: utils.Merge<Arg<client.Client['listConversations']>, {
|
|
24
|
+
channel?: utils.Cast<ChannelName, string>;
|
|
25
|
+
tags?: common.ToTags<keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>;
|
|
26
|
+
}>) => Res<client.Client['listConversations']>;
|
|
27
|
+
export type GetOrCreateConversation<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels']>(x: {
|
|
28
|
+
channel: utils.Cast<ChannelName, string>;
|
|
29
|
+
tags: common.ToTags<keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>;
|
|
30
|
+
}) => Promise<ConversationResponse<TIntegration, ChannelName>>;
|
|
31
|
+
export type UpdateConversation<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateConversation']>, {
|
|
32
|
+
tags: common.ToTags<keyof AllChannels<TIntegration>['conversation']['tags']>;
|
|
33
|
+
}>) => Promise<ConversationResponse<TIntegration>>;
|
|
34
|
+
export type DeleteConversation<_TIntegration extends common.BaseIntegration> = client.Client['deleteConversation'];
|
|
35
|
+
export type ListParticipants<_TIntegration extends common.BaseIntegration> = client.Client['listParticipants'];
|
|
36
|
+
export type AddParticipant<_TIntegration extends common.BaseIntegration> = client.Client['addParticipant'];
|
|
37
|
+
export type GetParticipant<_TIntegration extends common.BaseIntegration> = client.Client['getParticipant'];
|
|
38
|
+
export type RemoveParticipant<_TIntegration extends common.BaseIntegration> = client.Client['removeParticipant'];
|
|
39
|
+
type EventResponse<TIntegration extends common.BaseIntegration, TEvent extends keyof TIntegration['events']> = {
|
|
40
|
+
event: utils.Merge<Awaited<Res<client.Client['getEvent']>>['event'], {
|
|
41
|
+
type: TEvent;
|
|
42
|
+
payload: TIntegration['events'][TEvent];
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
export type CreateEvent<TIntegration extends common.BaseIntegration> = <TEvent extends keyof TIntegration['events']>(x: utils.Merge<Arg<client.Client['createEvent']>, {
|
|
46
|
+
type: WithPrefix<utils.Cast<TEvent, string>, TIntegration['name']>;
|
|
47
|
+
payload: TIntegration['events'][TEvent];
|
|
48
|
+
}>) => Promise<EventResponse<TIntegration, TEvent>>;
|
|
49
|
+
export type GetEvent<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getEvent']>) => Promise<utils.ValueOf<{
|
|
50
|
+
[K in keyof TIntegration['events']]: EventResponse<TIntegration, K>;
|
|
51
|
+
}>>;
|
|
52
|
+
export type ListEvents<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listEvents']>, {
|
|
53
|
+
type: WithPrefix<utils.Cast<keyof TIntegration['events'], string>, TIntegration['name']>;
|
|
54
|
+
}>) => Res<client.Client['listEvents']>;
|
|
55
|
+
type MessageResponse<TIntegration extends common.BaseIntegration, TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']> = {
|
|
56
|
+
message: utils.Merge<Awaited<Res<client.Client['createMessage']>>['message'], {
|
|
57
|
+
payload: TIntegration['channels'][TChannel]['messages'][TMessage];
|
|
58
|
+
tags: common.ToTags<keyof TIntegration['channels'][TChannel]['message']['tags']>;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
export type CreateMessage<TIntegration extends common.BaseIntegration> = <TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']>(x: utils.Merge<Arg<client.Client['createMessage']>, {
|
|
62
|
+
type: utils.Cast<TMessage, string>;
|
|
63
|
+
payload: TIntegration['channels'][TChannel]['messages'][TMessage];
|
|
64
|
+
tags: common.ToTags<keyof TIntegration['channels'][TChannel]['message']['tags']>;
|
|
65
|
+
}>) => Promise<MessageResponse<TIntegration, TChannel, TMessage>>;
|
|
66
|
+
export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']>(x: utils.Merge<Arg<client.Client['getOrCreateMessage']>, {
|
|
67
|
+
type: utils.Cast<TMessage, string>;
|
|
68
|
+
payload: TIntegration['channels'][TChannel]['messages'][TMessage];
|
|
69
|
+
tags: common.ToTags<keyof TIntegration['channels'][TChannel]['message']['tags']>;
|
|
70
|
+
}>) => Promise<MessageResponse<TIntegration, TChannel, TMessage>>;
|
|
71
|
+
export type GetMessage<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getMessage']>) => Promise<MessageResponse<TIntegration, keyof TIntegration['channels'], keyof utils.ValueOf<TIntegration['channels']>['messages']>>;
|
|
72
|
+
export type UpdateMessage<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateMessage']>, {
|
|
73
|
+
tags: common.ToTags<keyof AllChannels<TIntegration>['message']['tags']>;
|
|
74
|
+
}>) => Promise<MessageResponse<TIntegration, keyof TIntegration['channels'], keyof utils.ValueOf<TIntegration['channels']>['messages']>>;
|
|
75
|
+
export type ListMessages<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listMessages']>, {
|
|
76
|
+
tags: common.ToTags<keyof AllChannels<TIntegration>['message']['tags']>;
|
|
77
|
+
}>) => Res<client.Client['listMessages']>;
|
|
78
|
+
export type DeleteMessage<_TIntegration extends common.BaseIntegration> = client.Client['deleteMessage'];
|
|
79
|
+
type UserResponse<TIntegration extends common.BaseIntegration> = {
|
|
80
|
+
user: utils.Merge<Awaited<Res<client.Client['getUser']>>['user'], {
|
|
81
|
+
tags: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
export type CreateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['createUser']>, {
|
|
85
|
+
tags: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
86
|
+
}>) => Promise<UserResponse<TIntegration>>;
|
|
87
|
+
export type GetUser<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getUser']>) => Promise<UserResponse<TIntegration>>;
|
|
88
|
+
export type ListUsers<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listUsers']>, {
|
|
89
|
+
tags: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
90
|
+
}>) => Res<client.Client['listUsers']>;
|
|
91
|
+
export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['getOrCreateUser']>, {
|
|
92
|
+
tags: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
93
|
+
}>) => Promise<UserResponse<TIntegration>>;
|
|
94
|
+
export type UpdateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateUser']>, {
|
|
95
|
+
tags: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
96
|
+
}>) => Promise<UserResponse<TIntegration>>;
|
|
97
|
+
export type DeleteUser<_TIntegration extends common.BaseIntegration> = client.Client['deleteUser'];
|
|
98
|
+
type StateResponse<TIntegration extends common.BaseIntegration, TState extends keyof TIntegration['states']> = {
|
|
99
|
+
state: utils.Merge<Awaited<Res<client.Client['getState']>>['state'], {
|
|
100
|
+
payload: TIntegration['states'][TState];
|
|
101
|
+
}>;
|
|
102
|
+
meta: {
|
|
103
|
+
cached: boolean;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export type GetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['getState']>, {
|
|
107
|
+
name: utils.Cast<TState, string>;
|
|
108
|
+
}>) => Promise<StateResponse<TIntegration, TState>>;
|
|
109
|
+
export type SetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['setState']>, {
|
|
110
|
+
name: utils.Cast<TState, string>;
|
|
111
|
+
payload: TIntegration['states'][TState] | null;
|
|
112
|
+
}>) => Promise<StateResponse<TIntegration, TState>>;
|
|
113
|
+
export type GetOrSetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['getOrSetState']>, {
|
|
114
|
+
name: utils.Cast<TState, string>;
|
|
115
|
+
payload: TIntegration['states'][TState];
|
|
116
|
+
}>) => Promise<StateResponse<TIntegration, TState>>;
|
|
117
|
+
export type PatchState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['patchState']>, {
|
|
118
|
+
name: utils.Cast<TState, string>;
|
|
119
|
+
payload: Partial<TIntegration['states'][TState]>;
|
|
120
|
+
}>) => Promise<StateResponse<TIntegration, TState>>;
|
|
121
|
+
export type ConfigureIntegration<_TIntegration extends common.BaseIntegration> = client.Client['configureIntegration'];
|
|
122
|
+
export type UploadFile<_TIntegration extends common.BaseIntegration> = client.Client['uploadFile'];
|
|
123
|
+
export type UpsertFile<_TIntegration extends common.BaseIntegration> = client.Client['upsertFile'];
|
|
124
|
+
export type DeleteFile<_TIntegration extends common.BaseIntegration> = client.Client['deleteFile'];
|
|
125
|
+
export type ListFiles<_TIntegration extends common.BaseIntegration> = client.Client['listFiles'];
|
|
126
|
+
export type GetFile<_TIntegration extends common.BaseIntegration> = client.Client['getFile'];
|
|
127
|
+
export type UpdateFileMetadata<_TIntegration extends common.BaseIntegration> = client.Client['updateFileMetadata'];
|
|
22
128
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { RegisterHandler as RegisterFunction, UnregisterHandler as UnregisterFunction, WebhookHandler as WebhookFunction, CreateUserHandler as CreateUserFunction, CreateConversationHandler as CreateConversationFunction, ActionHandlers as ActionFunctions, ChannelHandlers as ChannelFunctions } from './server';
|
|
3
|
+
import { BaseIntegration } from './types';
|
|
4
4
|
export type IntegrationImplementationProps<TIntegration extends BaseIntegration = BaseIntegration> = {
|
|
5
5
|
register: RegisterFunction<TIntegration>;
|
|
6
6
|
unregister: UnregisterFunction<TIntegration>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IntegrationContext } from './types';
|
|
2
|
+
export declare const integrationOperationSchema: import("@bpinternal/zui").ZodEnum<["webhook_received", "message_created", "action_triggered", "register", "unregister", "ping", "create_user", "create_conversation"]>;
|
|
3
|
+
export declare const extractContext: (headers: Record<string, string | undefined>) => IntegrationContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Request, Response } from '../../serve';
|
|
2
|
+
import { BaseIntegration } from '../types';
|
|
3
|
+
import { IntegrationHandlers } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './logger';
|
|
6
|
+
export declare const integrationHandler: <TIntegration extends BaseIntegration>(instance: IntegrationHandlers<TIntegration>) => (req: Request) => Promise<Response | void>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type Conversation, type Message, type User } from '@botpress/client';
|
|
2
|
+
import { Request, Response } from '../../serve';
|
|
3
|
+
import { Cast, Merge, ValueOf } from '../../utils/type-utils';
|
|
4
|
+
import { IntegrationSpecificClient } from '../client';
|
|
5
|
+
import { BaseIntegration, ToTags } from '../types';
|
|
6
|
+
import { IntegrationLogger } from './logger';
|
|
7
|
+
type IntegrationOperation = 'webhook_received' | 'message_created' | 'action_triggered' | 'register' | 'unregister' | 'ping' | 'create_user' | 'create_conversation';
|
|
8
|
+
type IntegrationContextConfig<TIntegration extends BaseIntegration> = {
|
|
9
|
+
configurationType: null;
|
|
10
|
+
configuration: TIntegration['configuration'];
|
|
11
|
+
} | ValueOf<{
|
|
12
|
+
[TConfigType in keyof TIntegration['configurations']]: {
|
|
13
|
+
configurationType: TConfigType;
|
|
14
|
+
configuration: TIntegration['configurations'][TConfigType];
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export type IntegrationContext<TIntegration extends BaseIntegration = BaseIntegration> = {
|
|
18
|
+
botId: string;
|
|
19
|
+
botUserId: string;
|
|
20
|
+
integrationId: string;
|
|
21
|
+
webhookId: string;
|
|
22
|
+
operation: IntegrationOperation;
|
|
23
|
+
} & IntegrationContextConfig<TIntegration>;
|
|
24
|
+
export type CommonHandlerProps<TIntegration extends BaseIntegration> = {
|
|
25
|
+
ctx: IntegrationContext<TIntegration>;
|
|
26
|
+
client: IntegrationSpecificClient<TIntegration>;
|
|
27
|
+
logger: IntegrationLogger;
|
|
28
|
+
};
|
|
29
|
+
export type RegisterPayload = {
|
|
30
|
+
webhookUrl: string;
|
|
31
|
+
};
|
|
32
|
+
export type RegisterHandlerProps<TIntegration extends BaseIntegration> = CommonHandlerProps<TIntegration> & RegisterPayload;
|
|
33
|
+
export type RegisterHandler<TIntegration extends BaseIntegration> = (props: RegisterHandlerProps<TIntegration>) => Promise<void>;
|
|
34
|
+
export type UnregisterPayload = {
|
|
35
|
+
webhookUrl: string;
|
|
36
|
+
};
|
|
37
|
+
export type UnregisterHandlerProps<TIntegration extends BaseIntegration> = CommonHandlerProps<TIntegration> & UnregisterPayload;
|
|
38
|
+
export type UnregisterHandler<TIntegration extends BaseIntegration> = (props: UnregisterHandlerProps<TIntegration>) => Promise<void>;
|
|
39
|
+
export type WebhookPayload = {
|
|
40
|
+
req: Request;
|
|
41
|
+
};
|
|
42
|
+
export type WebhookHandlerProps<TIntegration extends BaseIntegration> = CommonHandlerProps<TIntegration> & WebhookPayload;
|
|
43
|
+
export type WebhookHandler<TIntegration extends BaseIntegration> = (props: WebhookHandlerProps<TIntegration>) => Promise<Response | void>;
|
|
44
|
+
export type ActionMetadata = {
|
|
45
|
+
setCost: (cost: number) => void;
|
|
46
|
+
};
|
|
47
|
+
export type ActionPayload<T extends string, I> = {
|
|
48
|
+
type: T;
|
|
49
|
+
input: I;
|
|
50
|
+
metadata: ActionMetadata;
|
|
51
|
+
};
|
|
52
|
+
export type ActionHandlerProps<TIntegration extends BaseIntegration, T extends string, I> = CommonHandlerProps<TIntegration> & ActionPayload<T, I>;
|
|
53
|
+
export type ActionHandlers<TIntegration extends BaseIntegration> = {
|
|
54
|
+
[ActionType in keyof TIntegration['actions']]: (props: ActionHandlerProps<TIntegration, Cast<ActionType, string>, TIntegration['actions'][ActionType]['input']>) => Promise<TIntegration['actions'][ActionType]['output']>;
|
|
55
|
+
};
|
|
56
|
+
export type CreateUserPayload<TIntegration extends BaseIntegration> = {
|
|
57
|
+
tags: ToTags<keyof TIntegration['user']['tags']>;
|
|
58
|
+
};
|
|
59
|
+
export type CreateUserHandlerProps<TIntegration extends BaseIntegration> = CommonHandlerProps<TIntegration> & CreateUserPayload<TIntegration>;
|
|
60
|
+
export type CreateUserHandler<TIntegration extends BaseIntegration> = (props: CreateUserHandlerProps<TIntegration>) => Promise<Response | void>;
|
|
61
|
+
export type CreateConversationPayload<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'] = keyof TIntegration['channels']> = {
|
|
62
|
+
channel: TChannel;
|
|
63
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['conversation']['tags']>;
|
|
64
|
+
};
|
|
65
|
+
export type CreateConversationHandlerProps<TIntegration extends BaseIntegration> = CommonHandlerProps<TIntegration> & CreateConversationPayload<TIntegration>;
|
|
66
|
+
export type CreateConversationHandler<TIntegration extends BaseIntegration> = (props: CreateConversationHandlerProps<TIntegration>) => Promise<Response | void>;
|
|
67
|
+
export type MessagePayload<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']> = {
|
|
68
|
+
type: TMessage;
|
|
69
|
+
payload: TIntegration['channels'][TChannel]['messages'][TMessage];
|
|
70
|
+
conversation: Merge<Conversation, {
|
|
71
|
+
channel: TChannel;
|
|
72
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['conversation']['tags']>;
|
|
73
|
+
}>;
|
|
74
|
+
message: Merge<Message, {
|
|
75
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['message']['tags']>;
|
|
76
|
+
}>;
|
|
77
|
+
user: Merge<User, {
|
|
78
|
+
tags: ToTags<keyof TIntegration['user']['tags']>;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
export type MessageHandlerProps<TIntegration extends BaseIntegration, TChannel extends keyof TIntegration['channels'], TMessage extends keyof TIntegration['channels'][TChannel]['messages']> = CommonHandlerProps<TIntegration> & MessagePayload<TIntegration, TChannel, TMessage> & {
|
|
82
|
+
ack: (props: {
|
|
83
|
+
tags: ToTags<keyof TIntegration['channels'][TChannel]['message']['tags']>;
|
|
84
|
+
}) => Promise<void>;
|
|
85
|
+
};
|
|
86
|
+
export type ChannelHandlers<TIntegration extends BaseIntegration> = {
|
|
87
|
+
[ChannelName in keyof TIntegration['channels']]: {
|
|
88
|
+
messages: {
|
|
89
|
+
[MessageType in keyof TIntegration['channels'][ChannelName]['messages']]: (props: CommonHandlerProps<TIntegration> & MessageHandlerProps<TIntegration, ChannelName, MessageType>) => Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export type IntegrationHandlers<TIntegration extends BaseIntegration> = {
|
|
94
|
+
register: RegisterHandler<TIntegration>;
|
|
95
|
+
unregister: UnregisterHandler<TIntegration>;
|
|
96
|
+
webhook: WebhookHandler<TIntegration>;
|
|
97
|
+
createUser?: CreateUserHandler<TIntegration>;
|
|
98
|
+
createConversation?: CreateConversationHandler<TIntegration>;
|
|
99
|
+
actions: ActionHandlers<TIntegration>;
|
|
100
|
+
channels: ChannelHandlers<TIntegration>;
|
|
101
|
+
};
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as utils from '../../utils/type-utils';
|
|
2
|
+
import { BaseIntegration } from './generic';
|
|
3
|
+
export type ConfigurationDefinition = BaseIntegration['configuration'];
|
|
4
|
+
export type ActionDefinition = BaseIntegration['actions'][string];
|
|
5
|
+
export type ChannelDefinition = BaseIntegration['channels'][string];
|
|
6
|
+
export type EventDefinition = BaseIntegration['events'][string];
|
|
7
|
+
export type StateDefinition = BaseIntegration['states'][string];
|
|
8
|
+
export type UserDefinition = BaseIntegration['user'];
|
|
9
|
+
type AsTags<T extends Record<string, string | undefined>> = utils.Cast<T, Record<string, string>>;
|
|
10
|
+
export type ToTags<TTags extends string | number | symbol> = AsTags<Partial<Record<utils.Cast<TTags, string>, string>>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as utils from '../../utils/type-utils';
|
|
2
|
+
export type BaseIntegration = {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
configuration: any;
|
|
6
|
+
configurations: Record<string, any>;
|
|
7
|
+
actions: Record<string, Record<'input' | 'output', any>>;
|
|
8
|
+
channels: Record<string, {
|
|
9
|
+
messages: Record<string, any>;
|
|
10
|
+
message: {
|
|
11
|
+
tags: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
conversation: {
|
|
14
|
+
tags: Record<string, any>;
|
|
15
|
+
creation: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
requiredTags: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
events: Record<string, any>;
|
|
22
|
+
states: Record<string, any>;
|
|
23
|
+
user: {
|
|
24
|
+
tags: Record<string, any>;
|
|
25
|
+
creation: {
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
requiredTags: string[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
entities: Record<string, any>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Usefull for tests, allows to create a channel with only the properties you want to override
|
|
34
|
+
*/
|
|
35
|
+
export type MakeChannel<C extends Partial<BaseIntegration['channels'][string]>> = {
|
|
36
|
+
messages: utils.Default<C['messages'], BaseIntegration['channels'][string]['messages']>;
|
|
37
|
+
message: utils.Default<C['message'], BaseIntegration['channels'][string]['message']>;
|
|
38
|
+
conversation: utils.Default<C['conversation'], BaseIntegration['channels'][string]['conversation']>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Usefull for tests, allows to create an integration with only the properties you want to override
|
|
42
|
+
*/
|
|
43
|
+
export type MakeIntegration<I extends Partial<BaseIntegration>> = {
|
|
44
|
+
name: utils.Default<I['name'], BaseIntegration['name']>;
|
|
45
|
+
version: utils.Default<I['version'], BaseIntegration['version']>;
|
|
46
|
+
configuration: utils.Default<I['configuration'], BaseIntegration['configuration']>;
|
|
47
|
+
configurations: utils.Default<I['configurations'], BaseIntegration['configurations']>;
|
|
48
|
+
actions: utils.Default<I['actions'], BaseIntegration['actions']>;
|
|
49
|
+
channels: utils.Default<I['channels'], BaseIntegration['channels']>;
|
|
50
|
+
events: utils.Default<I['events'], BaseIntegration['events']>;
|
|
51
|
+
states: utils.Default<I['states'], BaseIntegration['states']>;
|
|
52
|
+
user: utils.Default<I['user'], BaseIntegration['user']>;
|
|
53
|
+
entities: utils.Default<I['entities'], BaseIntegration['entities']>;
|
|
54
|
+
};
|
package/dist/message.d.ts
CHANGED
|
@@ -230,7 +230,7 @@ export declare const defaults: {
|
|
|
230
230
|
};
|
|
231
231
|
readonly bloc: {
|
|
232
232
|
readonly schema: import("@bpinternal/zui").ZodObject<{
|
|
233
|
-
items: import("@bpinternal/zui").ZodArray<import("@bpinternal/zui").
|
|
233
|
+
items: import("@bpinternal/zui").ZodArray<import("@bpinternal/zui").ZodUnion<[import("@bpinternal/zui").ZodObject<{
|
|
234
234
|
type: import("@bpinternal/zui").ZodLiteral<"text">;
|
|
235
235
|
payload: import("@bpinternal/zui").ZodObject<{
|
|
236
236
|
text: import("@bpinternal/zui").ZodString;
|
|
@@ -1,12 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
export type ValueOf<T> = T[keyof T];
|
|
2
3
|
export type Merge<A extends object, B extends object> = Omit<A, keyof B> & B;
|
|
3
4
|
export type Cast<T, U> = T extends U ? T : U;
|
|
5
|
+
export type SafeCast<T, U> = [T] extends [never] ? U : Cast<T, U>;
|
|
4
6
|
export type Writable<T> = {
|
|
5
7
|
-readonly [K in keyof T]: T[K];
|
|
6
8
|
};
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
9
|
-
export type
|
|
9
|
+
export type Default<T, U> = undefined extends T ? U : T;
|
|
10
|
+
export type IsExtend<X, Y> = X extends Y ? true : false;
|
|
11
|
+
export type IsEquivalent<X, Y> = IsExtend<X, Y> extends true ? IsExtend<Y, X> : false;
|
|
12
|
+
export type IsIdentical<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
13
|
+
export type IsEqual<X, Y> = IsIdentical<Normalize<X>, Normalize<Y>>;
|
|
14
|
+
export type AssertExtends<A, _B extends A> = true;
|
|
15
|
+
export type AssertTrue<_T extends true> = true;
|
|
16
|
+
export type AssertAll<_T extends true[]> = true;
|
|
10
17
|
export type Join<S extends (string | number | symbol)[]> = S extends [infer H, ...infer T] ? `${Cast<H, string>}${Join<Cast<T, string[]>>}` : S extends [infer H] ? Cast<H, string> : '';
|
|
11
18
|
export type Split<S extends string | number | symbol, D extends string> = S extends `${infer H}${D}${infer T}` ? [H, ...Split<Cast<T, string>, D>] : [S];
|
|
12
19
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
20
|
+
/**
|
|
21
|
+
* removes string index signature from Record
|
|
22
|
+
*/
|
|
23
|
+
export type ToSealedRecord<R extends Record<string, any>> = {
|
|
24
|
+
[K in keyof R as string extends K ? never : K]: R[K];
|
|
25
|
+
};
|
|
26
|
+
export type Normalize<T> = T extends (...args: infer A) => infer R ? (...args: Normalize<A>) => Normalize<R> : T extends Promise<infer R> ? Promise<Normalize<R>> : T extends Buffer ? Buffer : T extends object ? T extends infer O ? {
|
|
27
|
+
[K in keyof O]: Normalize<O[K]>;
|
|
28
|
+
} : never : T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Client } from '@botpress/client';
|
|
2
|
-
import { Cast, Merge } from '../../utils/type-utils';
|
|
3
|
-
import { BaseBot } from '../generic';
|
|
4
|
-
import * as types from './types';
|
|
5
|
-
type Arg<F extends (...args: any[]) => any> = Parameters<F>[number];
|
|
6
|
-
type Res<F extends (...args: any[]) => any> = ReturnType<F>;
|
|
7
|
-
export type CreateConversation<_TBot extends BaseBot> = Client['createConversation'];
|
|
8
|
-
export type GetConversation<_TBot extends BaseBot> = Client['getConversation'];
|
|
9
|
-
export type ListConversations<_TBot extends BaseBot> = Client['listConversations'];
|
|
10
|
-
export type GetOrCreateConversation<_TBot extends BaseBot> = Client['getOrCreateConversation'];
|
|
11
|
-
export type UpdateConversation<_TBot extends BaseBot> = Client['updateConversation'];
|
|
12
|
-
export type DeleteConversation<_TBot extends BaseBot> = Client['deleteConversation'];
|
|
13
|
-
export type ListParticipants<_TBot extends BaseBot> = Client['listParticipants'];
|
|
14
|
-
export type AddParticipant<_TBot extends BaseBot> = Client['addParticipant'];
|
|
15
|
-
export type GetParticipant<_TBot extends BaseBot> = Client['getParticipant'];
|
|
16
|
-
export type RemoveParticipant<_TBot extends BaseBot> = Client['removeParticipant'];
|
|
17
|
-
export type GetEvent<TBot extends BaseBot> = (x: Arg<Client['getEvent']>) => Promise<types.EventResponse<TBot>>;
|
|
18
|
-
export type ListEvents<_TBot extends BaseBot> = Client['listEvents'];
|
|
19
|
-
export type CreateMessage<TBot extends BaseBot> = <TMessage extends keyof types.GetMessages<TBot>>(x: Merge<Arg<Client['createMessage']>, {
|
|
20
|
-
type: Cast<TMessage, string>;
|
|
21
|
-
payload: Cast<types.GetMessages<TBot>[TMessage], Record<string, any>>;
|
|
22
|
-
}>) => Promise<types.MessageResponse<TBot, TMessage>>;
|
|
23
|
-
export type GetOrCreateMessage<TBot extends BaseBot> = <TMessage extends keyof types.GetMessages<TBot>>(x: Merge<Arg<Client['getOrCreateMessage']>, {
|
|
24
|
-
type: Cast<TMessage, string>;
|
|
25
|
-
payload: Cast<types.GetMessages<TBot>[TMessage], Record<string, any>>;
|
|
26
|
-
}>) => Promise<types.MessageResponse<TBot, TMessage>>;
|
|
27
|
-
export type GetMessage<TBot extends BaseBot> = (x: Arg<Client['getMessage']>) => Promise<types.MessageResponse<TBot>>;
|
|
28
|
-
export type UpdateMessage<TBot extends BaseBot> = (x: Arg<Client['updateMessage']>) => Promise<types.MessageResponse<TBot>>;
|
|
29
|
-
export type ListMessages<_TBot extends BaseBot> = Client['listMessages'];
|
|
30
|
-
export type DeleteMessage<_TBot extends BaseBot> = Client['deleteMessage'];
|
|
31
|
-
export type CreateUser<_TBot extends BaseBot> = Client['createUser'];
|
|
32
|
-
export type GetUser<_TBot extends BaseBot> = Client['getUser'];
|
|
33
|
-
export type ListUsers<_TBot extends BaseBot> = Client['listUsers'];
|
|
34
|
-
export type GetOrCreateUser<_TBot extends BaseBot> = Client['getOrCreateUser'];
|
|
35
|
-
export type UpdateUser<_TBot extends BaseBot> = Client['updateUser'];
|
|
36
|
-
export type DeleteUser<_TBot extends BaseBot> = Client['deleteUser'];
|
|
37
|
-
export type GetState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(x: Merge<Arg<Client['getState']>, {
|
|
38
|
-
name: Cast<TState, string>;
|
|
39
|
-
}>) => Promise<{
|
|
40
|
-
state: Merge<Awaited<Res<Client['getState']>>['state'], {
|
|
41
|
-
payload: TBot['states'][TState];
|
|
42
|
-
}>;
|
|
43
|
-
}>;
|
|
44
|
-
export type SetState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(x: Merge<Arg<Client['setState']>, {
|
|
45
|
-
name: Cast<TState, string>;
|
|
46
|
-
payload: TBot['states'][TState] | null;
|
|
47
|
-
}>) => Promise<{
|
|
48
|
-
state: Merge<Awaited<Res<Client['setState']>>['state'], {
|
|
49
|
-
payload: TBot['states'][TState];
|
|
50
|
-
}>;
|
|
51
|
-
}>;
|
|
52
|
-
export type GetOrSetState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(x: Merge<Arg<Client['getOrSetState']>, {
|
|
53
|
-
name: Cast<TState, string>;
|
|
54
|
-
payload: TBot['states'][TState];
|
|
55
|
-
}>) => Promise<{
|
|
56
|
-
state: Merge<Awaited<Res<Client['getOrSetState']>>['state'], {
|
|
57
|
-
payload: TBot['states'][TState];
|
|
58
|
-
}>;
|
|
59
|
-
}>;
|
|
60
|
-
export type PatchState<TBot extends BaseBot> = <TState extends keyof TBot['states']>(x: Merge<Arg<Client['patchState']>, {
|
|
61
|
-
name: Cast<TState, string>;
|
|
62
|
-
payload: Partial<TBot['states'][TState]>;
|
|
63
|
-
}>) => Promise<{
|
|
64
|
-
state: Merge<Awaited<Res<Client['patchState']>>['state'], {
|
|
65
|
-
payload: TBot['states'][TState];
|
|
66
|
-
}>;
|
|
67
|
-
}>;
|
|
68
|
-
export type CallAction<TBot extends BaseBot> = <ActionType extends keyof types.EnumerateActions<TBot>>(x: Merge<Arg<Client['callAction']>, {
|
|
69
|
-
type: Cast<ActionType, string>;
|
|
70
|
-
input: Cast<types.EnumerateActions<TBot>[ActionType], types.IntegrationInstanceActionDefinition>['input'];
|
|
71
|
-
}>) => Promise<{
|
|
72
|
-
output: Cast<types.EnumerateActions<TBot>[ActionType], types.IntegrationInstanceActionDefinition>['output'];
|
|
73
|
-
}>;
|
|
74
|
-
export type UploadFile<_TBot extends BaseBot> = Client['uploadFile'];
|
|
75
|
-
export type UpsertFile<_TBot extends BaseBot> = Client['upsertFile'];
|
|
76
|
-
export type DeleteFile<_TBot extends BaseBot> = Client['deleteFile'];
|
|
77
|
-
export type ListFiles<_TBot extends BaseBot> = Client['listFiles'];
|
|
78
|
-
export type GetFile<_TBot extends BaseBot> = Client['getFile'];
|
|
79
|
-
export type UpdateFileMetadata<_TBot extends BaseBot> = Client['updateFileMetadata'];
|
|
80
|
-
export type SearchFiles<_TBot extends BaseBot> = Client['searchFiles'];
|
|
81
|
-
export {};
|
package/dist/bot/context.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from '@bpinternal/zui';
|
|
2
|
-
export declare const botOperationSchema: import("@bpinternal/zui").ZodEnum<["event_received", "register", "unregister", "ping", "action_triggered"]>;
|
|
3
|
-
export type BotOperation = z.infer<typeof botOperationSchema>;
|
|
4
|
-
export type BotContext = {
|
|
5
|
-
botId: string;
|
|
6
|
-
type: string;
|
|
7
|
-
operation: BotOperation;
|
|
8
|
-
configuration: {
|
|
9
|
-
payload: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare const extractContext: (headers: Record<string, string | undefined>) => BotContext;
|
package/dist/bot/generic.d.ts
DELETED
package/dist/bot/server.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as client from '@botpress/client';
|
|
2
|
-
import { Request, Response } from '../serve';
|
|
3
|
-
import { BotSpecificClient } from './client';
|
|
4
|
-
import * as types from './client/types';
|
|
5
|
-
import { BotContext } from './context';
|
|
6
|
-
import { StateType } from './definition';
|
|
7
|
-
import { BaseBot } from './generic';
|
|
8
|
-
type CommonArgs<TBot extends BaseBot> = {
|
|
9
|
-
ctx: BotContext;
|
|
10
|
-
client: BotSpecificClient<TBot>;
|
|
11
|
-
};
|
|
12
|
-
type MessagePayload<TBot extends BaseBot> = {
|
|
13
|
-
user: client.User;
|
|
14
|
-
conversation: client.Conversation;
|
|
15
|
-
message: types.MessageResponse<TBot>['message'];
|
|
16
|
-
event: client.Event;
|
|
17
|
-
states: {
|
|
18
|
-
[TState in keyof TBot['states']]: {
|
|
19
|
-
type: StateType;
|
|
20
|
-
payload: TBot['states'][TState];
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
type MessageArgs<TBot extends BaseBot> = CommonArgs<TBot> & MessagePayload<TBot>;
|
|
25
|
-
type EventPayload<TBot extends BaseBot> = types.EventResponse<TBot>;
|
|
26
|
-
type EventArgs<TBot extends BaseBot> = CommonArgs<TBot> & EventPayload<TBot>;
|
|
27
|
-
type StateExpiredPayload = {
|
|
28
|
-
state: client.State;
|
|
29
|
-
};
|
|
30
|
-
type StateExpiredArgs<TBot extends BaseBot> = CommonArgs<TBot> & StateExpiredPayload;
|
|
31
|
-
export type MessageHandler<TBot extends BaseBot> = (args: MessageArgs<TBot>) => Promise<void>;
|
|
32
|
-
export type EventHandler<TBot extends BaseBot> = (args: EventArgs<TBot>) => Promise<void>;
|
|
33
|
-
export type StateExpiredHandler<TBot extends BaseBot> = (args: StateExpiredArgs<TBot>) => Promise<void>;
|
|
34
|
-
export type BotHandlers<TBot extends BaseBot> = {
|
|
35
|
-
messageHandlers: MessageHandler<TBot>[];
|
|
36
|
-
eventHandlers: EventHandler<TBot>[];
|
|
37
|
-
stateExpiredHandlers: StateExpiredHandler<TBot>[];
|
|
38
|
-
};
|
|
39
|
-
export declare const botHandler: <TBot extends BaseBot>(instance: BotHandlers<TBot>) => (req: Request) => Promise<Response | void>;
|
|
40
|
-
export {};
|