@wabot-dev/framework 0.9.1 → 0.9.5
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/in-memory/InMemoryCronJobRepository.js +45 -0
- package/dist/src/addon/async/in-memory/InMemoryJobRepository.js +75 -0
- package/dist/src/addon/async/in-memory/index.js +2 -0
- package/dist/src/addon/async/pg/PgCronJobRepository.js +7 -5
- package/dist/src/addon/async/pg/PgJobRepository.js +8 -5
- package/dist/src/addon/async/pg/PgTransactionAdapter.js +25 -0
- package/dist/src/addon/async/pg/index.js +3 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +4 -4
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +9 -8
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +4 -4
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +6 -5
- package/dist/src/addon/chat-bot/{ram/RamChatMemory.js → in-memory/InMemoryChatMemory.js} +2 -2
- package/dist/src/addon/chat-bot/{ram/RamChatRepository.js → in-memory/InMemoryChatRepository.js} +6 -6
- package/dist/src/addon/chat-bot/in-memory/index.js +2 -0
- package/dist/src/addon/chat-bot/pg/PgChatMemory.js +8 -7
- package/dist/src/addon/chat-bot/pg/PgChatRepository.js +7 -6
- package/dist/src/addon/chat-bot/pg/index.js +2 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +7 -2
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +85 -61
- package/dist/src/addon/chat-controller/cmd/CmdChannelConfig.js +8 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannelServer.js +169 -0
- package/dist/src/addon/chat-controller/cmd/cmdChannelSocketPath.js +16 -0
- package/dist/src/addon/chat-controller/cmd/runCmdClient.js +226 -0
- package/dist/src/addon/chat-controller/socket/@socket.js +3 -1
- package/dist/src/addon/chat-controller/socket/SocketChannelConfig.js +4 -4
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppSender.js +2 -72
- package/dist/src/addon/chat-controller/whatsapp/{WhatsAppReceiver.js → cloud-api/WhatsAppApiReceiver.js} +2 -2
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppApiSender.js +67 -0
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +5 -7
- package/dist/src/addon/chat-controller/whatsapp/wasender/@wasender.js +23 -0
- package/dist/src/addon/chat-controller/{wasender/WhatsAppByWasenderChannel.js → whatsapp/wasender/WasenderChannel.js} +20 -20
- package/dist/src/addon/chat-controller/{wasender/WhatsAppByWasenderChannelConfig.js → whatsapp/wasender/WasenderChannelConfig.js} +3 -3
- package/dist/src/addon/chat-controller/whatsapp/wasender/WasenderChannelName.js +3 -0
- package/dist/src/addon/chat-controller/{wasender/WhatsAppReceiverByWasender.js → whatsapp/wasender/WasenderReceiver.js} +7 -7
- package/dist/src/addon/chat-controller/{wasender/WhatsAppSenderByWasender.js → whatsapp/wasender/WasenderSender.js} +8 -5
- package/dist/src/addon/chat-controller/{wasender → whatsapp/wasender}/WasenderWebhookController.js +4 -4
- package/dist/src/addon/lock/InMemoryLockKey.js +45 -0
- package/dist/src/addon/lock/InMemoryLocker.js +15 -0
- package/dist/src/addon/lock/index.js +2 -0
- package/dist/src/core/repository/CrudRepository.js +25 -0
- package/dist/src/feature/async/{@cron.js → @cronHandler.js} +2 -2
- package/dist/src/feature/async/@transaction.js +22 -0
- package/dist/src/feature/async/AsyncMetadataStore.js +6 -0
- package/dist/src/feature/async/TransactionMetadataStore.js +28 -0
- package/dist/src/feature/chat-controller/metadata/ControllerMetadataStore.js +3 -0
- package/dist/src/feature/pg/@pgExtension.js +33 -0
- package/dist/src/feature/pg/PgJsonRepositoryAdapter.js +50 -0
- package/dist/src/feature/pg/index.js +10 -0
- package/dist/src/feature/project-runner/ProjectRunner.js +276 -0
- package/dist/src/feature/repository/@memoryExtension.js +29 -0
- package/dist/src/feature/repository/@query.js +22 -0
- package/dist/src/feature/repository/@queryExtension.js +21 -0
- package/dist/src/feature/repository/@repository.js +170 -0
- package/dist/src/feature/repository/MemoryRepositoryAdapter.js +110 -0
- package/dist/src/feature/repository/RepositoryAdapterRegistry.js +27 -0
- package/dist/src/feature/repository/RepositoryMetadataStore.js +102 -0
- package/dist/src/feature/repository/evaluateQueryAst.js +134 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +3 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +3 -0
- package/dist/src/index.d.ts +377 -298
- package/dist/src/index.js +40 -34
- package/package.json +9 -7
- package/dist/src/addon/chat-controller/wasender/@whatsAppByWasender.js +0 -20
- package/dist/src/addon/chat-controller/wasender/whatsAppByWasenderChannelName.js +0 -3
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +0 -20
- package/dist/src/addon/chat-controller/whatsapp/EnvWhatsAppRepository.js +0 -49
- package/dist/src/addon/chat-controller/whatsapp/PgWhatsAppRepository.js +0 -48
- package/dist/src/addon/chat-controller/whatsapp/WhatsApp.js +0 -30
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppChannel.js +0 -58
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppChannelConfig.js +0 -8
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppRepository.js +0 -10
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppSenderByCloudApi.js +0 -133
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +0 -5
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +0 -67
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +0 -63
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +0 -45
- package/dist/src/feature/pg/query/@pgJsonRepository.js +0 -73
- package/dist/src/feature/pg/query/@query.js +0 -14
- package/dist/src/feature/pg/query/PgJsonRepository.js +0 -23
- package/dist/src/feature/pg/query/PgRepositoryMetadataStore.js +0 -44
- /package/dist/src/addon/chat-controller/whatsapp/{whatsAppChannelName.js → cloud-api/whatsAppChannelName.js} +0 -0
- /package/dist/src/addon/chat-controller/{wasender → whatsapp/wasender}/extractNumberFromWasenderKey.js +0 -0
- /package/dist/src/feature/pg/{query/buildQuerySql.js → buildQuerySql.js} +0 -0
- /package/dist/src/feature/{pg/query → repository}/parseQueryMethodName.js +0 -0
package/dist/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { Logger } from './core/logger/Logger.js';
|
|
|
10
10
|
export { Mapper } from './core/mapper/Mapper.js';
|
|
11
11
|
export { Password } from './core/password/Password.js';
|
|
12
12
|
export { Random } from './core/random/Random.js';
|
|
13
|
+
export { CrudRepository } from './core/repository/CrudRepository.js';
|
|
13
14
|
export { Storable } from './core/storable/Storable.js';
|
|
14
15
|
export { isModel } from './core/validation/metadata/@isModel.js';
|
|
15
16
|
export { isOptional } from './core/validation/metadata/@isOptional.js';
|
|
@@ -44,7 +45,8 @@ export { DescriptionMetadataStore } from './core/description/metadata/Descriptio
|
|
|
44
45
|
export { Locker } from './core/lock/Locker.js';
|
|
45
46
|
export { command } from './feature/async/@command.js';
|
|
46
47
|
export { commandHandler } from './feature/async/@commandHandler.js';
|
|
47
|
-
export {
|
|
48
|
+
export { cronHandler } from './feature/async/@cronHandler.js';
|
|
49
|
+
export { transaction } from './feature/async/@transaction.js';
|
|
48
50
|
export { Async } from './feature/async/Async.js';
|
|
49
51
|
export { AsyncMetadataStore } from './feature/async/AsyncMetadataStore.js';
|
|
50
52
|
export { CronJob } from './feature/async/CronJob.js';
|
|
@@ -54,6 +56,8 @@ export { JobRepository } from './feature/async/JobRepository.js';
|
|
|
54
56
|
export { JobRunner } from './feature/async/JobRunner.js';
|
|
55
57
|
export { runCommandHandlers, stopCommandHandlers } from './feature/async/runCommandHandlers.js';
|
|
56
58
|
export { runCronHandlers, stopCronHandlers } from './feature/async/runCronHandlers.js';
|
|
59
|
+
export { TransactionMetadataStore } from './feature/async/TransactionMetadataStore.js';
|
|
60
|
+
export { ProjectRunner, run } from './feature/project-runner/ProjectRunner.js';
|
|
57
61
|
export { Chat } from './feature/chat-bot/Chat.js';
|
|
58
62
|
export { ChatAdapter } from './feature/chat-bot/ChatAdapter.js';
|
|
59
63
|
export { ChatAdapterRegistry } from './feature/chat-bot/ChatAdapterRegistry.js';
|
|
@@ -86,19 +90,25 @@ export { Mindset } from './feature/mindset/IMindset.js';
|
|
|
86
90
|
export { MindsetOperator } from './feature/mindset/MindsetOperator.js';
|
|
87
91
|
export { Money } from './feature/money/Money.js';
|
|
88
92
|
export { MoneyDto } from './feature/money/MoneyDto.js';
|
|
93
|
+
export { PG_ADAPTER_ID, pgExtension } from './feature/pg/@pgExtension.js';
|
|
89
94
|
export { PgCrudRepository } from './feature/pg/PgCrudRepository.js';
|
|
95
|
+
export { PgJsonRepositoryAdapter } from './feature/pg/PgJsonRepositoryAdapter.js';
|
|
90
96
|
export { PgLocker } from './feature/pg/PgLocker.js';
|
|
91
97
|
export { PgLockKey } from './feature/pg/PgLockKey.js';
|
|
92
|
-
export { PgRepositoryBase } from './feature/pg/PgRepositoryBase.js';
|
|
98
|
+
export { PgRepositoryBase, PgRepositoryBase as PgRepositoryExtension } from './feature/pg/PgRepositoryBase.js';
|
|
93
99
|
export { getClientMap, pgStorage } from './feature/pg/pgStorage.js';
|
|
94
|
-
export {
|
|
95
|
-
export { query } from './feature/pg/query/@query.js';
|
|
96
|
-
export { PgJsonRepository } from './feature/pg/query/PgJsonRepository.js';
|
|
97
|
-
export { PgRepositoryMetadataStore } from './feature/pg/query/PgRepositoryMetadataStore.js';
|
|
98
|
-
export { buildQuerySql } from './feature/pg/query/buildQuerySql.js';
|
|
99
|
-
export { parseQueryMethodName } from './feature/pg/query/parseQueryMethodName.js';
|
|
100
|
+
export { buildQuerySql } from './feature/pg/buildQuerySql.js';
|
|
100
101
|
export { getPgClient, withPgClient } from './feature/pg/withPgClient.js';
|
|
101
102
|
export { withPgTransaction } from './feature/pg/withPgTransaction.js';
|
|
103
|
+
export { memoryExtension } from './feature/repository/@memoryExtension.js';
|
|
104
|
+
export { query } from './feature/repository/@query.js';
|
|
105
|
+
export { queryExtension } from './feature/repository/@queryExtension.js';
|
|
106
|
+
export { repository } from './feature/repository/@repository.js';
|
|
107
|
+
export { evaluateQueryAst } from './feature/repository/evaluateQueryAst.js';
|
|
108
|
+
export { MEMORY_ADAPTER_ID, MemoryRepositoryAdapter, MemoryRepositoryExtension } from './feature/repository/MemoryRepositoryAdapter.js';
|
|
109
|
+
export { parseQueryMethodName } from './feature/repository/parseQueryMethodName.js';
|
|
110
|
+
export { RepositoryAdapterRegistry } from './feature/repository/RepositoryAdapterRegistry.js';
|
|
111
|
+
export { RepositoryMetadataStore } from './feature/repository/RepositoryMetadataStore.js';
|
|
102
112
|
export { onGet } from './feature/rest-controller/metadata/@onGet.js';
|
|
103
113
|
export { middleware } from './feature/rest-controller/metadata/@middleware.js';
|
|
104
114
|
export { onPost } from './feature/rest-controller/metadata/@onPost.js';
|
|
@@ -116,8 +126,11 @@ export { socketController } from './feature/socket-controller/metadata/@socketCo
|
|
|
116
126
|
export { onSocketEvent } from './feature/socket-controller/metadata/@onSocketEvent.js';
|
|
117
127
|
export { SocketControllerMetadataStore } from './feature/socket-controller/metadata/SocketControllerMetadataStore.js';
|
|
118
128
|
export { runSocketControllers } from './feature/socket-controller/runSocketControllers.js';
|
|
119
|
-
export { PgJobRepository } from './addon/async/pg/PgJobRepository.js';
|
|
120
129
|
export { PgCronJobRepository } from './addon/async/pg/PgCronJobRepository.js';
|
|
130
|
+
export { PgJobRepository } from './addon/async/pg/PgJobRepository.js';
|
|
131
|
+
export { PgTransactionAdapter } from './addon/async/pg/PgTransactionAdapter.js';
|
|
132
|
+
export { InMemoryJobRepository } from './addon/async/in-memory/InMemoryJobRepository.js';
|
|
133
|
+
export { InMemoryCronJobRepository } from './addon/async/in-memory/InMemoryCronJobRepository.js';
|
|
121
134
|
export { apiKeyHandshakeGuard } from './addon/auth/api-key/@apiKeyHandshakeGuard.js';
|
|
122
135
|
export { apiKeyGuard } from './addon/auth/api-key/@apiKeyGuard.js';
|
|
123
136
|
export { ApiKey } from './addon/auth/api-key/ApiKey.js';
|
|
@@ -145,12 +158,16 @@ export { OpenaiChatAdapter } from './addon/chat-bot/openia/OpenaiChatAdapter.js'
|
|
|
145
158
|
export { OpenRouterChatAdapter } from './addon/chat-bot/openrouter/OpenRouterChatAdapter.js';
|
|
146
159
|
export { PgChatRepository } from './addon/chat-bot/pg/PgChatRepository.js';
|
|
147
160
|
export { PgChatMemory } from './addon/chat-bot/pg/PgChatMemory.js';
|
|
148
|
-
export {
|
|
149
|
-
export {
|
|
161
|
+
export { InMemoryChatMemory } from './addon/chat-bot/in-memory/InMemoryChatMemory.js';
|
|
162
|
+
export { InMemoryChatRepository } from './addon/chat-bot/in-memory/InMemoryChatRepository.js';
|
|
150
163
|
export { WabotChatAdapter } from './addon/chat-bot/wabot/WabotChatAdapter.js';
|
|
151
164
|
export { cmd } from './addon/chat-controller/cmd/@cmd.js';
|
|
152
165
|
export { CmdChannel, readJsonFromFile, writeJsonToFile } from './addon/chat-controller/cmd/CmdChannel.js';
|
|
166
|
+
export { CmdChannelConfig } from './addon/chat-controller/cmd/CmdChannelConfig.js';
|
|
167
|
+
export { CmdChannelServer } from './addon/chat-controller/cmd/CmdChannelServer.js';
|
|
153
168
|
export { cmdChannelName } from './addon/chat-controller/cmd/cmdChannelName.js';
|
|
169
|
+
export { cmdChannelSocketPath } from './addon/chat-controller/cmd/cmdChannelSocketPath.js';
|
|
170
|
+
export { runCmdClient } from './addon/chat-controller/cmd/runCmdClient.js';
|
|
154
171
|
export { socket } from './addon/chat-controller/socket/@socket.js';
|
|
155
172
|
export { SocketChannel, SocketChannelMessageFile, SocketChannelReceivedMessage } from './addon/chat-controller/socket/SocketChannel.js';
|
|
156
173
|
export { SocketChannelConfig } from './addon/chat-controller/socket/SocketChannelConfig.js';
|
|
@@ -159,29 +176,18 @@ export { telegram } from './addon/chat-controller/telegram/@telegram.js';
|
|
|
159
176
|
export { TelegramChannelConfig } from './addon/chat-controller/telegram/TelegramChannelConfig.js';
|
|
160
177
|
export { TelegramChannel } from './addon/chat-controller/telegram/TelegramChannel.js';
|
|
161
178
|
export { telegramChannelName } from './addon/chat-controller/telegram/telegramChannelName.js';
|
|
162
|
-
export { whatsApp } from './addon/chat-controller/whatsapp/@whatsApp.js';
|
|
163
|
-
export { EnvWhatsAppRepository } from './addon/chat-controller/whatsapp/EnvWhatsAppRepository.js';
|
|
164
|
-
export { PgWhatsAppRepository } from './addon/chat-controller/whatsapp/PgWhatsAppRepository.js';
|
|
165
|
-
export { WhatsApp } from './addon/chat-controller/whatsapp/WhatsApp.js';
|
|
166
|
-
export { WhatsAppChannel } from './addon/chat-controller/whatsapp/WhatsAppChannel.js';
|
|
167
|
-
export { WhatsappChannelConfig } from './addon/chat-controller/whatsapp/WhatsAppChannelConfig.js';
|
|
168
|
-
export { WhatsAppReceiver } from './addon/chat-controller/whatsapp/WhatsAppReceiver.js';
|
|
169
|
-
export { WhatsAppRepository } from './addon/chat-controller/whatsapp/WhatsAppRepository.js';
|
|
170
|
-
export { WhatsAppSender } from './addon/chat-controller/whatsapp/WhatsAppSender.js';
|
|
171
|
-
export { whatsAppChannelName } from './addon/chat-controller/whatsapp/whatsAppChannelName.js';
|
|
172
179
|
export { WhatsAppReceiverByCloudApi } from './addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js';
|
|
173
|
-
export {
|
|
174
|
-
export {
|
|
175
|
-
export {
|
|
176
|
-
export {
|
|
177
|
-
export {
|
|
178
|
-
export {
|
|
179
|
-
export {
|
|
180
|
-
export {
|
|
181
|
-
export {
|
|
182
|
-
export {
|
|
183
|
-
export {
|
|
184
|
-
export {
|
|
185
|
-
export { whatsAppByWasenderChannelName } from './addon/chat-controller/wasender/whatsAppByWasenderChannelName.js';
|
|
180
|
+
export { WhatsAppApiSender } from './addon/chat-controller/whatsapp/cloud-api/WhatsAppApiSender.js';
|
|
181
|
+
export { wasender } from './addon/chat-controller/whatsapp/wasender/@wasender.js';
|
|
182
|
+
export { WasenderChannel } from './addon/chat-controller/whatsapp/wasender/WasenderChannel.js';
|
|
183
|
+
export { WasenderChannelConfig } from './addon/chat-controller/whatsapp/wasender/WasenderChannelConfig.js';
|
|
184
|
+
export { WasenderReceiver } from './addon/chat-controller/whatsapp/wasender/WasenderReceiver.js';
|
|
185
|
+
export { WasenderSender } from './addon/chat-controller/whatsapp/wasender/WasenderSender.js';
|
|
186
|
+
export { WasenderWebhookController } from './addon/chat-controller/whatsapp/wasender/WasenderWebhookController.js';
|
|
187
|
+
export { extractNumberFromWasenderMessageKey } from './addon/chat-controller/whatsapp/wasender/extractNumberFromWasenderKey.js';
|
|
188
|
+
export { wasenderChannelName } from './addon/chat-controller/whatsapp/wasender/WasenderChannelName.js';
|
|
189
|
+
export { WhatsAppSender } from './addon/chat-controller/whatsapp/WhatsAppSender.js';
|
|
190
|
+
export { InMemoryLockKey } from './addon/lock/InMemoryLockKey.js';
|
|
191
|
+
export { InMemoryLocker } from './addon/lock/InMemoryLocker.js';
|
|
186
192
|
export { HtmlModule } from './addon/mindset/html/HtmlModule.js';
|
|
187
193
|
export { Container } from './core/injection/Container.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wabot-dev/framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Framework for IA Chat Bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"fmt": "prettier --write .",
|
|
50
50
|
"fmt:check": "prettier --check .",
|
|
51
51
|
"types:check": "tsc --noEmit",
|
|
52
|
-
"elia:dev": "node --import @yucacodes/ts --import ./env.mjs ./test/elia/run.ts"
|
|
52
|
+
"elia:dev": "node --import @yucacodes/ts --import ./env.mjs ./test/elia/run.ts",
|
|
53
|
+
"elia:watch": "node --watch --import @yucacodes/ts --import ./env.mjs ./test/elia/run.ts",
|
|
54
|
+
"cmd:channel": "node --import @yucacodes/ts ./test/cmd.ts"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"@rollup/plugin-alias": "5.1.1",
|
|
@@ -57,10 +59,7 @@
|
|
|
57
59
|
"@rollup/plugin-json": "6.1.0",
|
|
58
60
|
"@rollup/plugin-node-resolve": "16.0.1",
|
|
59
61
|
"@rollup/plugin-typescript": "12.1.2",
|
|
60
|
-
"
|
|
61
|
-
"rollup": "^4.60.0",
|
|
62
|
-
"tsup": "^8.4.0",
|
|
63
|
-
"typescript": "^6.0.3"
|
|
62
|
+
"rollup": "^4.60.0"
|
|
64
63
|
},
|
|
65
64
|
"peerDependencies": {
|
|
66
65
|
"@anthropic-ai/sdk": "^0.60.0",
|
|
@@ -92,6 +91,9 @@
|
|
|
92
91
|
"tslib": "^2.8.1",
|
|
93
92
|
"tsyringe": "^4.9.1",
|
|
94
93
|
"uuid": "^14.0.0",
|
|
95
|
-
"wasenderapi": "^0.1.5"
|
|
94
|
+
"wasenderapi": "^0.1.5",
|
|
95
|
+
"tsup": "^8.4.0",
|
|
96
|
+
"typescript": "^6.0.3",
|
|
97
|
+
"prettier": "^3.5.3"
|
|
96
98
|
}
|
|
97
99
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { container } from '../../../core/injection/index.js';
|
|
2
|
-
import { WhatsAppByWasenderChannelConfig } from './WhatsAppByWasenderChannelConfig.js';
|
|
3
|
-
import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
4
|
-
import '../../../feature/chat-controller/ChatResolver.js';
|
|
5
|
-
import '../../../feature/chat-controller/runChatControllers.js';
|
|
6
|
-
import { WhatsAppByWasenderChannel } from './WhatsAppByWasenderChannel.js';
|
|
7
|
-
|
|
8
|
-
function whatsAppByWasender(config) {
|
|
9
|
-
return function (target, propertyKey) {
|
|
10
|
-
const store = container.resolve(ControllerMetadataStore);
|
|
11
|
-
store.saveChannelMetadata({
|
|
12
|
-
channelConstructor: WhatsAppByWasenderChannel,
|
|
13
|
-
functionName: propertyKey.toString(),
|
|
14
|
-
controllerConstructor: target.constructor,
|
|
15
|
-
channelConfig: new WhatsAppByWasenderChannelConfig(config ?? {}),
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { whatsAppByWasender };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { container } from '../../../core/injection/index.js';
|
|
2
|
-
import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
|
|
3
|
-
import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
4
|
-
import '../../../feature/chat-controller/ChatResolver.js';
|
|
5
|
-
import '../../../feature/chat-controller/runChatControllers.js';
|
|
6
|
-
import { WhatsAppChannel } from './WhatsAppChannel.js';
|
|
7
|
-
|
|
8
|
-
function whatsApp(config) {
|
|
9
|
-
return function (target, propertyKey) {
|
|
10
|
-
const store = container.resolve(ControllerMetadataStore);
|
|
11
|
-
store.saveChannelMetadata({
|
|
12
|
-
channelConstructor: WhatsAppChannel,
|
|
13
|
-
functionName: propertyKey.toString(),
|
|
14
|
-
controllerConstructor: target.constructor,
|
|
15
|
-
channelConfig: new WhatsappChannelConfig(typeof config === 'string' ? config : config.number),
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { whatsApp };
|
|
@@ -1,49 +0,0 @@
|
|
|
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,48 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Pool } from 'pg';
|
|
3
|
-
import { WhatsApp } from './WhatsApp.js';
|
|
4
|
-
import { singleton } from '../../../core/injection/index.js';
|
|
5
|
-
import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
|
|
6
|
-
import '../../../feature/pg/PgLocker.js';
|
|
7
|
-
import 'debug';
|
|
8
|
-
import 'node:crypto';
|
|
9
|
-
import '../../../feature/pg/withPgClient.js';
|
|
10
|
-
import '../../../feature/pg/pgStorage.js';
|
|
11
|
-
import '../../../feature/pg/query/PgJsonRepository.js';
|
|
12
|
-
import '../../../feature/pg/query/PgRepositoryMetadataStore.js';
|
|
13
|
-
|
|
14
|
-
let PgWhatsAppRepository = class PgWhatsAppRepository extends PgCrudRepository {
|
|
15
|
-
constructor(pool) {
|
|
16
|
-
super(pool, {
|
|
17
|
-
table: 'whatsapp',
|
|
18
|
-
constructor: WhatsApp,
|
|
19
|
-
schema: 'wabot',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async findBySlug(slug) {
|
|
23
|
-
const sql = `
|
|
24
|
-
SELECT ${this.columns}
|
|
25
|
-
FROM ${this.table}
|
|
26
|
-
WHERE data @> $1
|
|
27
|
-
LIMIT 1
|
|
28
|
-
`;
|
|
29
|
-
const items = await this.query(sql, [JSON.stringify({ slug })]);
|
|
30
|
-
return items.at(0) ?? null;
|
|
31
|
-
}
|
|
32
|
-
async findByBusinessNumber(number) {
|
|
33
|
-
const sql = `
|
|
34
|
-
SELECT ${this.columns}
|
|
35
|
-
FROM ${this.table}
|
|
36
|
-
WHERE data->'businessNumbers' @> $1
|
|
37
|
-
LIMIT 1
|
|
38
|
-
`;
|
|
39
|
-
const items = await this.query(sql, [JSON.stringify([{ number }])]);
|
|
40
|
-
return items.at(0) ?? null;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
PgWhatsAppRepository = __decorate([
|
|
44
|
-
singleton(),
|
|
45
|
-
__metadata("design:paramtypes", [Pool])
|
|
46
|
-
], PgWhatsAppRepository);
|
|
47
|
-
|
|
48
|
-
export { PgWhatsAppRepository };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Entity } from '../../../core/entity/Entity.js';
|
|
2
|
-
|
|
3
|
-
class WhatsApp extends Entity {
|
|
4
|
-
getVerifyToken() {
|
|
5
|
-
return this.data.verifyToken;
|
|
6
|
-
}
|
|
7
|
-
getSlug() {
|
|
8
|
-
return this.data.slug;
|
|
9
|
-
}
|
|
10
|
-
getBusinessAccount() {
|
|
11
|
-
return this.data.businessAccount;
|
|
12
|
-
}
|
|
13
|
-
getAppSecret() {
|
|
14
|
-
return this.data.appSecret;
|
|
15
|
-
}
|
|
16
|
-
getBusinessNumbers() {
|
|
17
|
-
return this.data.businessNumbers;
|
|
18
|
-
}
|
|
19
|
-
getAccessToken() {
|
|
20
|
-
return this.data.accessToken;
|
|
21
|
-
}
|
|
22
|
-
hasBusinessNumber(number) {
|
|
23
|
-
return this.data.businessNumbers.some((x) => x.number === number);
|
|
24
|
-
}
|
|
25
|
-
getBussinessNumber(number) {
|
|
26
|
-
return this.data.businessNumbers.find((x) => x.number === number) ?? null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { WhatsApp };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { injectable } from '../../../core/injection/index.js';
|
|
3
|
-
import { Logger } from '../../../core/logger/Logger.js';
|
|
4
|
-
import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
|
|
5
|
-
import { WhatsAppReceiver } from './WhatsAppReceiver.js';
|
|
6
|
-
import { WhatsAppSender } from './WhatsAppSender.js';
|
|
7
|
-
import { whatsAppChannelName } from './whatsAppChannelName.js';
|
|
8
|
-
|
|
9
|
-
let WhatsAppChannel = class WhatsAppChannel {
|
|
10
|
-
config;
|
|
11
|
-
sender;
|
|
12
|
-
receiver;
|
|
13
|
-
static channelName = whatsAppChannelName;
|
|
14
|
-
logger = new Logger('wabot:whatsapp-channel');
|
|
15
|
-
constructor(config, sender, receiver) {
|
|
16
|
-
this.config = config;
|
|
17
|
-
this.sender = sender;
|
|
18
|
-
this.receiver = receiver;
|
|
19
|
-
}
|
|
20
|
-
listen(callback) {
|
|
21
|
-
this.receiver.listenMessage({
|
|
22
|
-
to: this.config.number,
|
|
23
|
-
listener: async (message) => {
|
|
24
|
-
try {
|
|
25
|
-
await callback({
|
|
26
|
-
channel: whatsAppChannelName,
|
|
27
|
-
chatConnection: message.chatConnection,
|
|
28
|
-
message: message.message,
|
|
29
|
-
reply: async (replyMessage) => {
|
|
30
|
-
await this.sender.sendWhatsApp({
|
|
31
|
-
from: this.config.number,
|
|
32
|
-
to: message.chatConnection.id,
|
|
33
|
-
message: replyMessage,
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
this.logger.error('Failed to handle WhatsApp message', err);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
connect() {
|
|
45
|
-
this.receiver.connect();
|
|
46
|
-
}
|
|
47
|
-
disconnect() {
|
|
48
|
-
this.receiver.disconnect();
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
WhatsAppChannel = __decorate([
|
|
52
|
-
injectable(),
|
|
53
|
-
__metadata("design:paramtypes", [WhatsappChannelConfig,
|
|
54
|
-
WhatsAppSender,
|
|
55
|
-
WhatsAppReceiver])
|
|
56
|
-
], WhatsAppChannel);
|
|
57
|
-
|
|
58
|
-
export { WhatsAppChannel };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
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-controller/runChatControllers.js';
|
|
8
|
-
import '../../../../feature/chat-bot/ChatAdapterRegistry.js';
|
|
9
|
-
import '../../../../feature/chat-bot/ChatBot.js';
|
|
10
|
-
import '../../../../feature/chat-bot/ChatOperator.js';
|
|
11
|
-
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
12
|
-
import '../../../../feature/chat-bot/UnionChatAdapter.js';
|
|
13
|
-
import '../../../../feature/chat-bot/metadata/ChatAdapterMetadataStore.js';
|
|
14
|
-
import 'uuid';
|
|
15
|
-
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
16
|
-
import '../../../../core/error/setupErrorHandlers.js';
|
|
17
|
-
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
18
|
-
|
|
19
|
-
let WhatsAppSenderByCloudApi = class WhatsAppSenderByCloudApi extends WhatsAppSender {
|
|
20
|
-
logger = new Logger('wabot:whatsapp-sender-by-cloud-api');
|
|
21
|
-
constructor(chatRepository, chatResolver, whatsAppRepository) {
|
|
22
|
-
super(chatRepository, chatResolver, whatsAppRepository);
|
|
23
|
-
}
|
|
24
|
-
async sendWhatsApp(request, options) {
|
|
25
|
-
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
26
|
-
if (!whatsApp) {
|
|
27
|
-
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
28
|
-
}
|
|
29
|
-
const businessNumber = whatsApp.getBussinessNumber(request.from);
|
|
30
|
-
const url = `https://graph.facebook.com/v23.0/${businessNumber.id}/messages`;
|
|
31
|
-
const payload = {
|
|
32
|
-
messaging_product: 'whatsapp',
|
|
33
|
-
recipient_type: 'individual',
|
|
34
|
-
to: request.to,
|
|
35
|
-
type: 'text',
|
|
36
|
-
text: {
|
|
37
|
-
preview_url: false,
|
|
38
|
-
body: request.message.text,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
const response = await fetch(url, {
|
|
42
|
-
method: 'POST',
|
|
43
|
-
headers: {
|
|
44
|
-
Authorization: `Bearer ${whatsApp.getAccessToken()}`,
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
},
|
|
47
|
-
body: JSON.stringify(payload),
|
|
48
|
-
});
|
|
49
|
-
const data = await response.json();
|
|
50
|
-
if (!response.ok) {
|
|
51
|
-
throw new Error(JSON.stringify(data));
|
|
52
|
-
}
|
|
53
|
-
if (options?.writeChatMemory) {
|
|
54
|
-
await this.writePrivateChatMemory(request.message, request.to);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async sendWhatsAppTemplate(request, options) {
|
|
58
|
-
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
59
|
-
if (!whatsApp) {
|
|
60
|
-
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
61
|
-
}
|
|
62
|
-
const businessNumber = whatsApp.getBussinessNumber(request.from);
|
|
63
|
-
const payload = {
|
|
64
|
-
messaging_product: 'whatsapp',
|
|
65
|
-
recipient_type: 'individual',
|
|
66
|
-
to: request.to,
|
|
67
|
-
type: 'template',
|
|
68
|
-
template: {
|
|
69
|
-
name: request.templateMessage.templateName,
|
|
70
|
-
language: {
|
|
71
|
-
code: request.templateMessage.languageCode,
|
|
72
|
-
},
|
|
73
|
-
components: [
|
|
74
|
-
{
|
|
75
|
-
type: 'body',
|
|
76
|
-
parameters: request.templateMessage.parameters,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
const response = await fetch(`https://graph.facebook.com/v23.0/${businessNumber.id}/messages`, {
|
|
82
|
-
method: 'POST',
|
|
83
|
-
headers: {
|
|
84
|
-
Authorization: `Bearer ${whatsApp.getAccessToken()}`,
|
|
85
|
-
'Content-Type': 'application/json',
|
|
86
|
-
},
|
|
87
|
-
body: JSON.stringify(payload),
|
|
88
|
-
});
|
|
89
|
-
const data = await response.json();
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
throw new Error(JSON.stringify(data));
|
|
92
|
-
}
|
|
93
|
-
if (options?.writeChatMemory) {
|
|
94
|
-
const message = await this.mapTemplateToChatMessage(request);
|
|
95
|
-
await this.writePrivateChatMemory(message, request.to);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async getWhatsAppTemplate(request) {
|
|
99
|
-
const whatsApp = await this.whatsAppRepository.findByBusinessNumber(request.from);
|
|
100
|
-
if (!whatsApp) {
|
|
101
|
-
throw new Error(`not found WhatsApp with bussiness number '${request.from}'`);
|
|
102
|
-
}
|
|
103
|
-
const businessAccount = whatsApp.getBusinessAccount();
|
|
104
|
-
try {
|
|
105
|
-
// Make API call to WhatsApp Cloud API to get templates
|
|
106
|
-
const response = await fetch(`https://graph.facebook.com/v23.0/${businessAccount.id}/message_templates?name=${request.templateName}&language=${request.languageCode}&limit=1`, {
|
|
107
|
-
method: 'GET',
|
|
108
|
-
headers: {
|
|
109
|
-
Authorization: `Bearer ${whatsApp.getAccessToken()}`,
|
|
110
|
-
'Content-Type': 'application/json',
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
const data = (await response.json());
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
throw new Error(JSON.stringify(data));
|
|
116
|
-
}
|
|
117
|
-
const template = data.data[0] ?? null;
|
|
118
|
-
return template;
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
this.logger.error('Failed to fetch WhatsApp template', error);
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
WhatsAppSenderByCloudApi = __decorate([
|
|
127
|
-
singleton(),
|
|
128
|
-
__metadata("design:paramtypes", [ChatRepository,
|
|
129
|
-
ChatResolver,
|
|
130
|
-
WhatsAppRepository])
|
|
131
|
-
], WhatsAppSenderByCloudApi);
|
|
132
|
-
|
|
133
|
-
export { WhatsAppSenderByCloudApi };
|
|
@@ -1,5 +0,0 @@
|
|
|
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 };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { WhatsAppReceiver } from '../WhatsAppReceiver.js';
|
|
3
|
-
import { whatsAppChannelName } from '../whatsAppChannelName.js';
|
|
4
|
-
import { injectable } from '../../../../core/injection/index.js';
|
|
5
|
-
import { Logger } from '../../../../core/logger/Logger.js';
|
|
6
|
-
import { WHATSAPP_MESSAGE_EVENT } from './WhatsAppProxyContracts.js';
|
|
7
|
-
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
8
|
-
|
|
9
|
-
let WhatsAppReceiverByWabotProxy = class WhatsAppReceiverByWabotProxy extends WhatsAppReceiver {
|
|
10
|
-
connection;
|
|
11
|
-
loger = new Logger('wabot:whats-app-receiver-by-wabot-proxy');
|
|
12
|
-
constructor(connection) {
|
|
13
|
-
super();
|
|
14
|
-
this.connection = connection;
|
|
15
|
-
}
|
|
16
|
-
async connect() {
|
|
17
|
-
// Nothing
|
|
18
|
-
}
|
|
19
|
-
listenMessage(request) {
|
|
20
|
-
this.connection.getSocket().then(async (socket) => {
|
|
21
|
-
const req = {
|
|
22
|
-
event: 'listenMessage',
|
|
23
|
-
data: {
|
|
24
|
-
to: request.to,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
const response = await socket.emitWithAck(req.event, req.data);
|
|
28
|
-
if (response && typeof response == 'object' && response['error']) {
|
|
29
|
-
this.loger.error(response.error);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
else if (!response ||
|
|
33
|
-
typeof response !== 'object' ||
|
|
34
|
-
!Array.isArray(response.from) ||
|
|
35
|
-
typeof response.to !== 'string') {
|
|
36
|
-
this.loger.error('unknown response');
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.loger.trace(`succes add whats-app proxy listener for messages from [${response.from.join(',')}] to ${response.to}`);
|
|
40
|
-
socket.on(WHATSAPP_MESSAGE_EVENT, (data, callback) => {
|
|
41
|
-
if (data.to !== request.to) {
|
|
42
|
-
throw new Error(`expecting message to '${request.to}' but received to='${data.to}'`);
|
|
43
|
-
}
|
|
44
|
-
callback({ success: true });
|
|
45
|
-
this.loger.trace(`success receive message from '${data.from}' to '${data.to}'`);
|
|
46
|
-
request.listener({
|
|
47
|
-
chatConnection: {
|
|
48
|
-
chatType: 'PRIVATE',
|
|
49
|
-
channelName: whatsAppChannelName,
|
|
50
|
-
id: data.from,
|
|
51
|
-
},
|
|
52
|
-
message: {
|
|
53
|
-
text: data.content.text,
|
|
54
|
-
senderName: data.senderName,
|
|
55
|
-
senderId: data.from,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
WhatsAppReceiverByWabotProxy = __decorate([
|
|
63
|
-
injectable(),
|
|
64
|
-
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection])
|
|
65
|
-
], WhatsAppReceiverByWabotProxy);
|
|
66
|
-
|
|
67
|
-
export { WhatsAppReceiverByWabotProxy };
|