@wabot-dev/framework 0.1.0-beta.6 → 0.1.0-beta.61

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.
Files changed (185) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
  3. package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
  4. package/dist/src/addon/auth/api-key/ApiKey.js +53 -0
  5. package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
  6. package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
  7. package/dist/src/addon/auth/api-key/ApiKeyRepository.js +35 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +28 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +42 -0
  10. package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
  11. package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
  12. package/dist/src/addon/auth/jwt/Jwt.js +53 -0
  13. package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  14. package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
  15. package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
  16. package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
  17. package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
  18. package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
  19. package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
  20. package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
  21. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
  22. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  23. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  24. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
  25. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
  26. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
  27. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
  28. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  29. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
  30. package/dist/src/addon/chat-controller/cmd/@cmd.js +23 -0
  31. package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
  34. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  35. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +9 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -0
  38. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  39. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
  40. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  41. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  42. package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
  43. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +20 -41
  44. package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
  45. package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +26 -20
  46. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
  47. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
  48. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +60 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
  51. package/dist/src/core/auth/Auth.js +24 -0
  52. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
  53. package/dist/src/core/env/Env.js +39 -0
  54. package/dist/src/core/error/CustomError.js +15 -0
  55. package/dist/src/core/injection/index.js +4 -0
  56. package/dist/src/core/mapper/Mapper.js +42 -0
  57. package/dist/src/core/password/Password.js +30 -0
  58. package/dist/src/core/random/Random.js +65 -0
  59. package/dist/src/core/storable/Storable.js +8 -0
  60. package/dist/src/core/validation/core/validateArray.js +51 -0
  61. package/dist/src/core/validation/core/validateIsOptional.js +5 -0
  62. package/dist/src/core/validation/core/validateModel.js +36 -0
  63. package/dist/src/core/validation/metadata/@isArray.js +18 -0
  64. package/dist/src/core/validation/metadata/@isModel.js +18 -0
  65. package/dist/src/core/validation/metadata/@isOptional.js +17 -0
  66. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  67. package/dist/src/core/validation/modelInfo.js +9 -0
  68. package/dist/src/core/validation/validate.js +11 -0
  69. package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
  70. package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
  71. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  72. package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
  73. package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
  74. package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
  75. package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
  76. package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
  77. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  78. package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
  79. package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
  80. package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
  81. package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
  82. package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
  83. package/dist/src/core/validation/validators/max/@max.js +18 -0
  84. package/dist/src/core/validation/validators/max/validateMax.js +17 -0
  85. package/dist/src/core/validation/validators/min/@min.js +18 -0
  86. package/dist/src/core/validation/validators/min/validateMin.js +17 -0
  87. package/dist/src/feature/async/@command.js +11 -0
  88. package/dist/src/feature/async/@commandHandler.js +12 -0
  89. package/dist/src/feature/async/Async.js +38 -0
  90. package/dist/src/feature/async/Command.js +9 -0
  91. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  92. package/dist/src/feature/async/Job.js +27 -0
  93. package/dist/src/feature/async/JobRepository.js +31 -0
  94. package/dist/src/feature/async/JobRunner.js +48 -0
  95. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  96. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  97. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  98. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  99. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  100. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  101. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  102. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  103. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  104. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  105. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  106. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  107. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  108. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  109. package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
  110. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  111. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  112. package/dist/src/{mindset → feature/mindset}/IMindset.js +3 -0
  113. package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
  114. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  115. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  116. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  117. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  118. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  119. package/dist/src/feature/money/Money.js +61 -0
  120. package/dist/src/feature/money/MoneyDto.js +22 -0
  121. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +30 -9
  122. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  123. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  124. package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
  125. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  126. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  127. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  128. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  129. package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
  130. package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
  131. package/dist/src/feature/rest-controller/metadata/methodDecorator.js +19 -0
  132. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  133. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  134. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  135. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  136. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  137. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  138. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  139. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  140. package/dist/src/index.d.ts +1210 -576
  141. package/dist/src/index.js +147 -76
  142. package/package.json +10 -4
  143. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
  144. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  145. package/dist/src/channels/cmd/@cmd.js +0 -18
  146. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  147. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  148. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  149. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  150. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  151. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  152. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  153. package/dist/src/chatbot/ChatBot.js +0 -51
  154. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  155. package/dist/src/controller/channel/UserResolver.js +0 -21
  156. package/dist/src/core/IMessageContext.js +0 -12
  157. package/dist/src/core/chat/ChatItem.js +0 -15
  158. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  159. package/dist/src/core/user/IUserRepository.js +0 -19
  160. package/dist/src/core/user/User.js +0 -26
  161. package/dist/src/env/WabotEnv.js +0 -27
  162. package/dist/src/injection/index.js +0 -4
  163. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  164. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  165. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  166. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  167. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  168. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  169. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  170. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  171. package/dist/src/pre-made/service/EmailService.js +0 -13
  172. package/dist/src/pre-made/service/OtpService.js +0 -14
  173. package/dist/src/server/prepareChatContainer.js +0 -43
  174. package/dist/src/server/runChannel.js +0 -27
  175. package/dist/src/server/runServer.js +0 -40
  176. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  177. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  178. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  179. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  180. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  181. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  182. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  183. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  184. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  185. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,59 +0,0 @@
