@adatechnology/meta-whatsapp-module 0.6.0 → 0.8.0
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/index.cjs +102 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +379 -530
- package/dist/index.d.ts +379 -530
- package/dist/index.js +103 -11
- package/dist/index.js.map +1 -1
- package/dist/migrations/20260725195853_freezing_switch/snapshot.json +555 -0
- package/dist/migrations/20260725210958_military_leper_queen/snapshot.json +742 -0
- package/dist/migrations/20260725214800_illegal_black_tarantula/snapshot.json +810 -0
- package/dist/migrations/20260725234507_normal_viper/snapshot.json +930 -0
- package/dist/migrations/20260731041538_flow_media_meta_ids/snapshot.json +1649 -0
- package/package.json +6 -6
- package/dist/migrations/meta/_journal.json +0 -76
- /package/dist/migrations/{0000_freezing_switch.sql → 20260725195853_freezing_switch/migration.sql} +0 -0
- /package/dist/migrations/{0001_military_leper_queen.sql → 20260725210958_military_leper_queen/migration.sql} +0 -0
- /package/dist/migrations/{0002_illegal_black_tarantula.sql → 20260725214800_illegal_black_tarantula/migration.sql} +0 -0
- /package/dist/migrations/{0003_normal_viper.sql → 20260725234507_normal_viper/migration.sql} +0 -0
- /package/dist/migrations/{0004_widen_message_type.sql → 20260725234508_widen_message_type/migration.sql} +0 -0
- /package/dist/migrations/{0005_message_moderation.sql → 20260727182141_message_moderation/migration.sql} +0 -0
- /package/dist/migrations/{0006_conversation_documents.sql → 20260727215549_conversation_documents/migration.sql} +0 -0
- /package/dist/migrations/{0007_flow_media.sql → 20260728220000_flow_media/migration.sql} +0 -0
- /package/dist/migrations/{0008_message_transcription.sql → 20260731041536_message_transcription/migration.sql} +0 -0
- /package/dist/migrations/{0009_settings_transcription_policy.sql → 20260731041537_settings_transcription_policy/migration.sql} +0 -0
- /package/dist/migrations/{0010_flow_media_meta_ids.sql → 20260731041538_flow_media_meta_ids/migration.sql} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
CountInboundLocationsUseCase: () => CountInboundLocationsUseCase,
|
|
24
25
|
CreateFlowGraphUseCase: () => CreateFlowGraphUseCase,
|
|
25
26
|
DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS: () => DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS,
|
|
26
27
|
DeleteConversationUseCase: () => DeleteConversationUseCase,
|
|
@@ -34,6 +35,7 @@ __export(index_exports, {
|
|
|
34
35
|
FlowMediaRepository: () => FlowMediaRepository,
|
|
35
36
|
GetFlowGraphUseCase: () => GetFlowGraphUseCase,
|
|
36
37
|
GetLiveFlowPositionsUseCase: () => GetLiveFlowPositionsUseCase,
|
|
38
|
+
INBOUND_LOCATION_CONTENT: () => INBOUND_LOCATION_CONTENT,
|
|
37
39
|
InboundEffectsDispatcher: () => InboundEffectsDispatcher,
|
|
38
40
|
IngestInboundMediaUseCase: () => IngestInboundMediaUseCase,
|
|
39
41
|
InvalidFlowGraphError: () => InvalidFlowGraphError,
|
|
@@ -51,6 +53,7 @@ __export(index_exports, {
|
|
|
51
53
|
ProcessInboundDispatchUseCase: () => ProcessInboundDispatchUseCase,
|
|
52
54
|
PurgeExpiredDocumentsUseCase: () => PurgeExpiredDocumentsUseCase,
|
|
53
55
|
ReceiveWebhookUseCase: () => ReceiveWebhookUseCase,
|
|
56
|
+
RedactInboundLocationsUseCase: () => RedactInboundLocationsUseCase,
|
|
54
57
|
ReleaseConversationUseCase: () => ReleaseConversationUseCase,
|
|
55
58
|
SaveFlowGraphUseCase: () => SaveFlowGraphUseCase,
|
|
56
59
|
SendMessageUseCase: () => SendMessageUseCase,
|
|
@@ -615,6 +618,11 @@ var SessionRepository = class {
|
|
|
615
618
|
|
|
616
619
|
// src/repositories/MessageRepository.ts
|
|
617
620
|
var import_drizzle_orm3 = require("drizzle-orm");
|
|
621
|
+
|
|
622
|
+
// src/inboundLocation.constant.ts
|
|
623
|
+
var INBOUND_LOCATION_CONTENT = "\u{1F4CD} Localiza\xE7\xE3o";
|
|
624
|
+
|
|
625
|
+
// src/repositories/MessageRepository.ts
|
|
618
626
|
var DEFAULT_LIMIT2 = 50;
|
|
619
627
|
var MessageRepository = class {
|
|
620
628
|
static {
|
|
@@ -688,6 +696,49 @@ var MessageRepository = class {
|
|
|
688
696
|
return updated;
|
|
689
697
|
}
|
|
690
698
|
/**
|
|
699
|
+
* Linhas de entrada com `payload.location` que a redação alcança, mais as localizações com
|
|
700
|
+
* `payload` escalar string (gravação antiga do `bun-sql` com drizzle 0.x), nas quais `payload ?
|
|
701
|
+
* 'location'` dá falso e que, por isso, a redação não toca.
|
|
702
|
+
*/
|
|
703
|
+
async countInboundLocations(params) {
|
|
704
|
+
const inboundScope = (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(messages.companyId, params.companyId), (0, import_drizzle_orm3.eq)(messages.direction, "inbound"), (0, import_drizzle_orm3.lt)(messages.createdAt, params.receivedBefore));
|
|
705
|
+
const [reachable] = await this.db.select({
|
|
706
|
+
total: (0, import_drizzle_orm3.count)()
|
|
707
|
+
}).from(messages).where((0, import_drizzle_orm3.and)(inboundScope, this.hasRedactableLocation()));
|
|
708
|
+
const [unreachable] = await this.db.select({
|
|
709
|
+
total: (0, import_drizzle_orm3.count)()
|
|
710
|
+
}).from(messages).where((0, import_drizzle_orm3.and)(inboundScope, (0, import_drizzle_orm3.eq)(messages.type, "location"), import_drizzle_orm3.sql`jsonb_typeof(${messages.payload}) = 'string'`));
|
|
711
|
+
return {
|
|
712
|
+
counted: reachable?.total ?? 0,
|
|
713
|
+
unreachable: unreachable?.total ?? 0
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Redige UMA passada: tira `location` de `payload` (NULL quando não sobra chave) e põe o rótulo
|
|
718
|
+
* neutro em `content` das linhas de tipo `location`. Sem `ORDER BY`: o índice por empresa não serve
|
|
719
|
+
* à ordenação e a passada não precisa dela. `FOR UPDATE SKIP LOCKED` evita brigar com o webhook; o
|
|
720
|
+
* `company_id` é repetido fora da subconsulta. Nunca devolve nem registra os ids das linhas.
|
|
721
|
+
*/
|
|
722
|
+
async redactInboundLocations(params) {
|
|
723
|
+
const batch = this.db.$with("batch").as(this.db.select({
|
|
724
|
+
id: messages.id
|
|
725
|
+
}).from(messages).where((0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(messages.companyId, params.companyId), (0, import_drizzle_orm3.eq)(messages.direction, "inbound"), (0, import_drizzle_orm3.lt)(messages.createdAt, params.receivedBefore), this.hasRedactableLocation())).limit(params.batchSize).for("update", {
|
|
726
|
+
skipLocked: true
|
|
727
|
+
}));
|
|
728
|
+
const updated = await this.db.with(batch).update(messages).set({
|
|
729
|
+
payload: import_drizzle_orm3.sql`nullif(${messages.payload} - 'location', '{}'::jsonb)`,
|
|
730
|
+
content: import_drizzle_orm3.sql`case when ${messages.type} = 'location' then ${INBOUND_LOCATION_CONTENT} else ${messages.content} end`
|
|
731
|
+
}).from(batch).where((0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(messages.id, batch.id), (0, import_drizzle_orm3.eq)(messages.companyId, params.companyId))).returning({
|
|
732
|
+
id: messages.id
|
|
733
|
+
});
|
|
734
|
+
return {
|
|
735
|
+
redacted: updated.length
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
hasRedactableLocation() {
|
|
739
|
+
return import_drizzle_orm3.sql`jsonb_typeof(${messages.payload}) = 'object' and ${messages.payload} ? 'location'`;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
691
742
|
* Grava a transcrição endereçando pelo id da Meta, para quem só tem esse.
|
|
692
743
|
*
|
|
693
744
|
* Serve ao caso em que a transcrição acontece no próprio webhook — o grafo precisa do texto para
|
|
@@ -1427,6 +1478,36 @@ var PurgeExpiredDocumentsUseCase = class {
|
|
|
1427
1478
|
}
|
|
1428
1479
|
};
|
|
1429
1480
|
|
|
1481
|
+
// src/use-cases/RedactInboundLocations.use-case.ts
|
|
1482
|
+
var DEFAULT_BATCH_SIZE2 = 500;
|
|
1483
|
+
var CountInboundLocationsUseCase = class {
|
|
1484
|
+
static {
|
|
1485
|
+
__name(this, "CountInboundLocationsUseCase");
|
|
1486
|
+
}
|
|
1487
|
+
messageRepository;
|
|
1488
|
+
constructor(messageRepository) {
|
|
1489
|
+
this.messageRepository = messageRepository;
|
|
1490
|
+
}
|
|
1491
|
+
async execute(params) {
|
|
1492
|
+
return this.messageRepository.countInboundLocations(params);
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
var RedactInboundLocationsUseCase = class {
|
|
1496
|
+
static {
|
|
1497
|
+
__name(this, "RedactInboundLocationsUseCase");
|
|
1498
|
+
}
|
|
1499
|
+
messageRepository;
|
|
1500
|
+
constructor(messageRepository) {
|
|
1501
|
+
this.messageRepository = messageRepository;
|
|
1502
|
+
}
|
|
1503
|
+
async execute(params) {
|
|
1504
|
+
return this.messageRepository.redactInboundLocations({
|
|
1505
|
+
...params,
|
|
1506
|
+
batchSize: params.batchSize ?? DEFAULT_BATCH_SIZE2
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
|
|
1430
1511
|
// src/repositories/DocumentRepository.ts
|
|
1431
1512
|
var import_drizzle_orm6 = require("drizzle-orm");
|
|
1432
1513
|
var DEFAULT_LIMIT3 = 50;
|
|
@@ -2661,7 +2742,10 @@ var EMPTY_RESULT = {
|
|
|
2661
2742
|
accountEventsProcessed: 0,
|
|
2662
2743
|
unhandledEvents: 0
|
|
2663
2744
|
};
|
|
2664
|
-
|
|
2745
|
+
var DEFAULT_EXTRACTION_OPTIONS = {
|
|
2746
|
+
isLocationRedacted: false
|
|
2747
|
+
};
|
|
2748
|
+
function extractContent(message, { isLocationRedacted } = DEFAULT_EXTRACTION_OPTIONS) {
|
|
2665
2749
|
if (message.text?.body) return message.text.body;
|
|
2666
2750
|
const interactive = message.interactive;
|
|
2667
2751
|
if (interactive?.button_reply) return interactive.button_reply.title || interactive.button_reply.id;
|
|
@@ -2671,13 +2755,14 @@ function extractContent(message) {
|
|
|
2671
2755
|
return `Pedido: ${items} item(ns)`;
|
|
2672
2756
|
}
|
|
2673
2757
|
if (message.location) {
|
|
2758
|
+
if (isLocationRedacted) return INBOUND_LOCATION_CONTENT;
|
|
2674
2759
|
const label = message.location.name ?? message.location.address;
|
|
2675
|
-
return label ? `\u{1F4CD} Localiza\xE7\xE3o: ${label}` :
|
|
2760
|
+
return label ? `\u{1F4CD} Localiza\xE7\xE3o: ${label}` : INBOUND_LOCATION_CONTENT;
|
|
2676
2761
|
}
|
|
2677
2762
|
return message.image?.caption ?? message.document?.caption ?? null;
|
|
2678
2763
|
}
|
|
2679
2764
|
__name(extractContent, "extractContent");
|
|
2680
|
-
function extractPayload(message) {
|
|
2765
|
+
function extractPayload(message, { isLocationRedacted } = DEFAULT_EXTRACTION_OPTIONS) {
|
|
2681
2766
|
const payload = {};
|
|
2682
2767
|
if (message.interactive) payload["interactive"] = message.interactive;
|
|
2683
2768
|
if (message.order) payload["order"] = message.order;
|
|
@@ -2686,7 +2771,7 @@ function extractPayload(message) {
|
|
|
2686
2771
|
if (message.video) payload["video"] = message.video;
|
|
2687
2772
|
if (message.document) payload["document"] = message.document;
|
|
2688
2773
|
if (message.sticker) payload["sticker"] = message.sticker;
|
|
2689
|
-
if (message.location) payload["location"] = message.location;
|
|
2774
|
+
if (message.location && !isLocationRedacted) payload["location"] = message.location;
|
|
2690
2775
|
if (message.context?.referred_product) payload["referredProduct"] = message.context.referred_product;
|
|
2691
2776
|
return Object.keys(payload).length > 0 ? payload : null;
|
|
2692
2777
|
}
|
|
@@ -2829,14 +2914,17 @@ var ReceiveWebhookUseCase = class {
|
|
|
2829
2914
|
return true;
|
|
2830
2915
|
}
|
|
2831
2916
|
async handleMessage(companyId, message, profileName) {
|
|
2917
|
+
const extractionOptions = {
|
|
2918
|
+
isLocationRedacted: this.params.redactInboundLocation ?? false
|
|
2919
|
+
};
|
|
2832
2920
|
const saved = await this.params.logMessage.execute({
|
|
2833
2921
|
companyId,
|
|
2834
2922
|
whatsappNumber: message.from,
|
|
2835
2923
|
direction: "inbound",
|
|
2836
2924
|
sender: "customer",
|
|
2837
2925
|
type: message.type,
|
|
2838
|
-
content: extractContent(message),
|
|
2839
|
-
payload: extractPayload(message),
|
|
2926
|
+
content: extractContent(message, extractionOptions),
|
|
2927
|
+
payload: extractPayload(message, extractionOptions),
|
|
2840
2928
|
waMessageId: message.id,
|
|
2841
2929
|
status: "received",
|
|
2842
2930
|
startState: this.params.startState
|
|
@@ -2995,7 +3083,8 @@ function createMetaWhatsAppModule(params) {
|
|
|
2995
3083
|
logMessage,
|
|
2996
3084
|
startState,
|
|
2997
3085
|
hooks,
|
|
2998
|
-
realtime: providers.realtime
|
|
3086
|
+
realtime: providers.realtime,
|
|
3087
|
+
redactInboundLocation: params.features?.redactInboundLocation ?? false
|
|
2999
3088
|
});
|
|
3000
3089
|
const flowInterpreter = flowEngineEnabled ? new FlowInterpreter() : void 0;
|
|
3001
3090
|
if (flowInterpreter && providers.objectStorage?.getObject) {
|
|
@@ -3076,6 +3165,9 @@ function createMetaWhatsAppModule(params) {
|
|
|
3076
3165
|
// órfãos, já que a lista de uploadId vive justamente nas linhas que ela derruba.
|
|
3077
3166
|
delete: new DeleteConversationUseCase(sessionRepository, documentRepository, providers.objectStorage),
|
|
3078
3167
|
purgeExpiredDocuments: new PurgeExpiredDocumentsUseCase(documentRepository, providers.objectStorage),
|
|
3168
|
+
// Legado de `features.redactInboundLocation`: conta e redige a coordenada já gravada, por empresa.
|
|
3169
|
+
countInboundLocations: new CountInboundLocationsUseCase(messageRepository),
|
|
3170
|
+
redactInboundLocations: new RedactInboundLocationsUseCase(messageRepository),
|
|
3079
3171
|
export: new ExportConversationUseCase(sessionRepository),
|
|
3080
3172
|
// undefined quando transcrição não foi injetada, ou quando o storage não sabe ler de volta.
|
|
3081
3173
|
// O painel consulta a ausência para decidir se desenha o botão "transcrever".
|
|
@@ -3220,6 +3312,7 @@ async function redeemSseTicket(store, ticket) {
|
|
|
3220
3312
|
__name(redeemSseTicket, "redeemSseTicket");
|
|
3221
3313
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3222
3314
|
0 && (module.exports = {
|
|
3315
|
+
CountInboundLocationsUseCase,
|
|
3223
3316
|
CreateFlowGraphUseCase,
|
|
3224
3317
|
DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS,
|
|
3225
3318
|
DeleteConversationUseCase,
|
|
@@ -3233,6 +3326,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
3233
3326
|
FlowMediaRepository,
|
|
3234
3327
|
GetFlowGraphUseCase,
|
|
3235
3328
|
GetLiveFlowPositionsUseCase,
|
|
3329
|
+
INBOUND_LOCATION_CONTENT,
|
|
3236
3330
|
InboundEffectsDispatcher,
|
|
3237
3331
|
IngestInboundMediaUseCase,
|
|
3238
3332
|
InvalidFlowGraphError,
|
|
@@ -3250,6 +3344,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
3250
3344
|
ProcessInboundDispatchUseCase,
|
|
3251
3345
|
PurgeExpiredDocumentsUseCase,
|
|
3252
3346
|
ReceiveWebhookUseCase,
|
|
3347
|
+
RedactInboundLocationsUseCase,
|
|
3253
3348
|
ReleaseConversationUseCase,
|
|
3254
3349
|
SaveFlowGraphUseCase,
|
|
3255
3350
|
SendMessageUseCase,
|