@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.d.cts CHANGED
@@ -1629,7 +1629,7 @@ declare class SessionRepository {
1629
1629
  setFlowPosition(companyId: string, whatsappNumber: string, flowKey: string | null, currentNodeId: string | null): Promise<void>;
1630
1630
  touchInbound(companyId: string, whatsappNumber: string): Promise<void>;
1631
1631
  hoursSinceLastInbound(companyId: string, whatsappNumber: string): Promise<number | undefined>;
1632
- setMode(companyId: string, whatsappNumber: string, mode: SessionMode, assignedUserId?: string | null): Promise<void>;
1632
+ setMode(companyId: string, whatsappNumber: string, mode: SessionMode, assignedUserId?: string | null, clearHumanRequest?: boolean): Promise<void>;
1633
1633
  takeover(companyId: string, whatsappNumber: string, agentUserId: string): Promise<void>;
1634
1634
  release(companyId: string, whatsappNumber: string): Promise<void>;
1635
1635
  /**
package/dist/index.d.ts CHANGED
@@ -1629,7 +1629,7 @@ declare class SessionRepository {
1629
1629
  setFlowPosition(companyId: string, whatsappNumber: string, flowKey: string | null, currentNodeId: string | null): Promise<void>;
1630
1630
  touchInbound(companyId: string, whatsappNumber: string): Promise<void>;
1631
1631
  hoursSinceLastInbound(companyId: string, whatsappNumber: string): Promise<number | undefined>;
1632
- setMode(companyId: string, whatsappNumber: string, mode: SessionMode, assignedUserId?: string | null): Promise<void>;
1632
+ setMode(companyId: string, whatsappNumber: string, mode: SessionMode, assignedUserId?: string | null, clearHumanRequest?: boolean): Promise<void>;
1633
1633
  takeover(companyId: string, whatsappNumber: string, agentUserId: string): Promise<void>;
1634
1634
  release(companyId: string, whatsappNumber: string): Promise<void>;
1635
1635
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // ../../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.40_@swc+helpers@0.5.23__jiti@2.7.0_postcss@8.5.26_tsx@4.23.1_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/esm_shims.js
4
+ // ../../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.16.2_@swc+helpers@0.5.23__jiti@2.7.0_postcss@8.5.28_tsx@4.23.13_typescript@5.9.3_yaml@2.9.1/node_modules/tsup/assets/esm_shims.js
5
5
  import path from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  var getFilename = /* @__PURE__ */ __name(() => fileURLToPath(import.meta.url), "getFilename");
@@ -416,20 +416,33 @@ var SessionRepository = class {
416
416
  if (!session?.lastInboundAt) return void 0;
417
417
  return (Date.now() - session.lastInboundAt.getTime()) / (1e3 * 60 * 60);
418
418
  }
419
- async setMode(companyId, whatsappNumber, mode, assignedUserId) {
419
+ // `clearHumanRequest` é opt-in: quem chama `setMode` direto para outros fins (ex.: trocar de
420
+ // atendente sem mexer na fila) continua sem afetar `humanRequestedAt`. Só `takeover`/`release`
421
+ // pedem a limpeza, porque só eles representam "o pedido de atendimento foi resolvido".
422
+ async setMode(companyId, whatsappNumber, mode, assignedUserId, clearHumanRequest = false) {
420
423
  await this.db.update(sessions).set({
421
424
  mode,
422
425
  assignedUserId: assignedUserId ?? null,
426
+ ...clearHumanRequest ? {
427
+ humanRequestedAt: null
428
+ } : {},
423
429
  updatedAt: sql2`now()`
424
430
  }).where(and(eq(sessions.companyId, companyId), eq(sessions.whatsappNumber, whatsappNumber)));
425
431
  }
426
432
  // T3.3 — takeover: atendente assume a conversa, tirando-a do modo bot.
433
+ //
434
+ // Limpa `humanRequestedAt`: sem isso a conversa nunca sai da fila `waitingHuman` da inbox,
435
+ // mesmo depois de atendida — o filtro é só `humanRequestedAt is not null` (ver
436
+ // `listByContextFilters`), então o campo tem que voltar a null quando o pedido é resolvido.
427
437
  async takeover(companyId, whatsappNumber, agentUserId) {
428
- await this.setMode(companyId, whatsappNumber, "human", agentUserId);
438
+ await this.setMode(companyId, whatsappNumber, "human", agentUserId, true);
429
439
  }
430
440
  // T3.3 — release: devolve a conversa ao bot.
441
+ //
442
+ // Também limpa `humanRequestedAt` pelo mesmo motivo do takeover: se o cliente pedir atendimento
443
+ // de novo depois, `requestHuman` grava um novo timestamp normalmente.
431
444
  async release(companyId, whatsappNumber) {
432
- await this.setMode(companyId, whatsappNumber, "bot", null);
445
+ await this.setMode(companyId, whatsappNumber, "bot", null, true);
433
446
  }
434
447
  /**
435
448
  * Apaga a sessão; a cascata das FKs leva mensagens e documentos.
@@ -2537,6 +2550,10 @@ function extractContent(message) {
2537
2550
  const items = message.order.product_items.reduce((sum, item) => sum + item.quantity, 0);
2538
2551
  return `Pedido: ${items} item(ns)`;
2539
2552
  }
2553
+ if (message.location) {
2554
+ const label = message.location.name ?? message.location.address;
2555
+ return label ? `\u{1F4CD} Localiza\xE7\xE3o: ${label}` : "\u{1F4CD} Localiza\xE7\xE3o";
2556
+ }
2540
2557
  return message.image?.caption ?? message.document?.caption ?? null;
2541
2558
  }
2542
2559
  __name(extractContent, "extractContent");
@@ -2549,6 +2566,7 @@ function extractPayload(message) {
2549
2566
  if (message.video) payload["video"] = message.video;
2550
2567
  if (message.document) payload["document"] = message.document;
2551
2568
  if (message.sticker) payload["sticker"] = message.sticker;
2569
+ if (message.location) payload["location"] = message.location;
2552
2570
  if (message.context?.referred_product) payload["referredProduct"] = message.context.referred_product;
2553
2571
  return Object.keys(payload).length > 0 ? payload : null;
2554
2572
  }