1
- class WhatsAppReceiver {
2
- logger;
3
- listeners = new Map();
4
- constructor(logger) {
5
- this.logger = logger;
6
- }
7
- listenMessage(request) {
8
- this.listeners.set(request.to, request.listener);
9
- }
10
- async handlePayload(payload) {
11
- try {
12
- for (const entry of payload.entry) {
13
- for (const change of entry.changes) {
14
- if (change.field !== 'messages' || !change.value.messages || !change.value.contacts) {
15
- continue;
16
- }
17
- for (const message of change.value.messages) {
18
- const contact = change.value.contacts.find((x) => x.wa_id === message.from);
19
- if (!contact) {
20
- continue;
21
- }
22
- await this.emmitMessage(change.value.metadata, message, contact);
23
- }
24
- }
25
- }
26
- }
27
- catch (err) {
28
- this.logger.error(err);
29
- }
30
- }
31
- async emmitMessage(metadata, message, contact) {
32
- const listener = this.listeners.get(metadata.display_phone_number);
33
- if (!listener) {
34
- return;
35
- }
36
- if (message.type !== 'text') {
37
- this.logger.error(`message type ${message.type} is not supported yet`);
38
- return;
39
- }
40
- const channelName = 'WhatsAppChannel';
41
- const chatConnection = {
42
- id: contact.wa_id,
43
- chatType: 'PRIVATE',
44
- channelName,
45
- };
46
- const userConnection = {
47
- id: contact.wa_id,
48
- channelName,
49
- };
50
- await listener({
51
- chatConnection,
52
- userConnection,
53
- senderName: contact.profile.name,
54
- text: message.text.body,
55
- });
56
- }
57
- }
58
-
59
- export { WhatsAppReceiver };
@@ -1,32 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Logger } from '../../logger/Logger.js';
3
- import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
5
- import { devListentEvent } from '../wabot/WabotDevSocketContracts.js';
6
- import { singleton } from 'tsyringe';
7
- import { container } from '../../injection/index.js';
8
-
9
- let WhatsAppReceiverByDevConnection = class WhatsAppReceiverByDevConnection extends WhatsAppReceiver {
10
- wabotDevConnection;
11
- constructor(wabotDevConnection) {
12
- super(new Logger('wabot:whatsapp-receiver-by-dev-connection'));
13
- this.wabotDevConnection = wabotDevConnection;
14
- }
15
- async connect() {
16
- const socket = await this.wabotDevConnection.getSocket();
17
- socket.on(devListentEvent.DEV_WATSAPP_WEBHOOK, (payload) => {
18
- this.handlePayload(payload);
19
- });
20
- }
21
- };
22
- WhatsAppReceiverByDevConnection = __decorate([
23
- singleton(),
24
- __metadata("design:paramtypes", [WabotDevConnection])
25
- ], WhatsAppReceiverByDevConnection);
26
- if (WabotDevConnection.isTokenAvailable()) {
27
- container.register(WhatsAppReceiver, {
28
- useClass: WhatsAppReceiverByDevConnection,
29
- });
30
- }
31
-
32
- export { WhatsAppReceiverByDevConnection };
@@ -1,63 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Logger } from '../../logger/Logger.js';
3
- import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { singleton } from 'tsyringe';
5
- import { ExpressProvider } from '../express/ExpressProvider.js';
6
- import { WhatsAppRepository } from './WhatsAppRepository.js';
7
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
8
- import { container } from '../../injection/index.js';
9
-
10
- let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
11
- expressProvider;
12
- whatsAppRepository;
13
- expressApp;
14
- webhookPath = '/whatsapp/web-hook/:slug';
15
- constructor(expressProvider, whatsAppRepository) {
16
- super(new Logger('wabot:whatsapp-receiver-by-webhook'));
17
- this.expressProvider = expressProvider;
18
- this.whatsAppRepository = whatsAppRepository;
19
- this.expressApp = this.expressProvider.getExpress();
20
- }
21
- async connect() {
22
- this.expressApp.get(this.webhookPath, async (req, res) => {
23
- try {
24
- let mode = req.query['hub.mode'];
25
- let token = req.query['hub.verify_token'];
26
- let challenge = req.query['hub.challenge'];
27
- if (!mode || !token || !challenge) {
28
- res.sendStatus(400);
29
- return;
30
- }
31
- const whatsApp = await this.whatsAppRepository.findBySlug(req.params.slug);
32
- if (!whatsApp || mode !== 'subscribe' || token !== whatsApp.getVerifyToken()) {
33
- res.sendStatus(403);
34
- return;
35
- }
36
- res.status(200).send(challenge);
37
- }
38
- catch (e) {
39
- this.logger.error(e);
40
- res.sendStatus(500);
41
- return;
42
- }
43
- });
44
- this.expressApp.post(this.webhookPath, (req, res) => {
45
- const payload = req.body;
46
- this.handlePayload(payload);
47
- res.sendStatus(200);
48
- });
49
- this.expressProvider.listen();
50
- }
51
- };
52
- WhatsAppReceiverByWebHook = __decorate([
53
- singleton(),
54
- __metadata("design:paramtypes", [ExpressProvider,
55
- WhatsAppRepository])
56
- ], WhatsAppReceiverByWebHook);
57
- if (!WabotDevConnection.isTokenAvailable()) {
58
- container.register(WhatsAppReceiver, {
59
- useClass: WhatsAppReceiverByWebHook,
60
- });
61
- }
62
-
63
- export { WhatsAppReceiverByWebHook };
@@ -1,61 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { WhatsAppSender } from './WhatsAppSender.js';
3
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
4
- import { devEmitEvent } from '../wabot/WabotDevSocketContracts.js';
5
- import { Logger } from '../../logger/Logger.js';
6
- import { ChatRepository } from '../../core/chat/repository/IChatRepository.js';
7
- import '../../core/user/IUserRepository.js';
8
- import { singleton, container } from '../../injection/index.js';
9
- import { ChatResolver } from '../../controller/channel/ChatResolver.js';
10
- import '../../controller/channel/UserResolver.js';
11
- import '../../controller/metadata/ControllerMetadataStore.js';
12
- import { WhatsAppRepository } from './WhatsAppRepository.js';
13
-
14
- let WhatsAppSenderByDevConnection = class WhatsAppSenderByDevConnection extends WhatsAppSender {
15
- wabotDevConnection;
16
- constructor(wabotDevConnection, chatRepository, chatResolver, whatsAppRepository) {
17
- super(new Logger('wabot:whatsapp-sender-by-dev-connection'), chatRepository, chatResolver, whatsAppRepository);
18
- this.wabotDevConnection = wabotDevConnection;
19
- }
20
- async handleSendRequest(request) {
21
- const socket = await this.wabotDevConnection.getSocket();
22
- const req = {
23
- from: request.from,
24
- to: request.to,
25
- message: request.message,
26
- };
27
- const ack = await socket.emitWithAck(devEmitEvent.DEV_SEND_WHATSAPP, req);
28
- if (ack != 'OK') {
29
- throw new Error(`Error sending WhatsApp template: ${ack}`);
30
- }
31
- }
32
- async handleSendTemplateRequest(request) {
33
- const socket = await this.wabotDevConnection.getSocket();
34
- const req = {
35
- from: request.from,
36
- to: request.to,
37
- message: request.templateMessage,
38
- };
39
- const ack = await socket.emitWithAck(devEmitEvent.DEV_SEND_WHATSAPP_TEMPLATE, req);
40
- if (ack != 'OK') {
41
- throw new Error(`Error sending WhatsApp template: ${ack}`);
42
- }
43
- }
44
- async handleGetWhatsAppTemplate(request) {
45
- throw new Error("Not implemented");
46
- }
47
- };
48
- WhatsAppSenderByDevConnection = __decorate([
49
- singleton(),
50
- __metadata("design:paramtypes", [WabotDevConnection,
51
- ChatRepository,
52
- ChatResolver,
53
- WhatsAppRepository])
54
- ], WhatsAppSenderByDevConnection);
55
- if (WabotDevConnection.isTokenAvailable()) {
56
- container.register(WhatsAppSender, {
57
- useClass: WhatsAppSenderByDevConnection,
58
- });
59
- }
60
-
61
- export { WhatsAppSenderByDevConnection };
@@ -1,51 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
3
- import '../core/chat/repository/IChatRepository.js';
4
- import { ChatItem } from '../core/chat/ChatItem.js';
5
- import '../core/user/IUserRepository.js';
6
- import { injectable } from '../injection/index.js';
7
- import { ChatBotAdapter } from './ChatBotAdapter.js';
8
-
9
- let ChatBot = class ChatBot {
10
- memory;
11
- adapter;
12
- constructor(memory, adapter) {
13
- this.memory = memory;
14
- this.adapter = adapter;
15
- this.memory = memory;
16
- }
17
- async sendMessage(message, callback) {
18
- const newChatItem = new ChatItem({
19
- type: 'CONNECTION_MESSAGE',
20
- content: message,
21
- });
22
- await this.memory.create(newChatItem);
23
- this.processLoop(callback);
24
- }
25
- async processLoop(callback) {
26
- const prevChatItems = await this.memory.findLastItems(10);
27
- if (prevChatItems.length === 0) {
28
- return;
29
- }
30
- const lastChatItem = prevChatItems[prevChatItems.length - 1];
31
- const lastItemType = lastChatItem.getType();
32
- if (lastItemType === 'BOT_MESSAGE') {
33
- return;
34
- }
35
- const newChatItem = await this.adapter.generateNextChatItem(prevChatItems);
36
- await this.memory.create(newChatItem);
37
- const newChatItemData = newChatItem.getData();
38
- if (newChatItemData.type === 'BOT_MESSAGE') {
39
- callback(newChatItemData.content);
40
- return;
41
- }
42
- this.processLoop(callback);
43
- }
44
- };
45
- ChatBot = __decorate([
46
- injectable(),
47
- __metadata("design:paramtypes", [ChatMemory,
48
- ChatBotAdapter])
49
- ], ChatBot);
50
-
51
- export { ChatBot };
@@ -1,72 +0,0 @@
1
- import '../core/chat/repository/IChatRepository.js';
2
- import { ChatItem } from '../core/chat/ChatItem.js';
3
- import '../core/user/IUserRepository.js';
4
-
5
- class ChatBotAdapter {
6
- mindset;
7
- constructor(mindset) {
8
- this.mindset = mindset;
9
- }
10
- generateNextChatItem(chatItems) {
11
- throw new Error('Not implemented');
12
- }
13
- async systemPrompt() {
14
- let [identity, skills, limits] = await Promise.all([
15
- this.mindset.identity(),
16
- this.mindset.skills(),
17
- this.mindset.limits(),
18
- ]);
19
- const language = identity.language.replaceAll('#', ' ');
20
- const name = identity.name.replaceAll('#', ' ');
21
- const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
22
- const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
23
- skills = skills.replaceAll('#', ' ');
24
- limits = limits.replaceAll('#', ' ');
25
- const systemPrompt = `
26
- # System Instructions
27
- you should act as a assistant.
28
- your main language is ${language}.
29
- your name is ${name}.
30
- ${age ? 'you are ' + age + ' years old.' : ''}
31
-
32
- ${personality ? '## Personality (in your main language) \n' + personality : ''}
33
-
34
- ## Skills (in your main language)
35
- ${skills}
36
-
37
- ## System limitations (in your main language)
38
- ${limits}
39
-
40
- ## Chat memory
41
- Next you will receive a chat history,
42
- you should use this information to answer the user.
43
- `;
44
- return systemPrompt;
45
- }
46
- async buildBotMessageItem(text) {
47
- const senderName = (await this.mindset.identity()).name;
48
- const newBotMessage = new ChatItem({
49
- type: 'BOT_MESSAGE',
50
- content: {
51
- senderName,
52
- text,
53
- },
54
- });
55
- return newBotMessage;
56
- }
57
- async buildFunctionCallItem(id, functionName, functionArguments) {
58
- const functionResult = await this.mindset.callFunction(functionName, functionArguments);
59
- const newFunctionCall = new ChatItem({
60
- type: 'FUNCTION_CALL',
61
- content: {
62
- id,
63
- name: functionName,
64
- arguments: functionArguments,
65
- result: functionResult,
66
- },
67
- });
68
- return newFunctionCall;
69
- }
70
- }
71
-
72
- export { ChatBotAdapter };
@@ -1,21 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../core/chat/repository/IChatRepository.js';
3
- import { UserRepository } from '../../core/user/IUserRepository.js';
4
- import { singleton } from '../../injection/index.js';
5
-
6
- let UserResolver = class UserResolver {
7
- userRepository;
8
- constructor(userRepository) {
9
- this.userRepository = userRepository;
10
- }
11
- async resolve(connection) {
12
- let user = await this.userRepository.findByConnection(connection);
13
- return user;
14
- }
15
- };
16
- UserResolver = __decorate([
17
- singleton(),
18
- __metadata("design:paramtypes", [UserRepository])
19
- ], UserResolver);
20
-
21
- export { UserResolver };
@@ -1,12 +0,0 @@
1
- class MessageContext {
2
- message;
3
- chat;
4
- user;
5
- constructor(message, chat, user) {
6
- this.message = message;
7
- this.chat = chat;
8
- this.user = user;
9
- }
10
- }
11
-
12
- export { MessageContext };
@@ -1,15 +0,0 @@
1
- import { Persistent } from '../Persistent.js';
2
-
3
- class ChatItem extends Persistent {
4
- getType() {
5
- return this.data.type;
6
- }
7
- getContent() {
8
- return this.data.content;
9
- }
10
- getData() {
11
- return this.data;
12
- }
13
- }
14
-
15
- export { ChatItem };
@@ -1,10 +0,0 @@
1
- class ChatMemory {
2
- findLastItems(count) {
3
- throw new Error('Method not implemented.');
4
- }
5
- create(item) {
6
- throw new Error('Method not implemented.');
7
- }
8
- }
9
-
10
- export { ChatMemory };
@@ -1,19 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { singleton } from '../../injection/index.js';
3
-
4
- let UserRepository = class UserRepository {
5
- create(chat) {
6
- throw new Error('Method not implemented.');
7
- }
8
- update(chat) {
9
- throw new Error('Method not implemented.');
10
- }
11
- findByConnection(query) {
12
- throw new Error('Method not implemented.');
13
- }
14
- };
15
- UserRepository = __decorate([
16
- singleton()
17
- ], UserRepository);
18
-
19
- export { UserRepository };
@@ -1,26 +0,0 @@
1
- import { Persistent } from '../Persistent.js';
2
-
3
- class User extends Persistent {
4
- constructor(data) {
5
- super(data);
6
- }
7
- hasConnection(connection) {
8
- for (const con of this.data.connections) {
9
- if (con.channelName === connection.channelName && con.id === connection.id) {
10
- return true;
11
- }
12
- }
13
- return false;
14
- }
15
- getValue(key) {
16
- return this.data.keyValueData[key];
17
- }
18
- setValue(key, value) {
19
- this.data.keyValueData[key] = value;
20
- }
21
- addConnection(connection) {
22
- this.data.connections.push(connection);
23
- }
24
- }
25
-
26
- export { User };
@@ -1,27 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { singleton } from 'tsyringe';
3
-
4
- let WabotEnv = class WabotEnv {
5
- envType;
6
- constructor() {
7
- this.envType = process.env.WABOT_ENV ?? 'development';
8
- }
9
- isDevelopment() {
10
- return this.envType === 'development';
11
- }
12
- isProduction() {
13
- return this.envType === 'production';
14
- }
15
- requireString(varName) {
16
- const value = process.env[varName];
17
- if (!value)
18
- throw new Error(`Env Variable ${varName} is required`);
19
- return value;
20
- }
21
- };
22
- WabotEnv = __decorate([
23
- singleton(),
24
- __metadata("design:paramtypes", [])
25
- ], WabotEnv);
26
-
27
- export { WabotEnv };
@@ -1,4 +0,0 @@
1
- await import('reflect-metadata');
2
- const { injectable, container, singleton, inject } = await import('tsyringe');
3
-
4
- export { container, inject, injectable, singleton };
@@ -1,21 +0,0 @@
1
- import 'reflect-metadata';
2
- import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
3
- import { container } from '../../../injection/index.js';
4
- import { PARAM_DECORATION_IS_OPTIONAL } from './decoratorNames.js';
5
-
6
- function isOptional() {
7
- return (target, propertyKey) => {
8
- const paramName = propertyKey.toString();
9
- const paramType = Reflect.getMetadata('design:type', target, paramName);
10
- const store = container.resolve(MindsetMetadataStore);
11
- store.saveParamDecoration({
12
- decorationName: PARAM_DECORATION_IS_OPTIONAL,
13
- paramType: paramType,
14
- paramName: paramName,
15
- constructor: target.constructor,
16
- decorationConfig: {},
17
- });
18
- };
19
- }
20
-
21
- export { isOptional };
@@ -1,97 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../../core/chat/repository/IChatRepository.js';
3
- import { UserRepository } from '../../../core/user/IUserRepository.js';
4
- import { MessageContext } from '../../../core/IMessageContext.js';
5
- import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
6
- import 'reflect-metadata';
7
- import '../../../injection/index.js';
8
- import '../../../mindset/metadata/MindsetMetadataStore.js';
9
- import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
10
- import '../../../mindset/MindsetOperator.js';
11
- import { EmailService } from '../../service/EmailService.js';
12
- import { OtpService } from '../../service/OtpService.js';
13
- import { SendOneTimePasswordRequest } from './requests/SendOneTimePasswordRequest.js';
14
- import { ValidateOneTimePasswordRequest } from './requests/ValidateOneTimePasswordRequest.js';
15
-
16
- let AuthenticationModule = class AuthenticationModule {
17
- userRepository;
18
- emailService;
19
- otpService;
20
- context;
21
- constructor(userRepository, emailService, otpService, context) {
22
- this.userRepository = userRepository;
23
- this.emailService = emailService;
24
- this.otpService = otpService;
25
- this.context = context;
26
- }
27
- async sendOneTimePassword(request) {
28
- const user = await this.userRepository.findByConnection({
29
- channelName: 'EmailChannel',
30
- id: request.toEmail,
31
- });
32
- if (!user)
33
- return 'success';
34
- const otp = await this.otpService.generate();
35
- const html = await this.generateOtpEmailHtml(otp, user);
36
- const subject = await this.generateOtpEmailSubject();
37
- await this.emailService.sendEmail({
38
- from: request.fromEmail,
39
- to: request.toEmail,
40
- subject,
41
- html,
42
- });
43
- user.setValue('OTP', otp);
44
- await this.userRepository.update(user);
45
- return 'success';
46
- }
47
- async validateOneTimePassword(request) {
48
- const user = await this.userRepository.findByConnection({
49
- channelName: 'EmailChannel',
50
- id: request.userEmail,
51
- });
52
- if (!user) {
53
- throw new Error('Invalid OTP');
54
- }
55
- const otp = user.getValue('OTP');
56
- if (otp !== request.otp) {
57
- throw new Error('Invalid OTP');
58
- }
59
- user.addConnection(this.context.message.userConnection);
60
- await this.userRepository.update(user);
61
- return 'success';
62
- }
63
- async generateOtpEmailHtml(otp, user) {
64
- return `<p>Your OTP Code is ${otp}</p>`;
65
- }
66
- async generateOtpEmailSubject() {
67
- return 'OTP Code';
68
- }
69
- };
70
- __decorate([
71
- mindsetFunction({
72
- description: 'Send an One Time Password to the user when want authenticate',
73
- }),
74
- __metadata("design:type", Function),
75
- __metadata("design:paramtypes", [SendOneTimePasswordRequest]),
76
- __metadata("design:returntype", Promise)
77
- ], AuthenticationModule.prototype, "sendOneTimePassword", null);
78
- __decorate([
79
- mindsetFunction({
80
- description: 'Send an One Time Password to the user when want authenticate',
81
- }),
82
- __metadata("design:type", Function),
83
- __metadata("design:paramtypes", [ValidateOneTimePasswordRequest]),
84
- __metadata("design:returntype", Promise)
85
- ], AuthenticationModule.prototype, "validateOneTimePassword", null);
86
- AuthenticationModule = __decorate([
87
- mindsetModule({
88
- description: 'Provide authentication methods',
89
- language: 'english',
90
- }),
91
- __metadata("design:paramtypes", [UserRepository,
92
- EmailService,
93
- OtpService,
94
- MessageContext])
95
- ], AuthenticationModule);
96
-
97
- export { AuthenticationModule };
@@ -1,25 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import 'reflect-metadata';
3
- import '../../../../injection/index.js';
4
- import '../../../../mindset/metadata/MindsetMetadataStore.js';
5
- import { param } from '../../../../mindset/metadata/params/@param.js';
6
- import '../../../../mindset/MindsetOperator.js';
7
-
8
- class SendOneTimePasswordRequest {
9
- fromEmail = '';
10
- toEmail = '';
11
- }
12
- __decorate([
13
- param({
14
- description: 'Sender Email address',
15
- }),
16
- __metadata("design:type", String)
17
- ], SendOneTimePasswordRequest.prototype, "fromEmail", void 0);
18
- __decorate([
19
- param({
20
- description: 'Recipient Email Address, to send one time password',
21
- }),
22
- __metadata("design:type", String)
23
- ], SendOneTimePasswordRequest.prototype, "toEmail", void 0);
24
-
25
- export { SendOneTimePasswordRequest };
@@ -1,25 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import 'reflect-metadata';
3
- import '../../../../injection/index.js';
4
- import '../../../../mindset/metadata/MindsetMetadataStore.js';
5
- import { param } from '../../../../mindset/metadata/params/@param.js';
6
- import '../../../../mindset/MindsetOperator.js';
7
-
8
- class ValidateOneTimePasswordRequest {
9
- userEmail = '';
10
- otp = '';
11
- }
12
- __decorate([
13
- param({
14
- description: 'User Email',
15
- }),
16
- __metadata("design:type", String)
17
- ], ValidateOneTimePasswordRequest.prototype, "userEmail", void 0);
18
- __decorate([
19
- param({
20
- description: 'Otp provided by the User',
21
- }),
22
- __metadata("design:type", String)
23
- ], ValidateOneTimePasswordRequest.prototype, "otp", void 0);
24
-
25
- export { ValidateOneTimePasswordRequest };