@wabot-dev/framework 0.1.0-beta.6 → 0.1.0-beta.60
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/addon/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
- package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +53 -0
- package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +35 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +28 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +42 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +23 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +20 -41
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +26 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +60 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/core/auth/Auth.js +24 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +65 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateIsOptional.js +5 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/core/validation/metadata/@isArray.js +18 -0
- package/dist/src/core/validation/metadata/@isModel.js +18 -0
- package/dist/src/core/validation/metadata/@isOptional.js +17 -0
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/core/validation/validate.js +11 -0
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
- package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
- package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
- package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
- package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
- package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
- package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
- package/dist/src/core/validation/validators/max/@max.js +18 -0
- package/dist/src/core/validation/validators/max/validateMax.js +17 -0
- package/dist/src/core/validation/validators/min/@min.js +18 -0
- package/dist/src/core/validation/validators/min/validateMin.js +17 -0
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +27 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +48 -0
- package/dist/src/feature/async/JobsEventsHub.js +36 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +3 -0
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +30 -9
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
- package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
- package/dist/src/feature/rest-controller/metadata/methodDecorator.js +19 -0
- package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
- package/dist/src/index.d.ts +1202 -575
- package/dist/src/index.js +145 -76
- package/package.json +10 -4
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Logger } from '
|
|
3
|
-
import { WhatsAppSender } from '
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
6
|
-
import { ChatResolver } from '
|
|
7
|
-
import '
|
|
8
|
-
import {
|
|
9
|
-
import '
|
|
10
|
-
import
|
|
11
|
-
import
|
|
2
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
3
|
+
import { WhatsAppSender } from '../WhatsAppSender.js';
|
|
4
|
+
import { singleton } from '../../../../core/injection/index.js';
|
|
5
|
+
import '../../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
6
|
+
import { ChatResolver } from '../../../../feature/chat-controller/ChatResolver.js';
|
|
7
|
+
import '../../../../feature/chat-bot/ChatBot.js';
|
|
8
|
+
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
9
|
+
import 'uuid';
|
|
10
|
+
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
11
|
+
import 'reflect-metadata';
|
|
12
|
+
import '../../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
13
|
+
import '../../../../feature/mindset/MindsetOperator.js';
|
|
14
|
+
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
12
15
|
|
|
13
16
|
let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSender {
|
|
17
|
+
logger = new Logger('wabot:whatsapp-sender-by-cloud-api');
|
|
14
18
|
constructor(chatRepository, chatResolver, whatsAppRepository) {
|
|
15
|
-
super(
|
|
19
|
+
super(chatRepository, chatResolver, whatsAppRepository);
|
|
16
20
|
}
|
|
17
|
-
async
|
|
21
|
+
async sendWhatsApp(request, options) {
|
|
18
22
|
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
19
23
|
if (!whatsApp) {
|
|
20
24
|
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
@@ -43,8 +47,11 @@ let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSe
|
|
|
43
47
|
if (!response.ok) {
|
|
44
48
|
throw new Error(JSON.stringify(data));
|
|
45
49
|
}
|
|
50
|
+
if (options?.writeChatMemory) {
|
|
51
|
+
await this.writePrivateChatMemory(request.message, request.to);
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
|
-
async
|
|
54
|
+
async sendWhatsAppTemplate(request, options) {
|
|
48
55
|
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
49
56
|
if (!whatsApp) {
|
|
50
57
|
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
@@ -80,8 +87,12 @@ let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSe
|
|
|
80
87
|
if (!response.ok) {
|
|
81
88
|
throw new Error(JSON.stringify(data));
|
|
82
89
|
}
|
|
90
|
+
if (options?.writeChatMemory) {
|
|
91
|
+
const message = await this.mapTemplateToChatMessage(request);
|
|
92
|
+
await this.writePrivateChatMemory(message, request.to);
|
|
93
|
+
}
|
|
83
94
|
}
|
|
84
|
-
async
|
|
95
|
+
async getWhatsAppTemplate(request) {
|
|
85
96
|
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
86
97
|
if (!whatsApp) {
|
|
87
98
|
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
@@ -104,7 +115,7 @@ let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSe
|
|
|
104
115
|
return template;
|
|
105
116
|
}
|
|
106
117
|
catch (error) {
|
|
107
|
-
|
|
118
|
+
this.logger.error(error);
|
|
108
119
|
throw error;
|
|
109
120
|
}
|
|
110
121
|
}
|
|
@@ -115,10 +126,5 @@ WhatsAppSenderByCloudApi = __decorate([
|
|
|
115
126
|
ChatResolver,
|
|
116
127
|
WhatsAppRepository])
|
|
117
128
|
], WhatsAppSenderByCloudApi);
|
|
118
|
-
if (!WabotDevConnection.isTokenAvailable()) {
|
|
119
|
-
container.register(WhatsAppSender, {
|
|
120
|
-
useClass: WhatsAppSenderByCloudApi,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
129
|
|
|
124
130
|
export { WhatsAppSenderByCloudApi };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const WHATSAPP_PROXY_SEND_MESSAGE_EVENT = 'sendMessage';
|
|
2
|
+
const WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT = 'listenMessage';
|
|
3
|
+
const WHATSAPP_MESSAGE_EVENT = 'message';
|
|
4
|
+
|
|
5
|
+
export { WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { WhatsAppReceiver } from '../WhatsAppReceiver.js';
|
|
3
|
+
import { injectable } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import { WHATSAPP_MESSAGE_EVENT } from './WhatsAppProxyContracts.js';
|
|
6
|
+
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
7
|
+
|
|
8
|
+
let WhatsAppReceiverByWabotProxy = class WhatsAppReceiverByWabotProxy extends WhatsAppReceiver {
|
|
9
|
+
connection;
|
|
10
|
+
loger = new Logger('wabot:whats-app-receiver-by-wabot-proxy');
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
super();
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
}
|
|
15
|
+
async connect() {
|
|
16
|
+
// Nothing
|
|
17
|
+
}
|
|
18
|
+
listenMessage(request) {
|
|
19
|
+
this.connection.getSocket().then(async (socket) => {
|
|
20
|
+
const req = {
|
|
21
|
+
event: 'listenMessage',
|
|
22
|
+
data: {
|
|
23
|
+
to: [request.to],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const response = await socket.emitWithAck(req.event, req.data);
|
|
27
|
+
if (response && typeof response == 'object' && response['error']) {
|
|
28
|
+
this.loger.error(response.error);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else if (!response ||
|
|
32
|
+
typeof response !== 'object' ||
|
|
33
|
+
!Array.isArray(response.from) ||
|
|
34
|
+
!Array.isArray(response.to)) {
|
|
35
|
+
this.loger.error('unknown response');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.loger.trace(`succes add whats-app proxy listener for messages from [${response.from.join(',')}] to [${response.to.join(',')}]`);
|
|
39
|
+
socket.on(WHATSAPP_MESSAGE_EVENT, (data, callback) => {
|
|
40
|
+
if (data.to !== request.to) {
|
|
41
|
+
throw new Error(`expecting message to '${request.to}' but received to='${data.to}'`);
|
|
42
|
+
}
|
|
43
|
+
callback({ success: true });
|
|
44
|
+
this.loger.trace(`success receive message from '${data.from}' to '${data.to}'`);
|
|
45
|
+
request.listener({
|
|
46
|
+
chatConnection: {
|
|
47
|
+
channelName: 'WhatsAppChannel',
|
|
48
|
+
id: data.from,
|
|
49
|
+
},
|
|
50
|
+
message: {
|
|
51
|
+
text: data.content.text,
|
|
52
|
+
senderName: data.senderName,
|
|
53
|
+
senderId: data.from,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
WhatsAppReceiverByWabotProxy = __decorate([
|
|
61
|
+
injectable(),
|
|
62
|
+
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection])
|
|
63
|
+
], WhatsAppReceiverByWabotProxy);
|
|
64
|
+
|
|
65
|
+
export { WhatsAppReceiverByWabotProxy };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { WhatsAppSender } from '../WhatsAppSender.js';
|
|
3
|
+
import { singleton } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import '../../../../feature/chat-bot/ChatBot.js';
|
|
6
|
+
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
7
|
+
import 'uuid';
|
|
8
|
+
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
|
+
import '../../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
10
|
+
import { ChatResolver } from '../../../../feature/chat-controller/ChatResolver.js';
|
|
11
|
+
import 'reflect-metadata';
|
|
12
|
+
import '../../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
13
|
+
import '../../../../feature/mindset/MindsetOperator.js';
|
|
14
|
+
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
15
|
+
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
16
|
+
|
|
17
|
+
let WhatsAppSenderByWabotProxy = class WhatsAppSenderByWabotProxy extends WhatsAppSender {
|
|
18
|
+
wabotDevConnection;
|
|
19
|
+
logger = new Logger('wabot:whatsapp-sender-by-wabot-proxy');
|
|
20
|
+
constructor(wabotDevConnection, chatRepository, chatResolver, whatsAppRepository) {
|
|
21
|
+
super(chatRepository, chatResolver, whatsAppRepository);
|
|
22
|
+
this.wabotDevConnection = wabotDevConnection;
|
|
23
|
+
}
|
|
24
|
+
async sendWhatsApp(request, options) {
|
|
25
|
+
try {
|
|
26
|
+
const socket = await this.wabotDevConnection.getSocket();
|
|
27
|
+
const req = {
|
|
28
|
+
event: 'sendMessage',
|
|
29
|
+
data: {
|
|
30
|
+
from: request.from,
|
|
31
|
+
to: request.to,
|
|
32
|
+
content: {
|
|
33
|
+
text: request.message.text ?? 'No Text',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const ack = await socket.timeout(5000).emitWithAck(req.event, req.data);
|
|
38
|
+
if (!ack || !ack.success) {
|
|
39
|
+
throw new Error(`not success ack, when send whatsapp from '${request.from}' to '${request.to}'`);
|
|
40
|
+
}
|
|
41
|
+
this.logger.trace(`success send whatsapp from '${request.from}' to '${request.to}'`);
|
|
42
|
+
if (options?.writeChatMemory) {
|
|
43
|
+
await this.writePrivateChatMemory(request.message, request.to);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
this.logger.error(err);
|
|
48
|
+
throw new Error(undefined, { cause: err });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
WhatsAppSenderByWabotProxy = __decorate([
|
|
53
|
+
singleton(),
|
|
54
|
+
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection,
|
|
55
|
+
ChatRepository,
|
|
56
|
+
ChatResolver,
|
|
57
|
+
WhatsAppRepository])
|
|
58
|
+
], WhatsAppSenderByWabotProxy);
|
|
59
|
+
|
|
60
|
+
export { WhatsAppSenderByWabotProxy };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { Env } from '../../../../core/env/Env.js';
|
|
3
|
+
import { injectable } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import { io } from 'socket.io-client';
|
|
6
|
+
|
|
7
|
+
let WhatsAppWabotProxyConnection = class WhatsAppWabotProxyConnection {
|
|
8
|
+
baseUrl;
|
|
9
|
+
socket = null;
|
|
10
|
+
apiKey;
|
|
11
|
+
logger = new Logger('wabot:whats-app-wabot-proxy-connection');
|
|
12
|
+
constructor(env) {
|
|
13
|
+
this.apiKey = env.requireString('WABOT_API_KEY');
|
|
14
|
+
this.baseUrl = env.requireString('WABOT_PROXY_URL');
|
|
15
|
+
while (this.baseUrl.endsWith('/')) {
|
|
16
|
+
this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length - 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async getSocket() {
|
|
20
|
+
if (this.socket) {
|
|
21
|
+
return this.socket;
|
|
22
|
+
}
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const socket = io(`${this.baseUrl}/whats-app`, {
|
|
25
|
+
autoConnect: false,
|
|
26
|
+
auth: { token: this.apiKey },
|
|
27
|
+
reconnection: true,
|
|
28
|
+
});
|
|
29
|
+
socket.on('connect', async () => {
|
|
30
|
+
this.socket = socket;
|
|
31
|
+
resolve(socket);
|
|
32
|
+
});
|
|
33
|
+
socket.on('connect_error', (err) => {
|
|
34
|
+
reject(new Error(err && err.message ? err.message : 'connection error', { cause: err }));
|
|
35
|
+
});
|
|
36
|
+
socket.connect();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
WhatsAppWabotProxyConnection = __decorate([
|
|
41
|
+
injectable(),
|
|
42
|
+
__metadata("design:paramtypes", [Env])
|
|
43
|
+
], WhatsAppWabotProxyConnection);
|
|
44
|
+
|
|
45
|
+
export { WhatsAppWabotProxyConnection };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { mindsetFunction } from '../../../feature/mindset/metadata/functions/@mindsetFunction.js';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
import '../../../core/injection/index.js';
|
|
5
|
+
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
6
|
+
import { mindsetModule } from '../../../feature/mindset/metadata/modules/@mindsetModule.js';
|
|
7
|
+
import { param } from '../../../feature/mindset/metadata/params/@param.js';
|
|
8
|
+
import '../../../feature/mindset/MindsetOperator.js';
|
|
9
|
+
import { convert } from 'html-to-text';
|
|
10
|
+
|
|
11
|
+
function toPascalCaseFunctionName(title) {
|
|
12
|
+
const cleaned = title.replace(/[^a-zA-Z0-9]+/g, ' ');
|
|
13
|
+
const words = cleaned
|
|
14
|
+
.trim()
|
|
15
|
+
.split(/\s+/)
|
|
16
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
|
|
17
|
+
return words.join('');
|
|
18
|
+
}
|
|
19
|
+
async function fetchRawHtml(url) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
const html = await response.text();
|
|
26
|
+
return html;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`Failed to fetch HTML from ${url}: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class KeywordsReq {
|
|
33
|
+
keywords = '';
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
param({
|
|
37
|
+
description: 'Keywords separated by space',
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], KeywordsReq.prototype, "keywords", void 0);
|
|
41
|
+
function HtmlModule(options) {
|
|
42
|
+
var _a;
|
|
43
|
+
const standaricedTitle = toPascalCaseFunctionName(options.title);
|
|
44
|
+
let documentText = null;
|
|
45
|
+
let HtmlModuleIntern = class HtmlModuleIntern {
|
|
46
|
+
async [_a = `searchInTheDocument${standaricedTitle}`](req) {
|
|
47
|
+
if (!documentText) {
|
|
48
|
+
const rawHtml = await fetchRawHtml(options.url);
|
|
49
|
+
documentText = convert(rawHtml);
|
|
50
|
+
}
|
|
51
|
+
return documentText;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
__decorate([
|
|
55
|
+
mindsetFunction({
|
|
56
|
+
description: `Search information using keywords in the document "${options.title}". Priorize this info.`,
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", Function),
|
|
59
|
+
__metadata("design:paramtypes", [KeywordsReq]),
|
|
60
|
+
__metadata("design:returntype", Promise)
|
|
61
|
+
], HtmlModuleIntern.prototype, _a, null);
|
|
62
|
+
HtmlModuleIntern = __decorate([
|
|
63
|
+
mindsetModule({
|
|
64
|
+
description: `Search information using keywords in the document ${options.title}`,
|
|
65
|
+
})
|
|
66
|
+
], HtmlModuleIntern);
|
|
67
|
+
return HtmlModuleIntern;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { HtmlModule };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { CustomError } from '../error/CustomError.js';
|
|
3
|
+
import { scoped, Lifecycle } from '../injection/index.js';
|
|
4
|
+
|
|
5
|
+
let Auth = class Auth {
|
|
6
|
+
authInfo = null;
|
|
7
|
+
require() {
|
|
8
|
+
if (!this.authInfo) {
|
|
9
|
+
throw new CustomError({ message: 'Unauthorized', httpCode: 401 });
|
|
10
|
+
}
|
|
11
|
+
return this.authInfo;
|
|
12
|
+
}
|
|
13
|
+
assign(authInfo) {
|
|
14
|
+
if (this.authInfo) {
|
|
15
|
+
throw new CustomError({ message: 'Authorization info already assigned', httpCode: 401 });
|
|
16
|
+
}
|
|
17
|
+
this.authInfo = authInfo;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
Auth = __decorate([
|
|
21
|
+
scoped(Lifecycle.ContainerScoped)
|
|
22
|
+
], Auth);
|
|
23
|
+
|
|
24
|
+
export { Auth };
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
getId() {
|
|
1
|
+
import { Storable } from '../storable/Storable.js';
|
|
2
|
+
|
|
3
|
+
class Entity extends Storable {
|
|
4
|
+
get id() {
|
|
7
5
|
if (!this.data.id) {
|
|
8
6
|
throw new Error('id is required');
|
|
9
7
|
}
|
|
10
8
|
return this.data.id;
|
|
11
9
|
}
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use id
|
|
12
|
+
*/
|
|
13
|
+
getId() {
|
|
14
|
+
return this.id;
|
|
15
|
+
}
|
|
16
|
+
get createdAt() {
|
|
13
17
|
if (!this.data.createdAt) {
|
|
14
18
|
throw new Error('createdAt is required');
|
|
15
19
|
}
|
|
16
20
|
return new Date(this.data.createdAt);
|
|
17
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use createdAt
|
|
24
|
+
*/
|
|
25
|
+
getCreatedAt() {
|
|
26
|
+
return this.createdAt;
|
|
27
|
+
}
|
|
18
28
|
update(newData) {
|
|
19
|
-
this.data = newData;
|
|
29
|
+
this.data = { ...this.data, ...newData, updatedAt: new Date().getTime() };
|
|
20
30
|
}
|
|
21
31
|
wasCreated() {
|
|
22
32
|
return !!this.data.createdAt || !!this.data.id;
|
|
@@ -29,9 +39,11 @@ class Persistent {
|
|
|
29
39
|
throw new Error('createdAt is required');
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Should use Entity
|
|
45
|
+
*/
|
|
46
|
+
class Persistent extends Entity {
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
export { Persistent };
|
|
49
|
+
export { Entity, Persistent };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { singleton } from '../injection/index.js';
|
|
3
|
+
|
|
4
|
+
let Env = class Env {
|
|
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
|
+
isTesting() {
|
|
16
|
+
return this.envType === 'testing';
|
|
17
|
+
}
|
|
18
|
+
requireString(varName, options) {
|
|
19
|
+
const value = process.env[varName] ?? options?.default;
|
|
20
|
+
if (!value)
|
|
21
|
+
throw new Error(`Env Variable ${varName} is required`);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
requireNumber(varName, options) {
|
|
25
|
+
const strValue = this.requireString(varName, {
|
|
26
|
+
default: options?.default != null ? String(options.default) : undefined,
|
|
27
|
+
});
|
|
28
|
+
const value = Number(strValue);
|
|
29
|
+
if (isNaN(value))
|
|
30
|
+
throw new Error(`Env Variable ${varName} should have number format`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
Env = __decorate([
|
|
35
|
+
singleton(),
|
|
36
|
+
__metadata("design:paramtypes", [])
|
|
37
|
+
], Env);
|
|
38
|
+
|
|
39
|
+
export { Env };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CustomError extends Error {
|
|
2
|
+
humanMessage;
|
|
3
|
+
code;
|
|
4
|
+
httpCode;
|
|
5
|
+
info;
|
|
6
|
+
constructor(data) {
|
|
7
|
+
super(data.message, { cause: data.cause });
|
|
8
|
+
this.humanMessage = data.humanMessage;
|
|
9
|
+
this.code = data.code;
|
|
10
|
+
this.httpCode = data.httpCode;
|
|
11
|
+
this.info = data.info;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { CustomError };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Storable } from '../storable/Storable.js';
|
|
2
|
+
import { CustomError } from '../error/CustomError.js';
|
|
3
|
+
import '../injection/index.js';
|
|
4
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
5
|
+
import { validate } from '../validation/validate.js';
|
|
6
|
+
|
|
7
|
+
function deepCopyWithStorable(obj) {
|
|
8
|
+
if (obj === null || typeof obj !== 'object') {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
if (obj instanceof Date) {
|
|
12
|
+
return obj.getTime();
|
|
13
|
+
}
|
|
14
|
+
if (obj instanceof Storable) {
|
|
15
|
+
return deepCopyWithStorable(obj['data']);
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(obj)) {
|
|
18
|
+
return obj.map((item) => deepCopyWithStorable(item));
|
|
19
|
+
}
|
|
20
|
+
const copy = {};
|
|
21
|
+
for (const key in obj) {
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
23
|
+
copy[key] = deepCopyWithStorable(obj[key]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return copy;
|
|
27
|
+
}
|
|
28
|
+
class Mapper {
|
|
29
|
+
map(data, ctor) {
|
|
30
|
+
const validationResult = validate(deepCopyWithStorable(data), ctor);
|
|
31
|
+
if (validationResult.error) {
|
|
32
|
+
throw new CustomError({
|
|
33
|
+
httpCode: 500,
|
|
34
|
+
message: `Cant map value to ${ctor.name}`,
|
|
35
|
+
info: validationResult.error,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return validationResult.value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { Mapper };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { randomBytes, scryptSync, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { Random } from '../random/Random.js';
|
|
3
|
+
|
|
4
|
+
class Password {
|
|
5
|
+
static hash(options) {
|
|
6
|
+
const { password: secret, saltLength = 16, keyLength = 64 } = options;
|
|
7
|
+
const salt = randomBytes(saltLength).toString('hex');
|
|
8
|
+
const derivedKey = scryptSync(secret, salt, keyLength);
|
|
9
|
+
return `${salt}:${derivedKey.toString('hex')}`;
|
|
10
|
+
}
|
|
11
|
+
static isValid(req) {
|
|
12
|
+
const [salt, storedKeyHex] = req.hash.split(':');
|
|
13
|
+
if (!salt || !storedKeyHex)
|
|
14
|
+
return false;
|
|
15
|
+
try {
|
|
16
|
+
const keyLength = Buffer.from(storedKeyHex, 'hex').length;
|
|
17
|
+
const derivedKey = scryptSync(req.password, salt, keyLength);
|
|
18
|
+
const storedKey = Buffer.from(storedKeyHex, 'hex');
|
|
19
|
+
return timingSafeEqual(derivedKey, storedKey);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static generate(length) {
|
|
26
|
+
return Random.alphaNumeric(length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Password };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const DIGITS = '0123456789';
|
|
4
|
+
const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
|
+
const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
6
|
+
class Random {
|
|
7
|
+
static integer(options) {
|
|
8
|
+
const { min, max } = options;
|
|
9
|
+
if (min > max) {
|
|
10
|
+
throw new RangeError('min must be less than or equal to max');
|
|
11
|
+
}
|
|
12
|
+
const range = max - min + 1;
|
|
13
|
+
if (range <= 0) {
|
|
14
|
+
throw new RangeError('Range must be a positive number');
|
|
15
|
+
}
|
|
16
|
+
const byteSize = 6; // gives us up to 2^48
|
|
17
|
+
const maxGeneratedValue = Math.pow(2, byteSize * 8) - 1;
|
|
18
|
+
const maxAcceptable = maxGeneratedValue - (maxGeneratedValue % range);
|
|
19
|
+
let randomNumber;
|
|
20
|
+
do {
|
|
21
|
+
randomNumber = parseInt(randomBytes(byteSize).toString('hex'), 16);
|
|
22
|
+
} while (randomNumber >= maxAcceptable);
|
|
23
|
+
return min + (randomNumber % range);
|
|
24
|
+
}
|
|
25
|
+
static slug(name, options) {
|
|
26
|
+
const base = name
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.trim()
|
|
29
|
+
.replace(/[\s\_]+/g, '-') // spaces/underscores to hyphens
|
|
30
|
+
.replace(/[^a-z0-9\-]/g, '') // remove non-alphanumeric except hyphens
|
|
31
|
+
.replace(/\-+/g, '-') // collapse multiple hyphens
|
|
32
|
+
.replace(/^\-+|\-+$/g, ''); // trim hyphens from ends
|
|
33
|
+
const random = this.alphaNumericLowerCase(options.randomLength);
|
|
34
|
+
return `${base}-${random}`;
|
|
35
|
+
}
|
|
36
|
+
static alphaNumeric(length) {
|
|
37
|
+
const bytes = randomBytes(length);
|
|
38
|
+
let result = '';
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
const index = bytes[i] % ALPHA_NUMERIC_CHARSET.length;
|
|
41
|
+
result += ALPHA_NUMERIC_CHARSET[index];
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
static alphaNumericLowerCase(length) {
|
|
46
|
+
const bytes = randomBytes(length);
|
|
47
|
+
let result = '';
|
|
48
|
+
for (let i = 0; i < length; i++) {
|
|
49
|
+
const index = bytes[i] % ALPHA_NUMERIC_LOWER_CASE_CHARSET.length;
|
|
50
|
+
result += ALPHA_NUMERIC_LOWER_CASE_CHARSET[index];
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
static numberCode(length) {
|
|
55
|
+
const bytes = randomBytes(length);
|
|
56
|
+
let result = '';
|
|
57
|
+
for (let i = 0; i < length; i++) {
|
|
58
|
+
const index = bytes[i] % 10; // 0–9
|
|
59
|
+
result += DIGITS[index];
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Random };
|