@adatechnology/meta-whatsapp-module 0.3.0 → 0.3.1
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 +16 -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 +17 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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.
|