@wabot-dev/framework 0.0.6 → 0.0.8
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/src/ai/openia/OpenaiChatBotAdapter.js +10 -8
- package/dist/src/channels/cmd/@cmd.js +1 -0
- package/dist/src/channels/cmd/CmdChannel.js +32 -12
- package/dist/src/channels/telegram/@telegram.js +1 -0
- package/dist/src/channels/telegram/TelegramChannel.js +27 -14
- package/dist/src/chatbot/ChatBot.js +7 -5
- package/dist/src/chatbot/ChatBotAdapter.js +12 -4
- package/dist/src/chatbot/metadata/@chatBot.js +3 -0
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +3 -0
- package/dist/src/controller/channel/ChatResolver.js +9 -10
- package/dist/src/controller/channel/UserResolver.js +23 -0
- package/dist/src/core/IMessageContext.js +15 -0
- package/dist/src/{chatbot → core}/chat/Chat.js +1 -1
- package/dist/src/{chatbot → core}/chat/repository/ram/RamChatRepository.js +1 -0
- package/dist/src/core/user/User.js +42 -0
- package/dist/src/core/user/repository/IUserRepository.js +19 -0
- package/dist/src/core/user/repository/ram/RamUserRepository.js +28 -0
- package/dist/src/index.d.ts +249 -146
- package/dist/src/index.js +25 -13
- package/dist/src/mindset/IMindset.js +3 -3
- package/dist/src/mindset/metadata/params/@isOptional.js +1 -1
- package/dist/src/pre-made/modules/authentication/AuthenticationModule.js +99 -0
- package/dist/src/pre-made/modules/authentication/requests/SendOneTimePasswordRequest.js +25 -0
- package/dist/src/pre-made/modules/authentication/requests/ValidateOneTimePasswordRequest.js +25 -0
- package/dist/src/pre-made/modules/register-user/RegisterUserModule.js +58 -0
- package/dist/src/pre-made/modules/register-user/requests/RegisterUserWithEmailRequest.js +25 -0
- package/dist/src/pre-made/services/EmailService.js +13 -0
- package/dist/src/pre-made/services/OtpService.js +14 -0
- package/dist/src/server/prepareChatContainer.js +14 -10
- package/dist/src/server/runChannel.js +12 -4
- package/dist/src/server/runServer.js +15 -11
- package/package.json +8 -2
- package/dist/src/context/IContext.js +0 -10
- /package/dist/src/{chatbot → core}/chat/repository/IChatMemory.js +0 -0
- /package/dist/src/{chatbot → core}/chat/repository/IChatRepository.js +0 -0
- /package/dist/src/{chatbot → core}/chat/repository/ram/RamChatMemory.js +0 -0
package/dist/src/index.d.ts
CHANGED
|
@@ -1,111 +1,9 @@
|
|
|
1
|
+
import InjectionToken from 'tsyringe/dist/typings/providers/injection-token';
|
|
2
|
+
import DependencyContainer, { PreResolutionInterceptorCallback, PostResolutionInterceptorCallback } from 'tsyringe/dist/typings/types/dependency-container';
|
|
3
|
+
import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options';
|
|
1
4
|
import * as tsyringe from 'tsyringe';
|
|
2
|
-
import { DependencyContainer
|
|
5
|
+
import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
|
|
3
6
|
export { DependencyContainer } from 'tsyringe';
|
|
4
|
-
import { InterceptionOptions } from 'tsyringe/dist/typings/types';
|
|
5
|
-
import { PreResolutionInterceptorCallback, PostResolutionInterceptorCallback } from 'tsyringe/dist/typings/types/dependency-container';
|
|
6
|
-
|
|
7
|
-
interface IChatDocument {
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface IChatImage {
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface IChatSender {
|
|
14
|
-
shortName: string;
|
|
15
|
-
senderId?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface IChatMessage {
|
|
19
|
-
sender: IChatSender;
|
|
20
|
-
text?: string;
|
|
21
|
-
documents?: IChatDocument[];
|
|
22
|
-
images?: IChatImage[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface IChatFunctionCall {
|
|
26
|
-
foreignId: string;
|
|
27
|
-
name: string;
|
|
28
|
-
arguments?: string;
|
|
29
|
-
result: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type ISystemMessageItem = {
|
|
33
|
-
type: 'BOT_MESSAGE';
|
|
34
|
-
content: IChatMessage;
|
|
35
|
-
};
|
|
36
|
-
type IUserMessageItem = {
|
|
37
|
-
type: 'USER_MESSAGE';
|
|
38
|
-
content: IChatMessage;
|
|
39
|
-
};
|
|
40
|
-
type ISystemFunctionCallItem = {
|
|
41
|
-
type: 'FUNCTION_CALL';
|
|
42
|
-
content: IChatFunctionCall;
|
|
43
|
-
};
|
|
44
|
-
type IChatItem = {
|
|
45
|
-
id: string;
|
|
46
|
-
createdAt: Date;
|
|
47
|
-
} & (ISystemMessageItem | IUserMessageItem | ISystemFunctionCallItem);
|
|
48
|
-
type IChatItemType = IChatItem['type'];
|
|
49
|
-
|
|
50
|
-
interface IChatMemory {
|
|
51
|
-
findLastItems(count: number): Promise<IChatItem[]>;
|
|
52
|
-
saveItem(item: IChatItem): Promise<void>;
|
|
53
|
-
}
|
|
54
|
-
declare class ChatMemory implements IChatMemory {
|
|
55
|
-
findLastItems(count: number): Promise<IChatItem[]>;
|
|
56
|
-
saveItem(item: IChatItem): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare class RamChatMemory implements IChatMemory {
|
|
60
|
-
private memory;
|
|
61
|
-
findLastItems(count: number): Promise<IChatItem[]>;
|
|
62
|
-
saveItem(item: IChatItem): Promise<void>;
|
|
63
|
-
clearMemory(): Promise<void>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type IChatType = 'PRIVATE' | 'GROUP';
|
|
67
|
-
interface IChatConnection {
|
|
68
|
-
channelType: string;
|
|
69
|
-
chatId: string;
|
|
70
|
-
}
|
|
71
|
-
interface IChatData {
|
|
72
|
-
id?: string;
|
|
73
|
-
createdAt?: Date;
|
|
74
|
-
type: IChatType;
|
|
75
|
-
connections: IChatConnection[];
|
|
76
|
-
}
|
|
77
|
-
declare class Chat {
|
|
78
|
-
private data;
|
|
79
|
-
constructor(data: IChatData);
|
|
80
|
-
isPrivate(): boolean;
|
|
81
|
-
isGroup(): boolean;
|
|
82
|
-
hasConnection(connection: IChatConnection): boolean;
|
|
83
|
-
private validatePrivateChat;
|
|
84
|
-
private validateGroupChat;
|
|
85
|
-
getId(): string;
|
|
86
|
-
wasCreated(): boolean;
|
|
87
|
-
validate(): void;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface IChatRepository {
|
|
91
|
-
create(chat: Chat): Promise<void>;
|
|
92
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
93
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
94
|
-
}
|
|
95
|
-
declare class ChatRepository implements IChatRepository {
|
|
96
|
-
create(chat: Chat): Promise<void>;
|
|
97
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
98
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
declare class RamChatRepository implements IChatRepository {
|
|
102
|
-
private items;
|
|
103
|
-
private memories;
|
|
104
|
-
create(chat: Chat): Promise<void>;
|
|
105
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
106
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
107
|
-
private getMemory;
|
|
108
|
-
}
|
|
109
7
|
|
|
110
8
|
interface IMindsetFunctionConfig {
|
|
111
9
|
description: string;
|
|
@@ -159,6 +57,7 @@ interface IMindsetDecoration {
|
|
|
159
57
|
|
|
160
58
|
interface IMindsetModuleConfig {
|
|
161
59
|
description: string;
|
|
60
|
+
language?: string;
|
|
162
61
|
}
|
|
163
62
|
|
|
164
63
|
declare function mindsetModule<A>(config: IMindsetModuleConfig): (target: IConstructor<A>) => void;
|
|
@@ -188,6 +87,9 @@ interface IParamDecoration {
|
|
|
188
87
|
decorationConfig: any;
|
|
189
88
|
}
|
|
190
89
|
|
|
90
|
+
declare const PARAM_DECORATION_IS_OPTIONAL = "isOptional";
|
|
91
|
+
declare const PARAM_DECORATION_PARAM = "param";
|
|
92
|
+
|
|
191
93
|
interface IMindsetFunctionParamMetadata {
|
|
192
94
|
config: IParamConfig;
|
|
193
95
|
name: string;
|
|
@@ -284,6 +186,165 @@ declare class ChatBotMetadataStore {
|
|
|
284
186
|
getChatBotsMetadata(): IChatBotMetadata[];
|
|
285
187
|
}
|
|
286
188
|
|
|
189
|
+
type IChatType = 'PRIVATE' | 'GROUP';
|
|
190
|
+
interface IChatConnection {
|
|
191
|
+
chatType: IChatType;
|
|
192
|
+
channelName: string;
|
|
193
|
+
id: string;
|
|
194
|
+
}
|
|
195
|
+
interface IChatData {
|
|
196
|
+
id?: string;
|
|
197
|
+
createdAt?: Date;
|
|
198
|
+
type: IChatType;
|
|
199
|
+
connections: IChatConnection[];
|
|
200
|
+
}
|
|
201
|
+
declare class Chat {
|
|
202
|
+
private data;
|
|
203
|
+
constructor(data: IChatData);
|
|
204
|
+
isPrivate(): boolean;
|
|
205
|
+
isGroup(): boolean;
|
|
206
|
+
hasConnection(connection: IChatConnection): boolean;
|
|
207
|
+
private validatePrivateChat;
|
|
208
|
+
private validateGroupChat;
|
|
209
|
+
getId(): string;
|
|
210
|
+
wasCreated(): boolean;
|
|
211
|
+
validate(): void;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface IChatDocument {
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface IChatImage {
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
interface IUserConnection {
|
|
221
|
+
channelName: string;
|
|
222
|
+
id: string;
|
|
223
|
+
}
|
|
224
|
+
interface IUserData {
|
|
225
|
+
id?: string;
|
|
226
|
+
createdAt?: Date;
|
|
227
|
+
shortName: string;
|
|
228
|
+
connections: IUserConnection[];
|
|
229
|
+
keyValueData: {
|
|
230
|
+
[key: string]: string;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
declare class User {
|
|
234
|
+
private data;
|
|
235
|
+
constructor(data: IUserData);
|
|
236
|
+
getId(): string;
|
|
237
|
+
hasConnection(connection: IUserConnection): boolean;
|
|
238
|
+
wasCreated(): boolean;
|
|
239
|
+
validate(): void;
|
|
240
|
+
getValue(key: string): string;
|
|
241
|
+
setValue(key: string, value: string): void;
|
|
242
|
+
addConnection(connection: IUserConnection): void;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
interface IChatMessage {
|
|
246
|
+
text?: string;
|
|
247
|
+
documents?: IChatDocument[];
|
|
248
|
+
images?: IChatImage[];
|
|
249
|
+
senderName: string;
|
|
250
|
+
}
|
|
251
|
+
interface IConnectionChatMessage extends IChatMessage {
|
|
252
|
+
chatConnection: IChatConnection;
|
|
253
|
+
userConnection: IUserConnection;
|
|
254
|
+
userId?: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
interface IChatFunctionCall {
|
|
258
|
+
id: string;
|
|
259
|
+
name: string;
|
|
260
|
+
arguments?: string;
|
|
261
|
+
result: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
type ISystemMessageItem = {
|
|
265
|
+
type: 'BOT_MESSAGE';
|
|
266
|
+
content: IChatMessage;
|
|
267
|
+
};
|
|
268
|
+
type IReceivedMessageItem = {
|
|
269
|
+
type: 'CONNECTION_MESSAGE';
|
|
270
|
+
content: IConnectionChatMessage;
|
|
271
|
+
};
|
|
272
|
+
type ISystemFunctionCallItem = {
|
|
273
|
+
type: 'FUNCTION_CALL';
|
|
274
|
+
content: IChatFunctionCall;
|
|
275
|
+
};
|
|
276
|
+
type IChatItem = {
|
|
277
|
+
id: string;
|
|
278
|
+
createdAt: Date;
|
|
279
|
+
} & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
|
|
280
|
+
type IChatItemType = IChatItem['type'];
|
|
281
|
+
|
|
282
|
+
interface IChatMemory {
|
|
283
|
+
findLastItems(count: number): Promise<IChatItem[]>;
|
|
284
|
+
saveItem(item: IChatItem): Promise<void>;
|
|
285
|
+
}
|
|
286
|
+
declare class ChatMemory implements IChatMemory {
|
|
287
|
+
findLastItems(count: number): Promise<IChatItem[]>;
|
|
288
|
+
saveItem(item: IChatItem): Promise<void>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare class RamChatMemory implements IChatMemory {
|
|
292
|
+
private memory;
|
|
293
|
+
findLastItems(count: number): Promise<IChatItem[]>;
|
|
294
|
+
saveItem(item: IChatItem): Promise<void>;
|
|
295
|
+
clearMemory(): Promise<void>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface IChatRepository {
|
|
299
|
+
create(chat: Chat): Promise<void>;
|
|
300
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
301
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
302
|
+
}
|
|
303
|
+
declare class ChatRepository implements IChatRepository {
|
|
304
|
+
create(chat: Chat): Promise<void>;
|
|
305
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
306
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
declare class RamChatRepository implements IChatRepository {
|
|
310
|
+
private items;
|
|
311
|
+
private memories;
|
|
312
|
+
create(chat: Chat): Promise<void>;
|
|
313
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
314
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
315
|
+
private getMemory;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
interface IUserRepository {
|
|
319
|
+
create(chat: User): Promise<void>;
|
|
320
|
+
update(chat: User): Promise<void>;
|
|
321
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
322
|
+
}
|
|
323
|
+
declare class UserRepository implements IUserRepository {
|
|
324
|
+
create(chat: User): Promise<void>;
|
|
325
|
+
update(chat: User): Promise<void>;
|
|
326
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
declare class RamUserRepository implements IUserRepository {
|
|
330
|
+
private items;
|
|
331
|
+
create(chat: User): Promise<void>;
|
|
332
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
333
|
+
update(chat: User): Promise<void>;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
interface IMessageContext {
|
|
337
|
+
message: IConnectionChatMessage;
|
|
338
|
+
chat: Chat;
|
|
339
|
+
user: User | null;
|
|
340
|
+
}
|
|
341
|
+
declare class MessageContext implements IMessageContext {
|
|
342
|
+
message: IConnectionChatMessage;
|
|
343
|
+
chat: Chat;
|
|
344
|
+
user: User | null;
|
|
345
|
+
constructor(message: IConnectionChatMessage, chat: Chat, user: User | null);
|
|
346
|
+
}
|
|
347
|
+
|
|
287
348
|
interface IChatBotAdapter {
|
|
288
349
|
generateNextChatItem(chatItems: IChatItem[]): Promise<IChatItem>;
|
|
289
350
|
}
|
|
@@ -296,12 +357,12 @@ declare class ChatBotAdapter implements IChatBotAdapter {
|
|
|
296
357
|
id: string;
|
|
297
358
|
createdAt: Date;
|
|
298
359
|
} & ISystemMessageItem>;
|
|
299
|
-
protected buildFunctionCallItem(
|
|
360
|
+
protected buildFunctionCallItem(id: string, functionName: string, functionArguments: string): Promise<{
|
|
300
361
|
readonly id: string;
|
|
301
362
|
readonly createdAt: Date;
|
|
302
363
|
readonly type: "FUNCTION_CALL";
|
|
303
364
|
readonly content: {
|
|
304
|
-
readonly
|
|
365
|
+
readonly id: string;
|
|
305
366
|
readonly name: string;
|
|
306
367
|
readonly arguments: string;
|
|
307
368
|
readonly result: string;
|
|
@@ -317,7 +378,7 @@ declare class ChatBot implements IChatBot {
|
|
|
317
378
|
private memory;
|
|
318
379
|
private adapter;
|
|
319
380
|
constructor(memory: ChatMemory, adapter: ChatBotAdapter);
|
|
320
|
-
sendMessage(message:
|
|
381
|
+
sendMessage(message: IConnectionChatMessage, callback: (message: IChatMessage) => void): Promise<void>;
|
|
321
382
|
protected processLoop(callback: (message: IChatMessage) => void): Promise<void>;
|
|
322
383
|
}
|
|
323
384
|
|
|
@@ -331,46 +392,28 @@ declare class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
|
331
392
|
|
|
332
393
|
declare function cmd(): (target: object, propertyKey: string | symbol) => void;
|
|
333
394
|
|
|
334
|
-
interface IChatContext {
|
|
335
|
-
chatId: string;
|
|
336
|
-
message: IChatMessage;
|
|
337
|
-
reply: (message: IChatMessage) => void;
|
|
338
|
-
}
|
|
339
|
-
interface IUserContext {
|
|
340
|
-
userId: string;
|
|
341
|
-
}
|
|
342
|
-
interface IContext {
|
|
343
|
-
user?: IUserContext;
|
|
344
|
-
chat: IChatContext;
|
|
345
|
-
}
|
|
346
|
-
declare class Context implements IContext {
|
|
347
|
-
chat: IChatContext;
|
|
348
|
-
user?: IUserContext | undefined;
|
|
349
|
-
constructor(chat: IChatContext, user?: IUserContext | undefined);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
interface IMessageOrigin {
|
|
353
|
-
chatId: string;
|
|
354
|
-
chatType: IChatType;
|
|
355
|
-
channelType: Function;
|
|
356
|
-
}
|
|
357
|
-
interface IMessageContext extends IChatContext {
|
|
358
|
-
origin: IMessageOrigin;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
395
|
declare class ChatResolver {
|
|
362
396
|
private chatRepository;
|
|
363
397
|
constructor(chatRepository: ChatRepository);
|
|
364
|
-
resolve(
|
|
398
|
+
resolve(connection: IChatConnection): Promise<Chat>;
|
|
365
399
|
private resolveGroupChat;
|
|
366
400
|
private resolvePrivateChat;
|
|
367
401
|
}
|
|
368
402
|
|
|
403
|
+
interface IReceivedMessage extends IMessageContext {
|
|
404
|
+
reply: (message: IChatMessage) => void;
|
|
405
|
+
}
|
|
369
406
|
interface IChatChannel {
|
|
370
|
-
listen(callback: (message:
|
|
407
|
+
listen(callback: (message: IReceivedMessage) => void): void;
|
|
371
408
|
connect(): void;
|
|
372
409
|
}
|
|
373
410
|
|
|
411
|
+
declare class UserResolver {
|
|
412
|
+
private userRepository;
|
|
413
|
+
constructor(userRepository: UserRepository);
|
|
414
|
+
resolve(connection: IUserConnection): Promise<User | null>;
|
|
415
|
+
}
|
|
416
|
+
|
|
374
417
|
interface IchatControllerConfig {
|
|
375
418
|
}
|
|
376
419
|
|
|
@@ -400,10 +443,11 @@ declare class ControllerMetadataStore {
|
|
|
400
443
|
|
|
401
444
|
declare class CmdChannel implements IChatChannel {
|
|
402
445
|
private chatResolver;
|
|
446
|
+
private userResolver;
|
|
403
447
|
private rl;
|
|
404
448
|
private callBack;
|
|
405
|
-
constructor(chatResolver: ChatResolver);
|
|
406
|
-
listen(callback: (message:
|
|
449
|
+
constructor(chatResolver: ChatResolver, userResolver: UserResolver);
|
|
450
|
+
listen(callback: (message: IReceivedMessage) => void): void;
|
|
407
451
|
connect(): void;
|
|
408
452
|
}
|
|
409
453
|
|
|
@@ -420,13 +464,14 @@ declare function telegram(config: ITelegramChannelConfig): (target: object, prop
|
|
|
420
464
|
declare class TelegramChannel implements IChatChannel {
|
|
421
465
|
private config;
|
|
422
466
|
private chatResolver;
|
|
467
|
+
private userResolver;
|
|
423
468
|
private bot;
|
|
424
|
-
constructor(config: TelegramChannelConfig, chatResolver: ChatResolver);
|
|
425
|
-
listen(callback: (message:
|
|
469
|
+
constructor(config: TelegramChannelConfig, chatResolver: ChatResolver, userResolver: UserResolver);
|
|
470
|
+
listen(callback: (message: IReceivedMessage) => void): void;
|
|
426
471
|
connect(): void;
|
|
427
472
|
}
|
|
428
473
|
|
|
429
|
-
declare function prepareChatContainer(container: DependencyContainer, context:
|
|
474
|
+
declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
|
|
430
475
|
|
|
431
476
|
interface IrunChannelProps {
|
|
432
477
|
channel: IConstructor<IChatChannel>;
|
|
@@ -437,11 +482,69 @@ interface IrunChannelProps {
|
|
|
437
482
|
}
|
|
438
483
|
declare function runChannel(props: IrunChannelProps): void;
|
|
439
484
|
|
|
485
|
+
interface IServerProvider<T, ST extends T> {
|
|
486
|
+
replace: IConstructor<T>;
|
|
487
|
+
with: IConstructor<ST>;
|
|
488
|
+
singleton?: true;
|
|
489
|
+
}
|
|
440
490
|
interface IServerConfig {
|
|
441
491
|
controllers: IConstructor<any>[];
|
|
442
|
-
|
|
443
|
-
chatBotAdapter?: IConstructor<IChatBotAdapter>;
|
|
492
|
+
providers?: IServerProvider<unknown, unknown>[];
|
|
444
493
|
}
|
|
445
494
|
declare function runServer(config: IServerConfig): void;
|
|
446
495
|
|
|
447
|
-
|
|
496
|
+
declare class SendOneTimePasswordRequest {
|
|
497
|
+
fromEmail: string;
|
|
498
|
+
toEmail: string;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
declare class ValidateOneTimePasswordRequest {
|
|
502
|
+
userEmail: string;
|
|
503
|
+
otp: string;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
interface ISendEmailRequest {
|
|
507
|
+
from: string;
|
|
508
|
+
to: string;
|
|
509
|
+
subject: string;
|
|
510
|
+
html: string;
|
|
511
|
+
}
|
|
512
|
+
interface IEmailService {
|
|
513
|
+
sendEmail(request: ISendEmailRequest): Promise<void>;
|
|
514
|
+
}
|
|
515
|
+
declare class EmailService implements IEmailService {
|
|
516
|
+
sendEmail(request: ISendEmailRequest): Promise<void>;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
interface IOtpService {
|
|
520
|
+
generate(): Promise<string>;
|
|
521
|
+
}
|
|
522
|
+
declare class OtpService implements IOtpService {
|
|
523
|
+
generate(): Promise<string>;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
declare class AuthenticationModule {
|
|
527
|
+
private userRepository;
|
|
528
|
+
private emailService;
|
|
529
|
+
private otpService;
|
|
530
|
+
private context;
|
|
531
|
+
constructor(userRepository: UserRepository, emailService: EmailService, otpService: OtpService, context: MessageContext);
|
|
532
|
+
sendOneTimePassword(request: SendOneTimePasswordRequest): Promise<string>;
|
|
533
|
+
validateOneTimePassword(request: ValidateOneTimePasswordRequest): Promise<string>;
|
|
534
|
+
protected generateOtpEmailHtml(otp: string, user: User): Promise<string>;
|
|
535
|
+
protected generateOtpEmailSubject(): Promise<string>;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
declare class RegisterUserWithEmailRequest {
|
|
539
|
+
email: string;
|
|
540
|
+
shortName: string;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
declare class RegisterUserModule {
|
|
544
|
+
private userRepository;
|
|
545
|
+
private context;
|
|
546
|
+
constructor(userRepository: UserRepository, context: MessageContext);
|
|
547
|
+
registerUserWithEmail(request: RegisterUserWithEmailRequest): Promise<string>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, EmailService, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItem, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type IEmailService, type IMessageContext, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IOtpService, type IParamConfig, type IParamDecoration, type IReceivedMessage, type IReceivedMessageItem, type ISendEmailRequest, type IServerConfig, type IServerProvider, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IchatControllerConfig, type IrunChannelProps, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, SendOneTimePasswordRequest, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, chatBot, chatController, cmd, container, inject, injectable, isOptional, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, runChannel, runServer, singleton, telegram };
|
package/dist/src/index.js
CHANGED
|
@@ -4,20 +4,8 @@ export { CmdChannel } from './channels/cmd/CmdChannel.js';
|
|
|
4
4
|
export { telegram } from './channels/telegram/@telegram.js';
|
|
5
5
|
export { TelegramChannelConfig } from './channels/telegram/TelegramChannelConfig.js';
|
|
6
6
|
export { TelegramChannel } from './channels/telegram/TelegramChannel.js';
|
|
7
|
-
export { RamChatMemory } from './chatbot/chat/repository/ram/RamChatMemory.js';
|
|
8
|
-
export { RamChatRepository } from './chatbot/chat/repository/ram/RamChatRepository.js';
|
|
9
|
-
export { ChatMemory } from './chatbot/chat/repository/IChatMemory.js';
|
|
10
|
-
export { ChatRepository } from './chatbot/chat/repository/IChatRepository.js';
|
|
11
|
-
export { Chat } from './chatbot/chat/Chat.js';
|
|
12
7
|
export { chatBot } from './chatbot/metadata/@chatBot.js';
|
|
13
8
|
export { ChatBotMetadataStore } from './chatbot/metadata/ChatBotMetadataStore.js';
|
|
14
|
-
export { ChatBot } from './chatbot/ChatBot.js';
|
|
15
|
-
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
16
|
-
export { Context } from './context/IContext.js';
|
|
17
|
-
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
18
|
-
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
19
|
-
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
20
|
-
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
21
9
|
export { mindsetFunction } from './mindset/metadata/functions/@mindsetFunction.js';
|
|
22
10
|
export { MINDSET_FUNCTION_DECORATION_FUNCTION } from './mindset/metadata/functions/decoratorNames.js';
|
|
23
11
|
export { mindset } from './mindset/metadata/mindsets/@mindset.js';
|
|
@@ -26,10 +14,34 @@ export { mindsetModule } from './mindset/metadata/modules/@mindsetModule.js';
|
|
|
26
14
|
export { MINDSET_MODULE_DECORATION_MODULE } from './mindset/metadata/modules/decoratorNames.js';
|
|
27
15
|
export { isOptional } from './mindset/metadata/params/@isOptional.js';
|
|
28
16
|
export { param } from './mindset/metadata/params/@param.js';
|
|
29
|
-
export {
|
|
17
|
+
export { PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM } from './mindset/metadata/params/decoratorNames.js';
|
|
30
18
|
export { Mindset } from './mindset/IMindset.js';
|
|
19
|
+
export { MindsetMetadataStore } from './mindset/metadata/MindsetMetadataStore.js';
|
|
31
20
|
export { MindsetOperator } from './mindset/MindsetOperator.js';
|
|
21
|
+
export { ChatBot } from './chatbot/ChatBot.js';
|
|
22
|
+
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
23
|
+
export { RamChatMemory } from './core/chat/repository/ram/RamChatMemory.js';
|
|
24
|
+
export { RamChatRepository } from './core/chat/repository/ram/RamChatRepository.js';
|
|
25
|
+
export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
26
|
+
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
27
|
+
export { Chat } from './core/chat/Chat.js';
|
|
28
|
+
export { User } from './core/user/User.js';
|
|
29
|
+
export { RamUserRepository } from './core/user/repository/ram/RamUserRepository.js';
|
|
30
|
+
export { UserRepository } from './core/user/repository/IUserRepository.js';
|
|
31
|
+
export { MessageContext } from './core/IMessageContext.js';
|
|
32
|
+
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
33
|
+
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
34
|
+
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
35
|
+
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
36
|
+
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
32
37
|
export { prepareChatContainer } from './server/prepareChatContainer.js';
|
|
33
38
|
export { runChannel } from './server/runChannel.js';
|
|
34
39
|
export { runServer } from './server/runServer.js';
|
|
40
|
+
export { SendOneTimePasswordRequest } from './pre-made/modules/authentication/requests/SendOneTimePasswordRequest.js';
|
|
41
|
+
export { ValidateOneTimePasswordRequest } from './pre-made/modules/authentication/requests/ValidateOneTimePasswordRequest.js';
|
|
42
|
+
export { AuthenticationModule } from './pre-made/modules/authentication/AuthenticationModule.js';
|
|
43
|
+
export { RegisterUserWithEmailRequest } from './pre-made/modules/register-user/requests/RegisterUserWithEmailRequest.js';
|
|
44
|
+
export { RegisterUserModule } from './pre-made/modules/register-user/RegisterUserModule.js';
|
|
45
|
+
export { EmailService } from './pre-made/services/EmailService.js';
|
|
46
|
+
export { OtpService } from './pre-made/services/OtpService.js';
|
|
35
47
|
export { Container } from './injection/Container.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class Mindset {
|
|
2
2
|
identity() {
|
|
3
|
-
throw new Error(
|
|
3
|
+
throw new Error('Method not implemented.');
|
|
4
4
|
}
|
|
5
5
|
skills() {
|
|
6
|
-
throw new Error(
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
7
|
}
|
|
8
8
|
limits() {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error('Method not implemented.');
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import '../../../core/chat/repository/ram/RamChatRepository.js';
|
|
3
|
+
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
|
+
import '../../../core/user/repository/ram/RamUserRepository.js';
|
|
5
|
+
import { UserRepository } from '../../../core/user/repository/IUserRepository.js';
|
|
6
|
+
import { MessageContext } from '../../../core/IMessageContext.js';
|
|
7
|
+
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
8
|
+
import 'reflect-metadata';
|
|
9
|
+
import '../../../injection/index.js';
|
|
10
|
+
import '../../../mindset/metadata/MindsetMetadataStore.js';
|
|
11
|
+
import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
|
|
12
|
+
import '../../../mindset/MindsetOperator.js';
|
|
13
|
+
import { EmailService } from '../../services/EmailService.js';
|
|
14
|
+
import { OtpService } from '../../services/OtpService.js';
|
|
15
|
+
import { SendOneTimePasswordRequest } from './requests/SendOneTimePasswordRequest.js';
|
|
16
|
+
import { ValidateOneTimePasswordRequest } from './requests/ValidateOneTimePasswordRequest.js';
|
|
17
|
+
|
|
18
|
+
let AuthenticationModule = class AuthenticationModule {
|
|
19
|
+
userRepository;
|
|
20
|
+
emailService;
|
|
21
|
+
otpService;
|
|
22
|
+
context;
|
|
23
|
+
constructor(userRepository, emailService, otpService, context) {
|
|
24
|
+
this.userRepository = userRepository;
|
|
25
|
+
this.emailService = emailService;
|
|
26
|
+
this.otpService = otpService;
|
|
27
|
+
this.context = context;
|
|
28
|
+
}
|
|
29
|
+
async sendOneTimePassword(request) {
|
|
30
|
+
const user = await this.userRepository.findByConnection({
|
|
31
|
+
channelName: 'EmailChannel',
|
|
32
|
+
id: request.toEmail,
|
|
33
|
+
});
|
|
34
|
+
if (!user)
|
|
35
|
+
return 'success';
|
|
36
|
+
const otp = await this.otpService.generate();
|
|
37
|
+
const html = await this.generateOtpEmailHtml(otp, user);
|
|
38
|
+
const subject = await this.generateOtpEmailSubject();
|
|
39
|
+
await this.emailService.sendEmail({
|
|
40
|
+
from: request.fromEmail,
|
|
41
|
+
to: request.toEmail,
|
|
42
|
+
subject,
|
|
43
|
+
html,
|
|
44
|
+
});
|
|
45
|
+
user.setValue('OTP', otp);
|
|
46
|
+
await this.userRepository.update(user);
|
|
47
|
+
return 'success';
|
|
48
|
+
}
|
|
49
|
+
async validateOneTimePassword(request) {
|
|
50
|
+
const user = await this.userRepository.findByConnection({
|
|
51
|
+
channelName: 'EmailChannel',
|
|
52
|
+
id: request.userEmail,
|
|
53
|
+
});
|
|
54
|
+
if (!user) {
|
|
55
|
+
throw new Error('Invalid OTP');
|
|
56
|
+
}
|
|
57
|
+
const otp = user.getValue('OTP');
|
|
58
|
+
if (otp !== request.otp) {
|
|
59
|
+
throw new Error('Invalid OTP');
|
|
60
|
+
}
|
|
61
|
+
user.addConnection(this.context.message.userConnection);
|
|
62
|
+
await this.userRepository.update(user);
|
|
63
|
+
return 'success';
|
|
64
|
+
}
|
|
65
|
+
async generateOtpEmailHtml(otp, user) {
|
|
66
|
+
return `<p>Your OTP Code is ${otp}</p>`;
|
|
67
|
+
}
|
|
68
|
+
async generateOtpEmailSubject() {
|
|
69
|
+
return 'OTP Code';
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__decorate([
|
|
73
|
+
mindsetFunction({
|
|
74
|
+
description: 'Send an One Time Password to the user when want authenticate',
|
|
75
|
+
}),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [SendOneTimePasswordRequest]),
|
|
78
|
+
__metadata("design:returntype", Promise)
|
|
79
|
+
], AuthenticationModule.prototype, "sendOneTimePassword", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
mindsetFunction({
|
|
82
|
+
description: 'Send an One Time Password to the user when want authenticate',
|
|
83
|
+
}),
|
|
84
|
+
__metadata("design:type", Function),
|
|
85
|
+
__metadata("design:paramtypes", [ValidateOneTimePasswordRequest]),
|
|
86
|
+
__metadata("design:returntype", Promise)
|
|
87
|
+
], AuthenticationModule.prototype, "validateOneTimePassword", null);
|
|
88
|
+
AuthenticationModule = __decorate([
|
|
89
|
+
mindsetModule({
|
|
90
|
+
description: 'Provide authentication methods',
|
|
91
|
+
language: 'english',
|
|
92
|
+
}),
|
|
93
|
+
__metadata("design:paramtypes", [UserRepository,
|
|
94
|
+
EmailService,
|
|
95
|
+
OtpService,
|
|
96
|
+
MessageContext])
|
|
97
|
+
], AuthenticationModule);
|
|
98
|
+
|
|
99
|
+
export { AuthenticationModule };
|