@wabot-dev/framework 0.1.0-beta.3 → 0.1.0-beta.31
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/chat-bot/claude/ClaudeChatAdapter.js +117 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +125 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +101 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -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 +8 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
- package/dist/src/addon/chat-controller/whatsapp/EnvWhatsAppRepository.js +49 -0
- package/dist/src/{channels/whatsapp/WhatsAppRepository.js → addon/chat-controller/whatsapp/PgWhatsAppRepository.js} +5 -5
- package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +5 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +4 -7
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +3 -9
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +2 -9
- package/dist/src/{core/chat/repository/IChatMemory.js → addon/chat-controller/whatsapp/WhatsAppRepository.js} +4 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +39 -10
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByCloudApi.js +10 -13
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js +13 -15
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +23 -2
- package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/rest-controller/jwt/Jwt.js +36 -0
- package/dist/src/addon/rest-controller/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/rest-controller/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +50 -0
- package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
- package/dist/src/addon/rest-controller/jwt/JwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/rest-controller/jwt/JwtSigner.js +48 -0
- package/dist/src/addon/rest-controller/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/validation/is-boolean/@isBoolean.js +17 -0
- package/dist/src/addon/validation/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/addon/validation/is-date/@isDate.js +17 -0
- package/dist/src/addon/validation/is-date/validateIsDate.js +16 -0
- package/dist/src/addon/validation/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/addon/validation/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/addon/validation/is-number/@isNumber.js +17 -0
- package/dist/src/addon/validation/is-number/validateIsNumber.js +12 -0
- package/dist/src/addon/validation/is-present/@isPresent.js +17 -0
- package/dist/src/addon/validation/is-present/validateIsPresent.js +12 -0
- package/dist/src/addon/validation/is-string/@isString.js +17 -0
- package/dist/src/addon/validation/is-string/validateIsString.js +12 -0
- package/dist/src/addon/validation/max/@max.js +18 -0
- package/dist/src/addon/validation/max/validateMax.js +17 -0
- package/dist/src/addon/validation/min/@min.js +18 -0
- package/dist/src/addon/validation/min/validateMin.js +17 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
- 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/random/Random.js +37 -0
- package/dist/src/core/storable/Storable.js +8 -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/validateArray.js +41 -0
- package/dist/src/core/validation/validators/validateIsOptional.js +5 -0
- package/dist/src/core/validation/validators/validateModel.js +34 -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 +24 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +45 -0
- package/dist/src/feature/async/JobsEventsHub.js +24 -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 +50 -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 +5 -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 +1 -1
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +1 -1
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +66 -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/rest-controller/auth/Auth.js +24 -0
- package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
- package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
- package/dist/src/feature/rest-controller/metadata/@post.js +19 -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/runRestControllers.js +75 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +1 -1
- package/dist/src/index.d.ts +805 -475
- package/dist/src/index.js +118 -74
- package/package.json +6 -3
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
- package/dist/src/channels/cmd/@cmd.js +0 -18
- 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/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -21
- 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/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.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}/IMindset.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,8 +1,12 @@
|
|
|
1
|
-
import { container } from '
|
|
1
|
+
import { container } from '../../../core/injection/index.js';
|
|
2
2
|
import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import
|
|
3
|
+
import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
4
|
+
import '../../../feature/chat-controller/ChatResolver.js';
|
|
5
|
+
import 'uuid';
|
|
6
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
7
|
+
import 'reflect-metadata';
|
|
8
|
+
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
9
|
+
import '../../../feature/mindset/MindsetOperator.js';
|
|
6
10
|
import { WhatsAppChannel } from './WhatsAppChannel.js';
|
|
7
11
|
|
|
8
12
|
function whatsapp(config) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
3
|
+
import { WhatsApp } from './WhatsApp.js';
|
|
4
|
+
import { Env } from '../../../core/env/Env.js';
|
|
5
|
+
|
|
6
|
+
let EnvWhatsAppRepository = class EnvWhatsAppRepository {
|
|
7
|
+
env;
|
|
8
|
+
constructor(env) {
|
|
9
|
+
this.env = env;
|
|
10
|
+
}
|
|
11
|
+
async findBySlug(slug) {
|
|
12
|
+
const whatsApp = this.getFromEnvVars();
|
|
13
|
+
if (whatsApp.getSlug() !== slug) {
|
|
14
|
+
throw new Error(`Not found WhatsApp configuration in env variables for the required slug '${slug}'`);
|
|
15
|
+
}
|
|
16
|
+
return whatsApp;
|
|
17
|
+
}
|
|
18
|
+
async findByBusinessNumber(number) {
|
|
19
|
+
const whatsApp = this.getFromEnvVars();
|
|
20
|
+
if (!whatsApp.getBussinessNumber(number)) {
|
|
21
|
+
throw new Error(`Not found WhatsApp configuration in env variables for the required number '${number}'`);
|
|
22
|
+
}
|
|
23
|
+
return whatsApp;
|
|
24
|
+
}
|
|
25
|
+
getFromEnvVars() {
|
|
26
|
+
const whatsApp = new WhatsApp({
|
|
27
|
+
verifyToken: this.env.requireString('WHATSAPP_HOOK_TOKEN'),
|
|
28
|
+
slug: this.env.requireString('WHATSAPP_HOOK_SLUG'),
|
|
29
|
+
appSecret: this.env.requireString('WHATSAPP_APP_SECRET'),
|
|
30
|
+
businessAccount: {
|
|
31
|
+
id: this.env.requireString('WHATSAPP_ACCOUNT_ID'),
|
|
32
|
+
},
|
|
33
|
+
accessToken: this.env.requireString('WHATSAPP_ACCESS_TOKEN'),
|
|
34
|
+
businessNumbers: [
|
|
35
|
+
{
|
|
36
|
+
id: this.env.requireString('WHATSAPP_BUSINESS_NUMBER_ID'),
|
|
37
|
+
number: this.env.requireString('WHATSAPP_BUSINESS_NUMBER'),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
return whatsApp;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
EnvWhatsAppRepository = __decorate([
|
|
45
|
+
singleton(),
|
|
46
|
+
__metadata("design:paramtypes", [Env])
|
|
47
|
+
], EnvWhatsAppRepository);
|
|
48
|
+
|
|
49
|
+
export { EnvWhatsAppRepository };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { Pool } from 'pg';
|
|
3
3
|
import { WhatsApp } from './WhatsApp.js';
|
|
4
|
-
import { singleton } from '
|
|
4
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
5
5
|
import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
|
|
6
6
|
|
|
7
|
-
let
|
|
7
|
+
let PgWhatsAppRepository = class PgWhatsAppRepository extends PgCrudRepository {
|
|
8
8
|
constructor(pool) {
|
|
9
9
|
super(pool, {
|
|
10
10
|
table: 'whatsapp',
|
|
@@ -33,9 +33,9 @@ let WhatsAppRepository = class WhatsAppRepository extends PgCrudRepository {
|
|
|
33
33
|
return items.at(0) ?? null;
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
PgWhatsAppRepository = __decorate([
|
|
37
37
|
singleton(),
|
|
38
38
|
__metadata("design:paramtypes", [Pool])
|
|
39
|
-
],
|
|
39
|
+
], PgWhatsAppRepository);
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { PgWhatsAppRepository };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { singleton } from '
|
|
3
|
-
import { Logger } from '
|
|
2
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
3
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
4
4
|
import { io } from 'socket.io-client';
|
|
5
5
|
import { devEmitEvent } from './WabotDevSocketContracts.js';
|
|
6
6
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { Persistent } from '../../core/Persistent.js';
|
|
3
|
-
import '../../core/user/IUserRepository.js';
|
|
1
|
+
import { Entity } from '../../../core/entity/Entity.js';
|
|
4
2
|
|
|
5
|
-
class WhatsApp extends
|
|
3
|
+
class WhatsApp extends Entity {
|
|
6
4
|
getVerifyToken() {
|
|
7
5
|
return this.data.verifyToken;
|
|
8
6
|
}
|
|
7
|
+
getSlug() {
|
|
8
|
+
return this.data.slug;
|
|
9
|
+
}
|
|
9
10
|
getBusinessAccount() {
|
|
10
11
|
return this.data.businessAccount;
|
|
11
12
|
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { injectable } from '../../injection/index.js';
|
|
5
|
-
import '../../controller/metadata/ControllerMetadataStore.js';
|
|
6
|
-
import { Logger } from '../../logger/Logger.js';
|
|
2
|
+
import { injectable } from '../../../core/injection/index.js';
|
|
3
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
7
4
|
import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
|
|
8
5
|
import { WhatsAppReceiver } from './WhatsAppReceiver.js';
|
|
9
6
|
import { WhatsAppSender } from './WhatsAppSender.js';
|
|
10
7
|
|
|
11
8
|
let WhatsAppChannel = class WhatsAppChannel {
|
|
12
9
|
config;
|
|
13
|
-
chatResolver;
|
|
14
|
-
userResolver;
|
|
15
10
|
sender;
|
|
16
11
|
receiver;
|
|
17
12
|
logger = new Logger('wabot:whatsapp-channel');
|
|
18
|
-
constructor(config,
|
|
13
|
+
constructor(config, sender, receiver) {
|
|
19
14
|
this.config = config;
|
|
20
|
-
this.chatResolver = chatResolver;
|
|
21
|
-
this.userResolver = userResolver;
|
|
22
15
|
this.sender = sender;
|
|
23
16
|
this.receiver = receiver;
|
|
24
17
|
}
|
|
@@ -27,16 +20,13 @@ let WhatsAppChannel = class WhatsAppChannel {
|
|
|
27
20
|
to: this.config.number,
|
|
28
21
|
listener: async (message) => {
|
|
29
22
|
try {
|
|
30
|
-
const chat = await this.chatResolver.resolve(message.chatConnection);
|
|
31
|
-
const user = await this.userResolver.resolve(message.userConnection);
|
|
32
23
|
callback({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
message,
|
|
24
|
+
chatConnection: message.chatConnection,
|
|
25
|
+
message: message.message,
|
|
36
26
|
reply: (replyMessage) => {
|
|
37
27
|
this.sender.sendWhatsApp({
|
|
38
28
|
from: this.config.number,
|
|
39
|
-
to: message.
|
|
29
|
+
to: message.chatConnection.id,
|
|
40
30
|
message: replyMessage,
|
|
41
31
|
});
|
|
42
32
|
},
|
|
@@ -55,8 +45,6 @@ let WhatsAppChannel = class WhatsAppChannel {
|
|
|
55
45
|
WhatsAppChannel = __decorate([
|
|
56
46
|
injectable(),
|
|
57
47
|
__metadata("design:paramtypes", [WhatsappChannelConfig,
|
|
58
|
-
ChatResolver,
|
|
59
|
-
UserResolver,
|
|
60
48
|
WhatsAppSender,
|
|
61
49
|
WhatsAppReceiver])
|
|
62
50
|
], WhatsAppChannel);
|
|
@@ -43,15 +43,12 @@ class WhatsAppReceiver {
|
|
|
43
43
|
chatType: 'PRIVATE',
|
|
44
44
|
channelName,
|
|
45
45
|
};
|
|
46
|
-
const userConnection = {
|
|
47
|
-
id: contact.wa_id,
|
|
48
|
-
channelName,
|
|
49
|
-
};
|
|
50
46
|
await listener({
|
|
51
47
|
chatConnection,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
message: {
|
|
49
|
+
senderName: contact.profile.name,
|
|
50
|
+
text: message.text.body,
|
|
51
|
+
},
|
|
55
52
|
});
|
|
56
53
|
}
|
|
57
54
|
}
|
package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js
RENAMED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Logger } from '
|
|
2
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
3
3
|
import { WhatsAppReceiver } from './WhatsAppReceiver.js';
|
|
4
|
-
import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
|
|
5
|
-
import { devListentEvent } from '../wabot/WabotDevSocketContracts.js';
|
|
6
4
|
import { singleton } from 'tsyringe';
|
|
7
|
-
import {
|
|
5
|
+
import { WabotDevConnection } from './WabotDevConnection.js';
|
|
6
|
+
import { devListentEvent } from './WabotDevSocketContracts.js';
|
|
8
7
|
|
|
9
8
|
let WhatsAppReceiverByDevConnection = class WhatsAppReceiverByDevConnection extends WhatsAppReceiver {
|
|
10
9
|
wabotDevConnection;
|
|
@@ -23,10 +22,5 @@ WhatsAppReceiverByDevConnection = __decorate([
|
|
|
23
22
|
singleton(),
|
|
24
23
|
__metadata("design:paramtypes", [WabotDevConnection])
|
|
25
24
|
], WhatsAppReceiverByDevConnection);
|
|
26
|
-
if (WabotDevConnection.isTokenAvailable()) {
|
|
27
|
-
container.register(WhatsAppReceiver, {
|
|
28
|
-
useClass: WhatsAppReceiverByDevConnection,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
25
|
|
|
32
26
|
export { WhatsAppReceiverByDevConnection };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Logger } from '
|
|
2
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
3
3
|
import { WhatsAppReceiver } from './WhatsAppReceiver.js';
|
|
4
4
|
import { singleton } from 'tsyringe';
|
|
5
|
-
import { ExpressProvider } from '
|
|
5
|
+
import { ExpressProvider } from '../../../feature/express/ExpressProvider.js';
|
|
6
6
|
import { WhatsAppRepository } from './WhatsAppRepository.js';
|
|
7
|
-
import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
|
|
8
|
-
import { container } from '../../injection/index.js';
|
|
9
7
|
|
|
10
8
|
let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
|
|
11
9
|
expressProvider;
|
|
@@ -54,10 +52,5 @@ WhatsAppReceiverByWebHook = __decorate([
|
|
|
54
52
|
__metadata("design:paramtypes", [ExpressProvider,
|
|
55
53
|
WhatsAppRepository])
|
|
56
54
|
], WhatsAppReceiverByWebHook);
|
|
57
|
-
if (!WabotDevConnection.isTokenAvailable()) {
|
|
58
|
-
container.register(WhatsAppReceiver, {
|
|
59
|
-
useClass: WhatsAppReceiverByWebHook,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
55
|
|
|
63
56
|
export { WhatsAppReceiverByWebHook };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
class
|
|
2
|
-
|
|
1
|
+
class WhatsAppRepository {
|
|
2
|
+
findBySlug(slug) {
|
|
3
3
|
throw new Error('Method not implemented.');
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
findByBusinessNumber(number) {
|
|
6
6
|
throw new Error('Method not implemented.');
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { WhatsAppRepository };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import
|
|
3
|
-
import '
|
|
1
|
+
import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
|
|
2
|
+
import '../../../core/injection/index.js';
|
|
3
|
+
import 'uuid';
|
|
4
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
4
5
|
|
|
5
6
|
class WhatsAppSender {
|
|
6
7
|
logger;
|
|
@@ -13,6 +14,15 @@ class WhatsAppSender {
|
|
|
13
14
|
this.chatResolver = chatResolver;
|
|
14
15
|
this.whatsAppRepository = whatsAppRepository;
|
|
15
16
|
}
|
|
17
|
+
handleSendRequest(request) {
|
|
18
|
+
throw new Error('Not implemented');
|
|
19
|
+
}
|
|
20
|
+
handleSendTemplateRequest(request) {
|
|
21
|
+
throw new Error('Not implemented');
|
|
22
|
+
}
|
|
23
|
+
handleGetWhatsAppTemplate(request) {
|
|
24
|
+
throw new Error('Not implemented');
|
|
25
|
+
}
|
|
16
26
|
async sendWhatsApp(request, options) {
|
|
17
27
|
try {
|
|
18
28
|
await this.handleSendRequest(request);
|
|
@@ -22,6 +32,7 @@ class WhatsAppSender {
|
|
|
22
32
|
}
|
|
23
33
|
catch (error) {
|
|
24
34
|
this.logger.error(`Error sending WhatsApp message: ${error}`);
|
|
35
|
+
throw new Error(`Error sending WhatsApp message: ${error}`, { cause: error });
|
|
25
36
|
}
|
|
26
37
|
}
|
|
27
38
|
async sendWhatsAppTemplate(request, options) {
|
|
@@ -34,6 +45,7 @@ class WhatsAppSender {
|
|
|
34
45
|
}
|
|
35
46
|
catch (error) {
|
|
36
47
|
this.logger.error(`Error sending WhatsApp message: ${error}`);
|
|
48
|
+
throw new Error(`Error sending WhatsApp message: ${error}`, { cause: error });
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
51
|
async getWhatsAppTemplate(request) {
|
|
@@ -55,11 +67,12 @@ class WhatsAppSender {
|
|
|
55
67
|
if (!template) {
|
|
56
68
|
throw new Error(`WhatsAppTemplate with name ${request.templateMessage.templateName} and language ${request.templateMessage.languageCode} not found`);
|
|
57
69
|
}
|
|
70
|
+
const components = template.components
|
|
71
|
+
.filter((x) => x.text != null)
|
|
72
|
+
.map((x) => x.text)
|
|
73
|
+
.join('\n');
|
|
58
74
|
return {
|
|
59
|
-
text:
|
|
60
|
-
.filter((x) => x.text != null)
|
|
61
|
-
.map((x) => x.text)
|
|
62
|
-
.join('\n'),
|
|
75
|
+
text: this.replaceTemplateParameters(components, request.templateMessage.parameters),
|
|
63
76
|
senderName: request.senderName,
|
|
64
77
|
};
|
|
65
78
|
}
|
|
@@ -70,13 +83,29 @@ class WhatsAppSender {
|
|
|
70
83
|
channelName: 'WhatsAppChannel',
|
|
71
84
|
};
|
|
72
85
|
const chat = await this.chatResolver.resolve(chatConnection);
|
|
73
|
-
const chatMemory = await this.chatRepository.findMemory(chat.
|
|
86
|
+
const chatMemory = await this.chatRepository.findMemory(chat.id);
|
|
74
87
|
const chatItem = new ChatItem({
|
|
75
|
-
type: '
|
|
76
|
-
|
|
88
|
+
type: 'botMessage',
|
|
89
|
+
botMessage: message
|
|
77
90
|
});
|
|
78
91
|
await chatMemory.create(chatItem);
|
|
79
92
|
}
|
|
93
|
+
replaceTemplateParameters(template, data) {
|
|
94
|
+
let result = template;
|
|
95
|
+
data.forEach((param) => {
|
|
96
|
+
if (param.type === 'text' && param.parameter_name) {
|
|
97
|
+
const tag = `{{${param.parameter_name}}}`;
|
|
98
|
+
result = result.split(tag).join(param.text);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
data.forEach((param, index) => {
|
|
102
|
+
if (param.type === 'text') {
|
|
103
|
+
const tag = `{{${index + 1}}}`;
|
|
104
|
+
result = result.split(tag).join(param.text);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
80
109
|
}
|
|
81
110
|
|
|
82
111
|
export { WhatsAppSender };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Logger } from '
|
|
2
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
3
3
|
import { WhatsAppSender } from './WhatsAppSender.js';
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
6
|
-
import { ChatResolver } from '
|
|
7
|
-
import '
|
|
8
|
-
import
|
|
9
|
-
import '
|
|
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 { ChatRepository } from '../../../feature/chat-bot/ChatRepository.js';
|
|
8
|
+
import 'uuid';
|
|
9
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
10
|
+
import 'reflect-metadata';
|
|
11
|
+
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
12
|
+
import '../../../feature/mindset/MindsetOperator.js';
|
|
10
13
|
import { WhatsAppRepository } from './WhatsAppRepository.js';
|
|
11
|
-
import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
|
|
12
14
|
|
|
13
15
|
let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSender {
|
|
14
16
|
constructor(chatRepository, chatResolver, whatsAppRepository) {
|
|
@@ -115,10 +117,5 @@ WhatsAppSenderByCloudApi = __decorate([
|
|
|
115
117
|
ChatResolver,
|
|
116
118
|
WhatsAppRepository])
|
|
117
119
|
], WhatsAppSenderByCloudApi);
|
|
118
|
-
if (!WabotDevConnection.isTokenAvailable()) {
|
|
119
|
-
container.register(WhatsAppSender, {
|
|
120
|
-
useClass: WhatsAppSenderByCloudApi,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
120
|
|
|
124
121
|
export { WhatsAppSenderByCloudApi };
|
package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js
RENAMED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { WhatsAppSender } from './WhatsAppSender.js';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { ChatRepository } from '
|
|
7
|
-
import '
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import '
|
|
11
|
-
import '
|
|
3
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
4
|
+
import '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
5
|
+
import { ChatResolver } from '../../../feature/chat-controller/ChatResolver.js';
|
|
6
|
+
import { ChatRepository } from '../../../feature/chat-bot/ChatRepository.js';
|
|
7
|
+
import 'uuid';
|
|
8
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
|
+
import 'reflect-metadata';
|
|
10
|
+
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
11
|
+
import '../../../feature/mindset/MindsetOperator.js';
|
|
12
|
+
import { Logger } from '../../../core/logger/Logger.js';
|
|
12
13
|
import { WhatsAppRepository } from './WhatsAppRepository.js';
|
|
14
|
+
import { WabotDevConnection } from './WabotDevConnection.js';
|
|
15
|
+
import { devEmitEvent } from './WabotDevSocketContracts.js';
|
|
13
16
|
|
|
14
17
|
let WhatsAppSenderByDevConnection = class WhatsAppSenderByDevConnection extends WhatsAppSender {
|
|
15
18
|
wabotDevConnection;
|
|
@@ -42,7 +45,7 @@ let WhatsAppSenderByDevConnection = class WhatsAppSenderByDevConnection extends
|
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
async handleGetWhatsAppTemplate(request) {
|
|
45
|
-
throw new Error(
|
|
48
|
+
throw new Error('Not implemented');
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
WhatsAppSenderByDevConnection = __decorate([
|
|
@@ -52,10 +55,5 @@ WhatsAppSenderByDevConnection = __decorate([
|
|
|
52
55
|
ChatResolver,
|
|
53
56
|
WhatsAppRepository])
|
|
54
57
|
], WhatsAppSenderByDevConnection);
|
|
55
|
-
if (WabotDevConnection.isTokenAvailable()) {
|
|
56
|
-
container.register(WhatsAppSender, {
|
|
57
|
-
useClass: WhatsAppSenderByDevConnection,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
58
|
|
|
61
59
|
export { WhatsAppSenderByDevConnection };
|
|
@@ -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 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as shortUUID from 'short-uuid';
|
|
2
2
|
import { PgRepositoryBase } from './PgRepositoryBase.js';
|
|
3
|
+
import { CustomError } from '../../../core/error/CustomError.js';
|
|
3
4
|
|
|
4
5
|
class PgCrudRepository extends PgRepositoryBase {
|
|
5
6
|
config;
|
|
@@ -17,6 +18,26 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
17
18
|
const items = await this.query(sql, [id]);
|
|
18
19
|
return items.at(0) ?? null;
|
|
19
20
|
}
|
|
21
|
+
async findByIds(ids) {
|
|
22
|
+
const sql = `
|
|
23
|
+
SELECT ${this.columns}
|
|
24
|
+
FROM ${this.table}
|
|
25
|
+
WHERE id IN (${ids.map((_, i) => '$' + (i + 1)).join(',')})
|
|
26
|
+
LIMIT 1
|
|
27
|
+
`;
|
|
28
|
+
const items = await this.query(sql, ids);
|
|
29
|
+
return items;
|
|
30
|
+
}
|
|
31
|
+
async findOrThrow(id) {
|
|
32
|
+
const item = await this.find(id);
|
|
33
|
+
if (!item) {
|
|
34
|
+
throw new CustomError({
|
|
35
|
+
message: `Not found ${this.config.constructor.name} with id = '${id}'}`,
|
|
36
|
+
httpCode: 404,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
20
41
|
async findAll() {
|
|
21
42
|
const sql = `
|
|
22
43
|
SELECT ${this.columns}
|
|
@@ -46,10 +67,10 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
46
67
|
SET ${this.updates}
|
|
47
68
|
WHERE id = $${this.columnsList.length + 1}
|
|
48
69
|
`;
|
|
49
|
-
await this.exec(sql, [...this.values(item), item.
|
|
70
|
+
await this.exec(sql, [...this.values(item), item.id]);
|
|
50
71
|
}
|
|
51
72
|
async discard(item) {
|
|
52
|
-
const _item = await this.find(item.
|
|
73
|
+
const _item = await this.find(item.id);
|
|
53
74
|
if (!_item) {
|
|
54
75
|
throw new Error('Not found');
|
|
55
76
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '../../../core/injection/index.js';
|
|
2
|
+
import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
|
|
3
|
+
import { middleware } from '../../../feature/rest-controller/metadata/@middleware.js';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'debug';
|
|
6
|
+
import '../../../feature/express/ExpressProvider.js';
|
|
7
|
+
import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
8
|
+
import '../../../feature/rest-controller/auth/Auth.js';
|
|
9
|
+
import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
|
|
10
|
+
|
|
11
|
+
function jwtGuard() {
|
|
12
|
+
return function (target, propertyKey) {
|
|
13
|
+
middleware(JwtGuardMiddleware)(target, propertyKey);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { jwtGuard };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { JwtSigner } from './JwtSigner.js';
|
|
3
|
+
import { JwtRefreshTokenRepository } from './JwtRefreshTokenRepository.js';
|
|
4
|
+
import { JwtRefreshToken } from './JwtRefreshToken.js';
|
|
5
|
+
import { injectable } from '../../../core/injection/index.js';
|
|
6
|
+
import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
|
|
7
|
+
import 'path';
|
|
8
|
+
import 'debug';
|
|
9
|
+
import '../../../feature/express/ExpressProvider.js';
|
|
10
|
+
import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
11
|
+
import { Auth } from '../../../feature/rest-controller/auth/Auth.js';
|
|
12
|
+
|
|
13
|
+
let Jwt = class Jwt {
|
|
14
|
+
auth;
|
|
15
|
+
jwtSigner;
|
|
16
|
+
jwtRefreshTokenRepository;
|
|
17
|
+
constructor(auth, jwtSigner, jwtRefreshTokenRepository) {
|
|
18
|
+
this.auth = auth;
|
|
19
|
+
this.jwtSigner = jwtSigner;
|
|
20
|
+
this.jwtRefreshTokenRepository = jwtRefreshTokenRepository;
|
|
21
|
+
}
|
|
22
|
+
async createToken() {
|
|
23
|
+
const authInfo = this.auth.require();
|
|
24
|
+
const refreshToken = new JwtRefreshToken({ authInfo });
|
|
25
|
+
await this.jwtRefreshTokenRepository.create(refreshToken);
|
|
26
|
+
return await this.jwtSigner.signAccessAndRefreshToken(refreshToken);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Jwt = __decorate([
|
|
30
|
+
injectable(),
|
|
31
|
+
__metadata("design:paramtypes", [Auth,
|
|
32
|
+
JwtSigner,
|
|
33
|
+
JwtRefreshTokenRepository])
|
|
34
|
+
], Jwt);
|
|
35
|
+
|
|
36
|
+
export { Jwt };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { isModel } from '../../../core/validation/metadata/@isModel.js';
|
|
3
|
+
import '../../../core/injection/index.js';
|
|
4
|
+
import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
5
|
+
import { JwtTokenDto } from './JwtTokenDto.js';
|
|
6
|
+
|
|
7
|
+
class JwtAccessAndRefreshTokenDto {
|
|
8
|
+
access;
|
|
9
|
+
refresh;
|
|
10
|
+
}
|
|
11
|
+
__decorate([
|
|
12
|
+
isModel(JwtTokenDto),
|
|
13
|
+
__metadata("design:type", JwtTokenDto)
|
|
14
|
+
], JwtAccessAndRefreshTokenDto.prototype, "access", void 0);
|
|
15
|
+
__decorate([
|
|
16
|
+
isModel(JwtTokenDto),
|
|
17
|
+
__metadata("design:type", JwtTokenDto)
|
|
18
|
+
], JwtAccessAndRefreshTokenDto.prototype, "refresh", void 0);
|
|
19
|
+
|
|
20
|
+
export { JwtAccessAndRefreshTokenDto };
|