@wabot-dev/framework 0.1.0-beta.2 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +3 -5
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +3 -5
- package/dist/src/channels/cmd/@cmd.js +0 -4
- package/dist/src/channels/cmd/CmdChannel.js +0 -4
- package/dist/src/channels/express/ExpressProvider.js +46 -0
- package/dist/src/channels/http/HttpServerProvider.js +31 -0
- package/dist/src/channels/{socket-io → socket}/@socket.js +0 -4
- package/dist/src/channels/{socket-io → socket}/SocketChannel.js +12 -11
- package/dist/src/channels/socket/SocketServerProvider.js +50 -0
- package/dist/src/channels/telegram/@telegram.js +0 -4
- package/dist/src/channels/telegram/TelegramChannel.js +0 -4
- package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
- package/dist/src/channels/{whatsapp/WhatsAppDevSocketContracts.js → wabot/WabotDevSocketContracts.js} +3 -3
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
- package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
- package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
- package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
- package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
- package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
- package/dist/src/channels/whatsapp/WhatsAppSender.js +76 -17
- package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +124 -0
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +61 -0
- package/dist/src/chatbot/ChatBotAdapter.js +1 -5
- package/dist/src/chatbot/metadata/@chatBot.js +0 -5
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
- package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
- package/dist/src/controller/metadata/controller/@chatController.js +0 -2
- package/dist/src/core/IMessageContext.js +0 -2
- package/dist/src/env/WabotEnv.js +6 -0
- package/dist/src/index.d.ts +270 -202
- package/dist/src/index.js +28 -27
- package/dist/src/mindset/MindsetOperator.js +0 -2
- package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
- package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
- package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
- package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
- package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
- package/dist/src/repository/pg/PgCrudRepository.js +0 -1
- package/dist/src/server/prepareChatContainer.js +4 -4
- package/dist/src/server/runChannel.js +2 -10
- package/dist/src/server/runServer.js +0 -43
- package/package.json +2 -4
- package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -69
- package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -39
- package/dist/src/controller/express/Express.js +0 -5
- package/dist/src/controller/socket.io/SocketIO.js +0 -5
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
- package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
- package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
- package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
- /package/dist/src/channels/{socket-io → socket}/SocketChannelConfig.js +0 -0
package/dist/src/index.js
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
export { OpenaiChatBotAdapter } from './ai/openia/OpenaiChatBotAdapter.js';
|
|
2
1
|
export { DeepSeekChatBotAdapter } from './ai/deepseek/DeepSeekChatBotAdapter.js';
|
|
2
|
+
export { OpenaiChatBotAdapter } from './ai/openia/OpenaiChatBotAdapter.js';
|
|
3
3
|
export { cmd } from './channels/cmd/@cmd.js';
|
|
4
4
|
export { CmdChannel } from './channels/cmd/CmdChannel.js';
|
|
5
|
+
export { ExpressProvider } from './channels/express/ExpressProvider.js';
|
|
6
|
+
export { HttpServerProvider } from './channels/http/HttpServerProvider.js';
|
|
7
|
+
export { socket } from './channels/socket/@socket.js';
|
|
8
|
+
export { SocketChannel } from './channels/socket/SocketChannel.js';
|
|
9
|
+
export { SocketChannelConfig } from './channels/socket/SocketChannelConfig.js';
|
|
10
|
+
export { SocketServerProvider } from './channels/socket/SocketServerProvider.js';
|
|
5
11
|
export { telegram } from './channels/telegram/@telegram.js';
|
|
6
12
|
export { TelegramChannelConfig } from './channels/telegram/TelegramChannelConfig.js';
|
|
7
13
|
export { TelegramChannel } from './channels/telegram/TelegramChannel.js';
|
|
8
14
|
export { whatsapp } from './channels/whatsapp/@whatsapp.js';
|
|
15
|
+
export { WhatsApp } from './channels/whatsapp/WhatsApp.js';
|
|
9
16
|
export { WhatsAppChannel } from './channels/whatsapp/WhatsAppChannel.js';
|
|
10
17
|
export { WhatsappChannelConfig } from './channels/whatsapp/WhatsAppChannelConfig.js';
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
18
|
+
export { WhatsAppReceiver } from './channels/whatsapp/WhatsAppReceiver.js';
|
|
19
|
+
export { WhatsAppReceiverByDevConnection } from './channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
20
|
+
export { WhatsAppReceiverByWebHook } from './channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
21
|
+
export { WhatsAppRepository } from './channels/whatsapp/WhatsAppRepository.js';
|
|
15
22
|
export { WhatsAppSender } from './channels/whatsapp/WhatsAppSender.js';
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
23
|
+
export { WhatsAppSenderByDevConnection } from './channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
24
|
+
export { WhatsAppSenderByCloudApi } from './channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
25
|
+
export { PgWhatsAppRepository } from './channels/whatsapp/PgWhatsAppRepository.js';
|
|
26
|
+
export { EnvWhatsAppRepository } from './channels/whatsapp/EnvWhatsAppRepository.js';
|
|
19
27
|
export { chatBot } from './chatbot/metadata/@chatBot.js';
|
|
20
28
|
export { ChatBotMetadataStore } from './chatbot/metadata/ChatBotMetadataStore.js';
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
29
|
+
export { ChatBot } from './chatbot/ChatBot.js';
|
|
30
|
+
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
31
|
+
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
32
|
+
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
33
|
+
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
34
|
+
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
25
35
|
export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
26
36
|
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
27
37
|
export { Chat } from './core/chat/Chat.js';
|
|
@@ -30,23 +40,19 @@ export { User } from './core/user/User.js';
|
|
|
30
40
|
export { UserRepository } from './core/user/IUserRepository.js';
|
|
31
41
|
export { MessageContext } from './core/IMessageContext.js';
|
|
32
42
|
export { Persistent } from './core/Persistent.js';
|
|
43
|
+
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
44
|
+
export { mindsetFunction } from './mindset/metadata/functions/@mindsetFunction.js';
|
|
45
|
+
export { MINDSET_FUNCTION_DECORATION_FUNCTION } from './mindset/metadata/functions/decoratorNames.js';
|
|
46
|
+
export { mindset } from './mindset/metadata/mindsets/@mindset.js';
|
|
47
|
+
export { MINDSET_DECORATION_MINDSET } from './mindset/metadata/mindsets/decoratorNames.js';
|
|
33
48
|
export { mindsetModule } from './mindset/metadata/modules/@mindsetModule.js';
|
|
34
49
|
export { MINDSET_MODULE_DECORATION_MODULE } from './mindset/metadata/modules/decoratorNames.js';
|
|
35
50
|
export { isOptional } from './mindset/metadata/params/@isOptional.js';
|
|
36
51
|
export { param } from './mindset/metadata/params/@param.js';
|
|
37
52
|
export { PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM } from './mindset/metadata/params/decoratorNames.js';
|
|
38
|
-
export { Mindset } from './mindset/IMindset.js';
|
|
39
53
|
export { MindsetMetadataStore } from './mindset/metadata/MindsetMetadataStore.js';
|
|
54
|
+
export { Mindset } from './mindset/IMindset.js';
|
|
40
55
|
export { MindsetOperator } from './mindset/MindsetOperator.js';
|
|
41
|
-
export { ChatBot } from './chatbot/ChatBot.js';
|
|
42
|
-
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
43
|
-
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
44
|
-
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
45
|
-
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
46
|
-
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
47
|
-
export { ExpressApp } from './controller/express/Express.js';
|
|
48
|
-
export { SocketIoApp } from './controller/socket.io/SocketIO.js';
|
|
49
|
-
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
50
56
|
export { prepareChatContainer } from './server/prepareChatContainer.js';
|
|
51
57
|
export { runChannel } from './server/runChannel.js';
|
|
52
58
|
export { runServer } from './server/runServer.js';
|
|
@@ -59,17 +65,12 @@ export { EmailService } from './pre-made/service/EmailService.js';
|
|
|
59
65
|
export { OtpService } from './pre-made/service/OtpService.js';
|
|
60
66
|
export { PgUserRepository } from './pre-made/repository/user/pg/PgUserRepository.js';
|
|
61
67
|
export { RamUserRepository } from './pre-made/repository/user/ram/RamUserRepository.js';
|
|
62
|
-
export { SqliteUserRepository } from './pre-made/repository/user/sqlite/SqliteUserRepository.js';
|
|
63
68
|
export { PgChatRepository } from './pre-made/repository/chat/pg/PgChatRepository.js';
|
|
64
69
|
export { PgChatMemory } from './pre-made/repository/chat/pg/PgChatMemory.js';
|
|
65
|
-
export { SqliteChatMemory } from './pre-made/repository/chat/sqlite/SqliteChatMemory.js';
|
|
66
|
-
export { SqliteChatRepository } from './pre-made/repository/chat/sqlite/SqliteChatRepository.js';
|
|
67
70
|
export { RamChatMemory } from './pre-made/repository/chat/ram/RamChatMemory.js';
|
|
68
71
|
export { RamChatRepository } from './pre-made/repository/chat/ram/RamChatRepository.js';
|
|
69
72
|
export { PgCrudRepository } from './repository/pg/PgCrudRepository.js';
|
|
70
73
|
export { PgRepositoryBase } from './repository/pg/PgRepositoryBase.js';
|
|
71
|
-
export { SqliteCrudRepository } from './repository/sqlite/SqliteCrudRepository.js';
|
|
72
|
-
export { SqlitePersistentMapper, sqliteMapperFor } from './repository/sqlite/SqlitePersistentMapper.js';
|
|
73
74
|
export { Logger } from './logger/Logger.js';
|
|
74
75
|
export { WabotEnv } from './env/WabotEnv.js';
|
|
75
76
|
export { Container } from './injection/Container.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { injectable } from '../injection/index.js';
|
|
3
3
|
import { Mindset } from './IMindset.js';
|
|
4
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
5
|
-
import '../core/user/IUserRepository.js';
|
|
6
4
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
7
5
|
import { Container } from '../injection/Container.js';
|
|
8
6
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { singleton } from '../../injection/index.js';
|
|
3
|
-
import '../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../core/user/IUserRepository.js';
|
|
5
3
|
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './functions/decoratorNames.js';
|
|
6
4
|
import { MINDSET_DECORATION_MINDSET } from './mindsets/decoratorNames.js';
|
|
7
5
|
import { MINDSET_MODULE_DECORATION_MODULE } from './modules/decoratorNames.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import '../../../core/user/IUserRepository.js';
|
|
4
2
|
import { container, injectable } from '../../../injection/index.js';
|
|
5
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
6
4
|
import { MINDSET_DECORATION_MINDSET } from './decoratorNames.js';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { container, injectable } from '../../../injection/index.js';
|
|
3
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../../core/user/IUserRepository.js';
|
|
5
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
6
4
|
import { MINDSET_MODULE_DECORATION_MODULE } from './decoratorNames.js';
|
|
7
5
|
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
2
1
|
import '../../../../core/chat/repository/IChatRepository.js';
|
|
2
|
+
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
3
3
|
import '../../../../core/user/IUserRepository.js';
|
|
4
4
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
5
|
-
import 'fs';
|
|
6
|
-
import 'path';
|
|
7
|
-
import 'sqlite';
|
|
8
|
-
import 'sqlite3';
|
|
9
|
-
import 'uuid';
|
|
10
|
-
import 'pg';
|
|
11
5
|
|
|
12
6
|
class PgChatMemory extends PgCrudRepository {
|
|
13
7
|
chatId;
|
|
@@ -6,11 +6,6 @@ import { singleton } from '../../../../injection/index.js';
|
|
|
6
6
|
import { Pool } from 'pg';
|
|
7
7
|
import { PgChatMemory } from './PgChatMemory.js';
|
|
8
8
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
9
|
-
import 'fs';
|
|
10
|
-
import 'path';
|
|
11
|
-
import 'sqlite';
|
|
12
|
-
import 'sqlite3';
|
|
13
|
-
import 'uuid';
|
|
14
9
|
|
|
15
10
|
let PgChatRepository = class PgChatRepository extends PgCrudRepository {
|
|
16
11
|
constructor(pool) {
|
|
@@ -4,11 +4,6 @@ import { User } from '../../../../core/user/User.js';
|
|
|
4
4
|
import '../../../../core/user/IUserRepository.js';
|
|
5
5
|
import { singleton } from '../../../../injection/index.js';
|
|
6
6
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
7
|
-
import 'fs';
|
|
8
|
-
import 'path';
|
|
9
|
-
import 'sqlite';
|
|
10
|
-
import 'sqlite3';
|
|
11
|
-
import 'uuid';
|
|
12
7
|
import { Pool } from 'pg';
|
|
13
8
|
|
|
14
9
|
let PgUserRepository = class PgUserRepository extends PgCrudRepository {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
|
|
2
|
-
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import '../core/user/IUserRepository.js';
|
|
4
|
-
import { MessageContext } from '../core/IMessageContext.js';
|
|
5
1
|
import '../injection/index.js';
|
|
6
2
|
import 'reflect-metadata';
|
|
7
3
|
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
8
4
|
import { Mindset } from '../mindset/IMindset.js';
|
|
9
5
|
import '../mindset/MindsetOperator.js';
|
|
6
|
+
import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
|
|
7
|
+
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
8
|
+
import '../core/user/IUserRepository.js';
|
|
9
|
+
import { MessageContext } from '../core/IMessageContext.js';
|
|
10
10
|
import 'uuid';
|
|
11
11
|
import { ChatBotMetadataStore } from '../chatbot/metadata/ChatBotMetadataStore.js';
|
|
12
12
|
import { ChatBot } from '../chatbot/ChatBot.js';
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import { container } from '../injection/index.js';
|
|
3
|
-
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
4
|
-
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
5
|
-
import '../core/user/IUserRepository.js';
|
|
6
|
-
import '../mindset/MindsetOperator.js';
|
|
7
2
|
import 'uuid';
|
|
8
3
|
import '../chatbot/metadata/ChatBotMetadataStore.js';
|
|
9
4
|
import { ChatBot } from '../chatbot/ChatBot.js';
|
|
10
5
|
import { ChatBotAdapter } from '../chatbot/ChatBotAdapter.js';
|
|
11
|
-
import '../
|
|
12
|
-
import '../
|
|
13
|
-
import '../controller/metadata/ControllerMetadataStore.js';
|
|
14
|
-
import 'express';
|
|
15
|
-
import 'socket.io';
|
|
6
|
+
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
7
|
+
import '../core/user/IUserRepository.js';
|
|
16
8
|
import { prepareChatContainer } from './prepareChatContainer.js';
|
|
17
9
|
|
|
18
10
|
function runChannel(props) {
|
|
@@ -1,49 +1,10 @@
|
|
|
1
1
|
import '../controller/channel/ChatResolver.js';
|
|
2
2
|
import '../controller/channel/UserResolver.js';
|
|
3
3
|
import { container } from '../injection/index.js';
|
|
4
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
5
|
-
import '../core/user/IUserRepository.js';
|
|
6
4
|
import { ControllerMetadataStore } from '../controller/metadata/ControllerMetadataStore.js';
|
|
7
|
-
import { ExpressApp } from '../controller/express/Express.js';
|
|
8
|
-
import { SocketIoApp } from '../controller/socket.io/SocketIO.js';
|
|
9
5
|
import { prepareChatContainer } from './prepareChatContainer.js';
|
|
10
|
-
import express from 'express';
|
|
11
|
-
import { Server } from 'socket.io';
|
|
12
|
-
import http from 'http';
|
|
13
|
-
import bodyParser from 'body-parser';
|
|
14
|
-
import { Logger } from '../logger/Logger.js';
|
|
15
6
|
|
|
16
7
|
function runServer(config) {
|
|
17
|
-
const httpLogger = new Logger('wabot:http');
|
|
18
|
-
const socketLogger = new Logger('wabot:socket');
|
|
19
|
-
const expressApp = express();
|
|
20
|
-
const httpServer = http.createServer(expressApp);
|
|
21
|
-
const io = new Server(httpServer, {
|
|
22
|
-
cors: {
|
|
23
|
-
origin: '*',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
expressApp.use(bodyParser.json());
|
|
27
|
-
expressApp.use((req, res, next) => {
|
|
28
|
-
const start = process.hrtime();
|
|
29
|
-
res.on('finish', () => {
|
|
30
|
-
const [seconds, nanoseconds] = process.hrtime(start);
|
|
31
|
-
const ms = (seconds * 1000 + nanoseconds / 1e6).toFixed(2);
|
|
32
|
-
httpLogger.trace(`${req.method} ${req.originalUrl} ${res.statusCode} - ${ms}ms`);
|
|
33
|
-
});
|
|
34
|
-
next();
|
|
35
|
-
});
|
|
36
|
-
io.on('connection', (socket) => {
|
|
37
|
-
socketLogger.trace(`socket:${socket.id} connection`);
|
|
38
|
-
socket.onAny((event) => {
|
|
39
|
-
socketLogger.trace(`socket:${socket.id} emmits ${event}`);
|
|
40
|
-
});
|
|
41
|
-
socket.on('disconnect', (reason) => {
|
|
42
|
-
socketLogger.trace(`socket:${socket.id} disconnect with reason: ${reason}`);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
container.register(ExpressApp, { useValue: expressApp });
|
|
46
|
-
container.register(SocketIoApp, { useValue: io });
|
|
47
8
|
for (const provider of config.providers ?? []) {
|
|
48
9
|
if (provider.singleton) {
|
|
49
10
|
container.registerSingleton(provider.replace, provider.with);
|
|
@@ -74,10 +35,6 @@ function runServer(config) {
|
|
|
74
35
|
channel.connect();
|
|
75
36
|
}
|
|
76
37
|
}
|
|
77
|
-
const PORT = process.env.PORT || 3000;
|
|
78
|
-
httpServer.listen(PORT, () => {
|
|
79
|
-
httpLogger.info(`server listenig on port ${PORT}`);
|
|
80
|
-
});
|
|
81
38
|
}
|
|
82
39
|
|
|
83
40
|
export { runServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wabot-dev/framework",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "Framework for IA Chat Bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"fmt": "prettier --write .",
|
|
17
17
|
"fmt:check": "prettier --check .",
|
|
18
18
|
"types:check": "tsc --noEmit",
|
|
19
|
-
"elia:dev": "yts --import ./
|
|
19
|
+
"elia:dev": "yts --import ./env.mjs ./test/elia/runElia.ts"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@rollup/plugin-alias": "5.1.1",
|
|
@@ -51,8 +51,6 @@
|
|
|
51
51
|
"short-uuid": "^5.2.0",
|
|
52
52
|
"socket.io": "^4.8.1",
|
|
53
53
|
"socket.io-client": "^4.8.1",
|
|
54
|
-
"sqlite": "^5.1.1",
|
|
55
|
-
"sqlite3": "^5.1.7",
|
|
56
54
|
"tslib": "^2.8.1",
|
|
57
55
|
"tsyringe": "^4.9.1",
|
|
58
56
|
"uuid": "^11.1.0"
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { singleton } from '../../injection/index.js';
|
|
3
|
-
import { Logger } from '../../logger/Logger.js';
|
|
4
|
-
import { io } from 'socket.io-client';
|
|
5
|
-
import { WhatsAppConnection } from './WhatsAppConnection.js';
|
|
6
|
-
import { devWhatsappEmitEvent, devWhatsAppListentEvent } from './WhatsAppDevSocketContracts.js';
|
|
7
|
-
|
|
8
|
-
let WhatsAppDevConnection = class WhatsAppDevConnection extends WhatsAppConnection {
|
|
9
|
-
devProxy;
|
|
10
|
-
devProxySocket;
|
|
11
|
-
devToken;
|
|
12
|
-
connected = false;
|
|
13
|
-
constructor() {
|
|
14
|
-
super(new Logger('wabot:whatsapp-dev-connection'));
|
|
15
|
-
this.devProxy = process.env.WABOT_DEV_PROXY ?? 'https://proxy.wabot.dev';
|
|
16
|
-
this.devToken = process.env.WABOT_DEV_TOKEN;
|
|
17
|
-
this.devProxySocket = io(this.devProxy, { autoConnect: false });
|
|
18
|
-
}
|
|
19
|
-
async sendWhatsApp(businessNumber, to, chatMessage) {
|
|
20
|
-
const req = {
|
|
21
|
-
from: businessNumber,
|
|
22
|
-
to,
|
|
23
|
-
message: chatMessage,
|
|
24
|
-
};
|
|
25
|
-
await this.devProxySocket.emitWithAck(devWhatsappEmitEvent.DEV_SEND_WHATSAPP, req);
|
|
26
|
-
}
|
|
27
|
-
async sendWhatsAppTemplate(businessNumber, to, templateMessage) {
|
|
28
|
-
const req = {
|
|
29
|
-
from: businessNumber,
|
|
30
|
-
to,
|
|
31
|
-
message: templateMessage,
|
|
32
|
-
};
|
|
33
|
-
await this.devProxySocket.emitWithAck(devWhatsappEmitEvent.DEV_SEND_WHATSAPP_TEMPLATE, req);
|
|
34
|
-
}
|
|
35
|
-
connect() {
|
|
36
|
-
if (this.connected) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.connected = true;
|
|
40
|
-
this.devProxySocket.connect();
|
|
41
|
-
this.devProxySocket.on('connect', async () => {
|
|
42
|
-
if (!this.devToken) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const req = {
|
|
47
|
-
token: this.devToken,
|
|
48
|
-
};
|
|
49
|
-
const ack = await this.devProxySocket.emitWithAck(devWhatsappEmitEvent.DEV_CONNECTION, req);
|
|
50
|
-
if (ack != 'OK') {
|
|
51
|
-
return this.logger.debug('dev connection fails');
|
|
52
|
-
}
|
|
53
|
-
this.devProxySocket.on(devWhatsAppListentEvent.DEV_WATSAPP_WEBHOOK, async (payload) => {
|
|
54
|
-
await this.handlePayload(payload);
|
|
55
|
-
});
|
|
56
|
-
return this.logger.debug('success dev connection');
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
this.logger.error(err);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
WhatsAppDevConnection = __decorate([
|
|
65
|
-
singleton(),
|
|
66
|
-
__metadata("design:paramtypes", [])
|
|
67
|
-
], WhatsAppDevConnection);
|
|
68
|
-
|
|
69
|
-
export { WhatsAppDevConnection };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param, __metadata } from 'tslib';
|
|
2
|
-
import '../../controller/channel/ChatResolver.js';
|
|
3
|
-
import '../../controller/channel/UserResolver.js';
|
|
4
|
-
import { inject } from '../../injection/index.js';
|
|
5
|
-
import '../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../core/user/IUserRepository.js';
|
|
7
|
-
import '../../controller/metadata/ControllerMetadataStore.js';
|
|
8
|
-
import { ExpressApp } from '../../controller/express/Express.js';
|
|
9
|
-
import 'socket.io';
|
|
10
|
-
import { singleton } from 'tsyringe';
|
|
11
|
-
|
|
12
|
-
let WhatsAppProdConnection = class WhatsAppProdConnection {
|
|
13
|
-
express;
|
|
14
|
-
constructor(express) {
|
|
15
|
-
this.express = express;
|
|
16
|
-
this.express.get('/try-express', (req, res) => {
|
|
17
|
-
res.status(200).json({ success: true });
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
listenMessage(businessNumber, listener) {
|
|
21
|
-
throw new Error('Method not implemented.');
|
|
22
|
-
}
|
|
23
|
-
sendWhatsApp(businessNumber, to, replyMessage) {
|
|
24
|
-
throw new Error('Method not implemented.');
|
|
25
|
-
}
|
|
26
|
-
sendWhatsAppTemplate(businessNumber, to, templateMessage) {
|
|
27
|
-
throw new Error('Method not implemented.');
|
|
28
|
-
}
|
|
29
|
-
connect() {
|
|
30
|
-
throw new Error('Method not implemented.');
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
WhatsAppProdConnection = __decorate([
|
|
34
|
-
singleton(),
|
|
35
|
-
__param(0, inject(ExpressApp)),
|
|
36
|
-
__metadata("design:paramtypes", [Function])
|
|
37
|
-
], WhatsAppProdConnection);
|
|
38
|
-
|
|
39
|
-
export { WhatsAppProdConnection };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
3
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../../../core/user/IUserRepository.js';
|
|
5
|
-
import 'pg';
|
|
6
|
-
import 'short-uuid';
|
|
7
|
-
import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
|
|
8
|
-
import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
|
|
9
|
-
|
|
10
|
-
class SqliteChatMemory extends SqliteCrudRepository {
|
|
11
|
-
constructor(chatId) {
|
|
12
|
-
super('chat_item', SqliteChatMemory.getDbPath(chatId), sqliteMapperFor(ChatItem));
|
|
13
|
-
}
|
|
14
|
-
async findLastItems(count) {
|
|
15
|
-
const allItems = await this.findAll();
|
|
16
|
-
return allItems.slice(allItems.length - count, allItems.length);
|
|
17
|
-
}
|
|
18
|
-
static getDbPath(chatId) {
|
|
19
|
-
return path.join(process.cwd(), '.sqlite', 'chat-memory', chatId + '.db');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { SqliteChatMemory };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
2
|
-
import { Chat } from '../../../../core/chat/Chat.js';
|
|
3
|
-
import '../../../../core/user/IUserRepository.js';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { SqliteChatMemory } from './SqliteChatMemory.js';
|
|
6
|
-
import 'pg';
|
|
7
|
-
import 'short-uuid';
|
|
8
|
-
import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
|
|
9
|
-
import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
|
|
10
|
-
|
|
11
|
-
class SqliteChatRepository extends SqliteCrudRepository {
|
|
12
|
-
constructor() {
|
|
13
|
-
super('chat', SqliteChatRepository.getDbPath(), sqliteMapperFor(Chat));
|
|
14
|
-
}
|
|
15
|
-
async findByConnection(query) {
|
|
16
|
-
const allChats = await this.findAll();
|
|
17
|
-
return allChats.find((chat) => chat.hasConnection(query)) ?? null;
|
|
18
|
-
}
|
|
19
|
-
async findMemory(chatId) {
|
|
20
|
-
const chat = await this.find(chatId);
|
|
21
|
-
if (!chat)
|
|
22
|
-
return null;
|
|
23
|
-
return new SqliteChatMemory(chatId);
|
|
24
|
-
}
|
|
25
|
-
static getDbPath() {
|
|
26
|
-
return path.join(process.cwd(), '.sqlite', 'chat.db');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { SqliteChatRepository };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
2
|
-
import { User } from '../../../../core/user/User.js';
|
|
3
|
-
import '../../../../core/user/IUserRepository.js';
|
|
4
|
-
import 'pg';
|
|
5
|
-
import 'short-uuid';
|
|
6
|
-
import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
|
|
7
|
-
import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
|
|
10
|
-
class SqliteUserRepository extends SqliteCrudRepository {
|
|
11
|
-
constructor() {
|
|
12
|
-
super('user', SqliteUserRepository.getDbPath(), sqliteMapperFor(User));
|
|
13
|
-
}
|
|
14
|
-
async findByConnection(query) {
|
|
15
|
-
const allItems = await this.findAll();
|
|
16
|
-
return allItems.find((item) => item.hasConnection(query)) ?? null;
|
|
17
|
-
}
|
|
18
|
-
static getDbPath() {
|
|
19
|
-
return path.join(process.cwd(), '.sqlite', 'user.db');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { SqliteUserRepository };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { promises } from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { open } from 'sqlite';
|
|
4
|
-
import sqlite3 from 'sqlite3';
|
|
5
|
-
import { v4 } from 'uuid';
|
|
6
|
-
|
|
7
|
-
class SqliteCrudRepository {
|
|
8
|
-
table;
|
|
9
|
-
dbPath;
|
|
10
|
-
mapper;
|
|
11
|
-
tableCreated = false;
|
|
12
|
-
constructor(table, dbPath, mapper) {
|
|
13
|
-
this.table = table;
|
|
14
|
-
this.dbPath = dbPath;
|
|
15
|
-
this.mapper = mapper;
|
|
16
|
-
}
|
|
17
|
-
async find(id) {
|
|
18
|
-
const db = await this.getDb();
|
|
19
|
-
const result = await db.all(`SELECT id, data FROM ${this.table} WHERE id=?`, [
|
|
20
|
-
id,
|
|
21
|
-
]);
|
|
22
|
-
db.close();
|
|
23
|
-
if (result.length < 1) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
const item = this.mapper.rev(result[0].data);
|
|
27
|
-
return item;
|
|
28
|
-
}
|
|
29
|
-
async findAll() {
|
|
30
|
-
const db = await this.getDb();
|
|
31
|
-
const result = await db.all(`SELECT id, data FROM ${this.table}`);
|
|
32
|
-
db.close();
|
|
33
|
-
const items = result.map((item) => this.mapper.rev(item.data));
|
|
34
|
-
return items;
|
|
35
|
-
}
|
|
36
|
-
async create(item) {
|
|
37
|
-
if (item.wasCreated()) {
|
|
38
|
-
throw new Error('Item already created');
|
|
39
|
-
}
|
|
40
|
-
item['data'].id = v4();
|
|
41
|
-
item['data'].createdAt = new Date().getTime();
|
|
42
|
-
item.validate();
|
|
43
|
-
const db = await this.getDb();
|
|
44
|
-
await db.run(`INSERT INTO ${this.table} VALUES (?, ?, ?)`, [
|
|
45
|
-
item.getId(),
|
|
46
|
-
item.getCreatedAt().getTime(),
|
|
47
|
-
this.mapper.map(item),
|
|
48
|
-
]);
|
|
49
|
-
db.close();
|
|
50
|
-
}
|
|
51
|
-
async update(item) {
|
|
52
|
-
if (!item.wasCreated()) {
|
|
53
|
-
throw new Error('Item is not created');
|
|
54
|
-
}
|
|
55
|
-
item.validate();
|
|
56
|
-
const db = await this.getDb();
|
|
57
|
-
await db.run(`UPDATE ${this.table} SET data=? WHERE id=?`, [
|
|
58
|
-
this.mapper.map(item),
|
|
59
|
-
item.getId(),
|
|
60
|
-
]);
|
|
61
|
-
db.close();
|
|
62
|
-
}
|
|
63
|
-
async discard(item) {
|
|
64
|
-
item.discard();
|
|
65
|
-
await this.update(item);
|
|
66
|
-
}
|
|
67
|
-
async getDb() {
|
|
68
|
-
const dbDirPath = path.dirname(this.dbPath);
|
|
69
|
-
await promises.mkdir(dbDirPath, { recursive: true });
|
|
70
|
-
const db = await open({
|
|
71
|
-
filename: this.dbPath,
|
|
72
|
-
driver: sqlite3.Database,
|
|
73
|
-
});
|
|
74
|
-
if (!this.tableCreated) {
|
|
75
|
-
this.tableCreated = true;
|
|
76
|
-
await this.createTable(db);
|
|
77
|
-
}
|
|
78
|
-
return db;
|
|
79
|
-
}
|
|
80
|
-
async createTable(db) {
|
|
81
|
-
await db.exec(`CREATE TABLE IF NOT EXISTS ${this.table}(id TEXT, created_at INTEGER, data TEXT)`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { SqliteCrudRepository };
|