@adatechnology/meta-whatsapp-module 0.3.0 → 0.4.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 +21 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -505,20 +505,33 @@ var SessionRepository = class {
|
|
|
505
505
|
if (!session?.lastInboundAt) return void 0;
|
|
506
506
|
return (Date.now() - session.lastInboundAt.getTime()) / (1e3 * 60 * 60);
|
|
507
507
|
}
|
|
508
|
-
|
|
508
|
+
// `clearHumanRequest` é opt-in: quem chama `setMode` direto para outros fins (ex.: trocar de
|
|
509
|
+
// atendente sem mexer na fila) continua sem afetar `humanRequestedAt`. Só `takeover`/`release`
|
|
510
|
+
// pedem a limpeza, porque só eles representam "o pedido de atendimento foi resolvido".
|
|
511
|
+
async setMode(companyId, whatsappNumber, mode, assignedUserId, clearHumanRequest = false) {
|
|
509
512
|
await this.db.update(sessions).set({
|
|
510
513
|
mode,
|
|
511
514
|
assignedUserId: assignedUserId ?? null,
|
|
515
|
+
...clearHumanRequest ? {
|
|
516
|
+
humanRequestedAt: null
|
|
517
|
+
} : {},
|
|
512
518
|
updatedAt: import_drizzle_orm2.sql`now()`
|
|
513
519
|
}).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(sessions.companyId, companyId), (0, import_drizzle_orm2.eq)(sessions.whatsappNumber, whatsappNumber)));
|
|
514
520
|
}
|
|
515
521
|
// T3.3 — takeover: atendente assume a conversa, tirando-a do modo bot.
|
|
522
|
+
//
|
|
523
|
+
// Limpa `humanRequestedAt`: sem isso a conversa nunca sai da fila `waitingHuman` da inbox,
|
|
524
|
+
// mesmo depois de atendida — o filtro é só `humanRequestedAt is not null` (ver
|
|
525
|
+
// `listByContextFilters`), então o campo tem que voltar a null quando o pedido é resolvido.
|
|
516
526
|
async takeover(companyId, whatsappNumber, agentUserId) {
|
|
517
|
-
await this.setMode(companyId, whatsappNumber, "human", agentUserId);
|
|
527
|
+
await this.setMode(companyId, whatsappNumber, "human", agentUserId, true);
|
|
518
528
|
}
|
|
519
529
|
// T3.3 — release: devolve a conversa ao bot.
|
|
530
|
+
//
|
|
531
|
+
// Também limpa `humanRequestedAt` pelo mesmo motivo do takeover: se o cliente pedir atendimento
|
|
532
|
+
// de novo depois, `requestHuman` grava um novo timestamp normalmente.
|
|
520
533
|
async release(companyId, whatsappNumber) {
|
|
521
|
-
await this.setMode(companyId, whatsappNumber, "bot", null);
|
|
534
|
+
await this.setMode(companyId, whatsappNumber, "bot", null, true);
|
|
522
535
|
}
|
|
523
536
|
/**
|
|
524
537
|
* Apaga a sessão; a cascata das FKs leva mensagens e documentos.
|
|
@@ -2626,6 +2639,10 @@ function extractContent(message) {
|
|
|
2626
2639
|
const items = message.order.product_items.reduce((sum, item) => sum + item.quantity, 0);
|
|
2627
2640
|
return `Pedido: ${items} item(ns)`;
|
|
2628
2641
|
}
|
|
2642
|
+
if (message.location) {
|
|
2643
|
+
const label = message.location.name ?? message.location.address;
|
|
2644
|
+
return label ? `\u{1F4CD} Localiza\xE7\xE3o: ${label}` : "\u{1F4CD} Localiza\xE7\xE3o";
|
|
2645
|
+
}
|
|
2629
2646
|
return message.image?.caption ?? message.document?.caption ?? null;
|
|
2630
2647
|
}
|
|
2631
2648
|
__name(extractContent, "extractContent");
|
|
@@ -2638,6 +2655,7 @@ function extractPayload(message) {
|
|
|
2638
2655
|
if (message.video) payload["video"] = message.video;
|
|
2639
2656
|
if (message.document) payload["document"] = message.document;
|
|
2640
2657
|
if (message.sticker) payload["sticker"] = message.sticker;
|
|
2658
|
+
if (message.location) payload["location"] = message.location;
|
|
2641
2659
|
if (message.context?.referred_product) payload["referredProduct"] = message.context.referred_product;
|
|
2642
2660
|
return Object.keys(payload).length > 0 ? payload : null;
|
|
2643
2661
|
}
|