@adatechnology/meta-whatsapp-module 0.8.1 → 0.9.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 CHANGED
@@ -23,6 +23,7 @@ var index_exports = {};
23
23
  __export(index_exports, {
24
24
  CountInboundLocationsUseCase: () => CountInboundLocationsUseCase,
25
25
  CreateFlowGraphUseCase: () => CreateFlowGraphUseCase,
26
+ DEFAULT_FALLBACK_LIST_LABEL: () => DEFAULT_FALLBACK_LIST_LABEL,
26
27
  DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS: () => DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS,
27
28
  DeleteConversationUseCase: () => DeleteConversationUseCase,
28
29
  DeleteFlowGraphUseCase: () => DeleteFlowGraphUseCase,
@@ -48,13 +49,14 @@ __export(index_exports, {
48
49
  META_WHATSAPP_MIGRATIONS_TABLE: () => META_WHATSAPP_MIGRATIONS_TABLE,
49
50
  MessageRepository: () => MessageRepository,
50
51
  OptimisticLockError: () => OptimisticLockError,
51
- PREVIEW_MEDIA_ID_PREFIX: () => import_meta_whatsapp_contracts8.PREVIEW_MEDIA_ID_PREFIX,
52
+ PREVIEW_MEDIA_ID_PREFIX: () => import_meta_whatsapp_contracts9.PREVIEW_MEDIA_ID_PREFIX,
52
53
  PRODUCT_LIST_LIMIT: () => PRODUCT_LIST_LIMIT,
53
54
  ProcessInboundDispatchUseCase: () => ProcessInboundDispatchUseCase,
54
55
  PurgeExpiredDocumentsUseCase: () => PurgeExpiredDocumentsUseCase,
55
56
  ReceiveWebhookUseCase: () => ReceiveWebhookUseCase,
56
57
  RedactInboundLocationsUseCase: () => RedactInboundLocationsUseCase,
57
58
  ReleaseConversationUseCase: () => ReleaseConversationUseCase,
59
+ RequestHumanConversationUseCase: () => RequestHumanConversationUseCase,
58
60
  SaveFlowGraphUseCase: () => SaveFlowGraphUseCase,
59
61
  SendMessageUseCase: () => SendMessageUseCase,
60
62
  SessionRepository: () => SessionRepository,
@@ -65,8 +67,8 @@ __export(index_exports, {
65
67
  TRANSCRIPTION_STATUS: () => TRANSCRIPTION_STATUS,
66
68
  TakeoverConversationUseCase: () => TakeoverConversationUseCase,
67
69
  TranscribeAudioUseCase: () => TranscribeAudioUseCase,
68
- WEBHOOK_CLAIM_TTL_SECONDS: () => import_meta_graph_core2.WEBHOOK_CLAIM_TTL_SECONDS,
69
- WEBHOOK_NONCE_TTL_SECONDS: () => import_meta_graph_core2.WEBHOOK_NONCE_TTL_SECONDS,
70
+ WEBHOOK_CLAIM_TTL_SECONDS: () => import_meta_graph_core3.WEBHOOK_CLAIM_TTL_SECONDS,
71
+ WEBHOOK_NONCE_TTL_SECONDS: () => import_meta_graph_core3.WEBHOOK_NONCE_TTL_SECONDS,
70
72
  WhatsAppChannelAdapter: () => WhatsAppChannelAdapter,
71
73
  buildInboundJobId: () => buildInboundJobId,
72
74
  claimWebhookDelivery: () => claimWebhookDelivery,
@@ -88,11 +90,11 @@ __export(index_exports, {
88
90
  metaWhatsAppSchema: () => metaWhatsAppSchema,
89
91
  redeemSseTicket: () => redeemSseTicket,
90
92
  resolveFailureStatus: () => resolveFailureStatus,
91
- resolvePreviewUploadId: () => import_meta_whatsapp_contracts8.resolvePreviewUploadId,
93
+ resolvePreviewUploadId: () => import_meta_whatsapp_contracts9.resolvePreviewUploadId,
92
94
  runMetaWhatsAppMigrations: () => runMetaWhatsAppMigrations,
93
95
  sessions: () => sessions,
94
96
  settings: () => settings,
95
- toPreviewMediaId: () => import_meta_whatsapp_contracts8.toPreviewMediaId,
97
+ toPreviewMediaId: () => import_meta_whatsapp_contracts9.toPreviewMediaId,
96
98
  toSessionContract: () => toSessionContract,
97
99
  transcriptionRetryAfterSeconds: () => transcriptionRetryAfterSeconds,
98
100
  verifyWebhookChallenge: () => verifyWebhookChallenge,
@@ -102,7 +104,7 @@ module.exports = __toCommonJS(index_exports);
102
104
 
103
105
  // src/createMetaWhatsAppModule.ts
104
106
  var import_meta_whatsapp_provider = require("@adatechnology/meta-whatsapp-provider");
105
- var import_meta_whatsapp_contracts13 = require("@adatechnology/meta-whatsapp-contracts");
107
+ var import_meta_whatsapp_contracts14 = require("@adatechnology/meta-whatsapp-contracts");
106
108
 
107
109
  // src/repositories/SessionRepository.ts
108
110
  var import_drizzle_orm2 = require("drizzle-orm");
@@ -1104,6 +1106,7 @@ var LogMessageUseCase = class {
1104
1106
  // src/use-cases/SendMessage.use-case.ts
1105
1107
  var import_meta_whatsapp_contracts2 = require("@adatechnology/meta-whatsapp-contracts");
1106
1108
  var WHATSAPP_WINDOW_HOURS = 24;
1109
+ var DEFAULT_FALLBACK_LIST_LABEL = "Op\xE7\xF5es";
1107
1110
  var SendMessageUseCase = class {
1108
1111
  static {
1109
1112
  __name(this, "SendMessageUseCase");
@@ -1188,6 +1191,54 @@ var SendMessageUseCase = class {
1188
1191
  }
1189
1192
  return saved;
1190
1193
  }
1194
+ /**
1195
+ * Botões ou lista, pelo mesmo caminho do `sendText`: janela, envio, transcript (idempotente pelo
1196
+ * `waMessageId`). Os limites da Meta são conferidos ANTES de tudo — mensagem fora do teto a Graph
1197
+ * API recusa inteira, e o erro local (`InteractiveLimitExceededError`) diz qual campo corrigir.
1198
+ *
1199
+ * O transcript guarda `type: 'interactive'`, o corpo em `content` e a mensagem inteira (ids e
1200
+ * títulos das opções) em `payload.interactive`, para o histórico mostrar o que foi oferecido.
1201
+ */
1202
+ async sendInteractive(params) {
1203
+ (0, import_meta_whatsapp_contracts2.assertInteractiveWithinLimits)(params.interactive);
1204
+ await this.assertWithinWindow(params.companyId, params.whatsappNumber);
1205
+ const { externalMessageId } = await this.sendInteractiveThroughChannel(params);
1206
+ return this.logMessage.execute({
1207
+ companyId: params.companyId,
1208
+ whatsappNumber: params.whatsappNumber,
1209
+ direction: "outbound",
1210
+ sender: params.sender,
1211
+ agentUserId: params.agentUserId ?? null,
1212
+ type: "interactive",
1213
+ content: params.interactive.body,
1214
+ payload: {
1215
+ interactive: params.interactive
1216
+ },
1217
+ waMessageId: externalMessageId,
1218
+ status: "sent",
1219
+ startState: params.startState
1220
+ });
1221
+ }
1222
+ sendInteractiveThroughChannel(params) {
1223
+ const interactive = params.interactive;
1224
+ const to = params.whatsappNumber;
1225
+ if (interactive.kind === "list") {
1226
+ return this.channel.sendInteractiveList({
1227
+ to,
1228
+ body: interactive.body,
1229
+ buttonLabel: interactive.buttonLabel,
1230
+ sections: interactive.sections
1231
+ });
1232
+ }
1233
+ if (this.channel.sendInteractiveButtons) {
1234
+ return this.channel.sendInteractiveButtons({
1235
+ to,
1236
+ body: interactive.body,
1237
+ buttons: interactive.buttons
1238
+ });
1239
+ }
1240
+ return this.channel.sendInteractiveList(buttonsAsList(interactive, to, params.fallbackListLabel));
1241
+ }
1191
1242
  // Template é o único envio que ignora a janela — é justamente o mecanismo que a Meta oferece
1192
1243
  // para reabri-la.
1193
1244
  async sendTemplate(params) {
@@ -1215,6 +1266,15 @@ var SendMessageUseCase = class {
1215
1266
  });
1216
1267
  }
1217
1268
  };
1269
+ function buttonsAsList(interactive, to, label) {
1270
+ return {
1271
+ to,
1272
+ body: interactive.body,
1273
+ buttonLabel: label ?? DEFAULT_FALLBACK_LIST_LABEL,
1274
+ rows: interactive.buttons
1275
+ };
1276
+ }
1277
+ __name(buttonsAsList, "buttonsAsList");
1218
1278
  function mediaTypeFor(mimeType) {
1219
1279
  if (mimeType.startsWith("image/")) return "image";
1220
1280
  if (mimeType.startsWith("audio/")) return "audio";
@@ -1230,9 +1290,11 @@ var TakeoverConversationUseCase = class {
1230
1290
  }
1231
1291
  sessionRepository;
1232
1292
  realtime;
1233
- constructor(sessionRepository, realtime) {
1293
+ hooks;
1294
+ constructor(sessionRepository, realtime, hooks) {
1234
1295
  this.sessionRepository = sessionRepository;
1235
1296
  this.realtime = realtime;
1297
+ this.hooks = hooks;
1236
1298
  }
1237
1299
  async execute(params) {
1238
1300
  await this.sessionRepository.takeover(params.companyId, params.whatsappNumber, params.agentUserId);
@@ -1241,6 +1303,15 @@ var TakeoverConversationUseCase = class {
1241
1303
  assignedUserId: params.agentUserId
1242
1304
  });
1243
1305
  this.realtime?.emit("global", "data-changed", {});
1306
+ await this.hooks?.onConversationModeChanged?.({
1307
+ companyId: params.companyId,
1308
+ whatsappNumber: params.whatsappNumber,
1309
+ kind: "takeover",
1310
+ mode: "human",
1311
+ assignedUserId: params.agentUserId,
1312
+ actorId: params.actorId ?? params.agentUserId,
1313
+ occurredAt: /* @__PURE__ */ new Date()
1314
+ });
1244
1315
  }
1245
1316
  };
1246
1317
 
@@ -1251,9 +1322,11 @@ var ReleaseConversationUseCase = class {
1251
1322
  }
1252
1323
  sessionRepository;
1253
1324
  realtime;
1254
- constructor(sessionRepository, realtime) {
1325
+ hooks;
1326
+ constructor(sessionRepository, realtime, hooks) {
1255
1327
  this.sessionRepository = sessionRepository;
1256
1328
  this.realtime = realtime;
1329
+ this.hooks = hooks;
1257
1330
  }
1258
1331
  async execute(params) {
1259
1332
  await this.sessionRepository.release(params.companyId, params.whatsappNumber);
@@ -1262,6 +1335,166 @@ var ReleaseConversationUseCase = class {
1262
1335
  assignedUserId: null
1263
1336
  });
1264
1337
  this.realtime?.emit("global", "data-changed", {});
1338
+ await this.hooks?.onConversationModeChanged?.({
1339
+ companyId: params.companyId,
1340
+ whatsappNumber: params.whatsappNumber,
1341
+ kind: "release",
1342
+ mode: "bot",
1343
+ assignedUserId: null,
1344
+ actorId: params.actorId ?? null,
1345
+ occurredAt: /* @__PURE__ */ new Date()
1346
+ });
1347
+ }
1348
+ };
1349
+
1350
+ // src/use-cases/RequestHumanConversation.use-case.ts
1351
+ var import_meta_whatsapp_contracts3 = require("@adatechnology/meta-whatsapp-contracts");
1352
+
1353
+ // src/channel/inboundDispatch.ts
1354
+ var import_meta_graph_core = require("@adatechnology/meta-graph-core");
1355
+ function buildInboundJobId(job) {
1356
+ return job.kind === "message" ? `wa-inbound-message:${job.message.id}` : `wa-inbound-status:${job.status.id}:${job.status.status}`;
1357
+ }
1358
+ __name(buildInboundJobId, "buildInboundJobId");
1359
+ function toSessionContract(row) {
1360
+ return {
1361
+ id: row.id,
1362
+ companyId: row.companyId,
1363
+ whatsappNumber: row.whatsappNumber,
1364
+ currentState: row.currentState,
1365
+ flowKey: row.flowKey,
1366
+ currentNodeId: row.currentNodeId,
1367
+ context: row.context,
1368
+ mode: row.mode,
1369
+ assignedUserId: row.assignedUserId,
1370
+ humanRequestedAt: row.humanRequestedAt?.toISOString() ?? null,
1371
+ lastInboundAt: row.lastInboundAt?.toISOString() ?? null,
1372
+ lastAgentReadAt: row.lastAgentReadAt?.toISOString() ?? null,
1373
+ lastActivity: row.lastActivity.toISOString(),
1374
+ createdAt: row.createdAt.toISOString(),
1375
+ updatedAt: row.updatedAt.toISOString()
1376
+ };
1377
+ }
1378
+ __name(toSessionContract, "toSessionContract");
1379
+ function extractAnswer(message) {
1380
+ const interactive = message.interactive;
1381
+ if (interactive?.button_reply) return interactive.button_reply.id;
1382
+ if (interactive?.list_reply) return interactive.list_reply.id;
1383
+ return message.text?.body;
1384
+ }
1385
+ __name(extractAnswer, "extractAnswer");
1386
+ var InboundEffectsDispatcher = class {
1387
+ static {
1388
+ __name(this, "InboundEffectsDispatcher");
1389
+ }
1390
+ params;
1391
+ constructor(params) {
1392
+ this.params = params;
1393
+ }
1394
+ async run(job) {
1395
+ if (job.kind === "message") return this.runMessageEffects(job);
1396
+ return this.runStatusEffects(job);
1397
+ }
1398
+ async runMessageEffects(job) {
1399
+ const { companyId, message, savedMessageId, media } = job;
1400
+ if (media) {
1401
+ await this.params.hooks?.onMediaReceived?.({
1402
+ companyId,
1403
+ messageId: savedMessageId,
1404
+ whatsappNumber: message.from,
1405
+ sourceMediaId: media.sourceMediaId,
1406
+ mimeType: media.mimeType,
1407
+ ...media.filename ? {
1408
+ filename: media.filename
1409
+ } : {}
1410
+ });
1411
+ }
1412
+ const sessionRow = await this.params.sessionRepository.getContext(companyId, message.from);
1413
+ if (!sessionRow) return;
1414
+ if (sessionRow.mode === "human") return;
1415
+ const outcome = await this.params.hooks?.onMessageReceived?.(message, toSessionContract(sessionRow), job.profileName === void 0 ? {} : {
1416
+ profileName: job.profileName
1417
+ });
1418
+ if (outcome?.outcome === "handled") return;
1419
+ void extractAnswer(message);
1420
+ }
1421
+ async runStatusEffects(job) {
1422
+ const sessionRow = await this.params.sessionRepository.getContext(job.companyId, job.whatsappNumber);
1423
+ await this.params.hooks?.onStatusUpdate?.(job.status, sessionRow ? toSessionContract(sessionRow) : null);
1424
+ }
1425
+ };
1426
+ var ProcessInboundDispatchUseCase = class {
1427
+ static {
1428
+ __name(this, "ProcessInboundDispatchUseCase");
1429
+ }
1430
+ dispatcher;
1431
+ hooks;
1432
+ constructor(dispatcher, hooks) {
1433
+ this.dispatcher = dispatcher;
1434
+ this.hooks = hooks;
1435
+ }
1436
+ async execute(job) {
1437
+ await runInboundEffects({
1438
+ dispatcher: this.dispatcher,
1439
+ job,
1440
+ ...this.hooks ? {
1441
+ hooks: this.hooks
1442
+ } : {}
1443
+ });
1444
+ }
1445
+ };
1446
+ async function runInboundEffects(params) {
1447
+ const { job } = params;
1448
+ try {
1449
+ await params.dispatcher.run(job);
1450
+ } catch (error) {
1451
+ if (!(0, import_meta_graph_core.isDeterministicMetaRejection)(error)) throw error;
1452
+ await params.hooks?.onInboundEffectRejected?.({
1453
+ companyId: job.companyId,
1454
+ kind: job.kind,
1455
+ whatsappNumber: job.kind === "message" ? job.message.from : job.whatsappNumber,
1456
+ code: error.code,
1457
+ error
1458
+ });
1459
+ }
1460
+ }
1461
+ __name(runInboundEffects, "runInboundEffects");
1462
+
1463
+ // src/use-cases/RequestHumanConversation.use-case.ts
1464
+ var RequestHumanConversationUseCase = class {
1465
+ static {
1466
+ __name(this, "RequestHumanConversationUseCase");
1467
+ }
1468
+ sessionRepository;
1469
+ realtime;
1470
+ hooks;
1471
+ constructor(sessionRepository, realtime, hooks) {
1472
+ this.sessionRepository = sessionRepository;
1473
+ this.realtime = realtime;
1474
+ this.hooks = hooks;
1475
+ }
1476
+ async execute(params) {
1477
+ await this.sessionRepository.requestHuman(params.companyId, params.whatsappNumber);
1478
+ const session = await this.sessionRepository.getContext(params.companyId, params.whatsappNumber);
1479
+ if (!session) throw new import_meta_whatsapp_contracts3.SessionNotFoundError(params.whatsappNumber);
1480
+ this.realtime?.emit(`conv:${params.whatsappNumber}`, "human-requested", {
1481
+ humanRequestedAt: session.humanRequestedAt?.toISOString() ?? null
1482
+ });
1483
+ this.realtime?.emit("global", "data-changed", {});
1484
+ const outcomes = await Promise.allSettled([
1485
+ (async () => this.hooks?.onHumanRequested?.(toSessionContract(session)))(),
1486
+ (async () => this.hooks?.onConversationModeChanged?.({
1487
+ companyId: params.companyId,
1488
+ whatsappNumber: params.whatsappNumber,
1489
+ kind: "human-requested",
1490
+ mode: session.mode,
1491
+ assignedUserId: session.assignedUserId,
1492
+ actorId: params.actorId ?? null,
1493
+ occurredAt: /* @__PURE__ */ new Date()
1494
+ }))()
1495
+ ]);
1496
+ const failure = outcomes.find((outcome) => outcome.status === "rejected");
1497
+ if (failure) throw failure.reason;
1265
1498
  }
1266
1499
  };
1267
1500
 
@@ -1280,7 +1513,7 @@ var ListConversationsUseCase = class {
1280
1513
  };
1281
1514
 
1282
1515
  // src/use-cases/ListMessages.use-case.ts
1283
- var import_meta_whatsapp_contracts3 = require("@adatechnology/meta-whatsapp-contracts");
1516
+ var import_meta_whatsapp_contracts4 = require("@adatechnology/meta-whatsapp-contracts");
1284
1517
  var ListMessagesUseCase = class {
1285
1518
  static {
1286
1519
  __name(this, "ListMessagesUseCase");
@@ -1293,7 +1526,7 @@ var ListMessagesUseCase = class {
1293
1526
  }
1294
1527
  async execute(params) {
1295
1528
  const session = await this.sessionRepository.getContext(params.companyId, params.whatsappNumber);
1296
- if (!session) throw new import_meta_whatsapp_contracts3.SessionNotFoundError(params.whatsappNumber);
1529
+ if (!session) throw new import_meta_whatsapp_contracts4.SessionNotFoundError(params.whatsappNumber);
1297
1530
  const repoParams = {
1298
1531
  companyId: params.companyId,
1299
1532
  sessionId: session.id,
@@ -1305,7 +1538,7 @@ var ListMessagesUseCase = class {
1305
1538
  };
1306
1539
 
1307
1540
  // src/use-cases/ListConversationDocuments.use-case.ts
1308
- var import_meta_whatsapp_contracts4 = require("@adatechnology/meta-whatsapp-contracts");
1541
+ var import_meta_whatsapp_contracts5 = require("@adatechnology/meta-whatsapp-contracts");
1309
1542
  var ListConversationDocumentsUseCase = class {
1310
1543
  static {
1311
1544
  __name(this, "ListConversationDocumentsUseCase");
@@ -1318,7 +1551,7 @@ var ListConversationDocumentsUseCase = class {
1318
1551
  }
1319
1552
  async execute(params) {
1320
1553
  const session = await this.sessionRepository.getContext(params.companyId, params.whatsappNumber);
1321
- if (!session) throw new import_meta_whatsapp_contracts4.SessionNotFoundError(params.whatsappNumber);
1554
+ if (!session) throw new import_meta_whatsapp_contracts5.SessionNotFoundError(params.whatsappNumber);
1322
1555
  const { rows, total } = await this.documentRepository.listByConversation({
1323
1556
  companyId: params.companyId,
1324
1557
  sessionId: session.id,
@@ -1396,7 +1629,7 @@ var ListCompanyDocumentsUseCase = class {
1396
1629
  };
1397
1630
 
1398
1631
  // src/use-cases/DeleteConversation.use-case.ts
1399
- var import_meta_whatsapp_contracts5 = require("@adatechnology/meta-whatsapp-contracts");
1632
+ var import_meta_whatsapp_contracts6 = require("@adatechnology/meta-whatsapp-contracts");
1400
1633
  var DeleteConversationUseCase = class {
1401
1634
  static {
1402
1635
  __name(this, "DeleteConversationUseCase");
@@ -1411,7 +1644,7 @@ var DeleteConversationUseCase = class {
1411
1644
  }
1412
1645
  async execute(params) {
1413
1646
  const session = await this.sessionRepository.getContext(params.companyId, params.whatsappNumber);
1414
- if (!session) throw new import_meta_whatsapp_contracts5.SessionNotFoundError(params.whatsappNumber);
1647
+ if (!session) throw new import_meta_whatsapp_contracts6.SessionNotFoundError(params.whatsappNumber);
1415
1648
  const uploadIds = await this.documentRepository.listUploadIdsBySession(params.companyId, session.id);
1416
1649
  if (uploadIds.length > 0 && !this.objectStorage?.delete) {
1417
1650
  throw new Error("storage_delete_unsupported: a conversa tem arquivos e o storage injetado n\xE3o implementa delete");
@@ -1657,7 +1890,7 @@ var DocumentRepository = class {
1657
1890
  };
1658
1891
 
1659
1892
  // src/use-cases/ExportConversation.use-case.ts
1660
- var import_meta_whatsapp_contracts6 = require("@adatechnology/meta-whatsapp-contracts");
1893
+ var import_meta_whatsapp_contracts7 = require("@adatechnology/meta-whatsapp-contracts");
1661
1894
  var ExportConversationUseCase = class {
1662
1895
  static {
1663
1896
  __name(this, "ExportConversationUseCase");
@@ -1668,7 +1901,7 @@ var ExportConversationUseCase = class {
1668
1901
  }
1669
1902
  async execute(params) {
1670
1903
  const result = await this.sessionRepository.exportConversation(params.companyId, params.whatsappNumber);
1671
- if (!result) throw new import_meta_whatsapp_contracts6.SessionNotFoundError(params.whatsappNumber);
1904
+ if (!result) throw new import_meta_whatsapp_contracts7.SessionNotFoundError(params.whatsappNumber);
1672
1905
  return result;
1673
1906
  }
1674
1907
  };
@@ -1748,7 +1981,7 @@ var GetLiveFlowPositionsUseCase = class {
1748
1981
  };
1749
1982
 
1750
1983
  // src/flows/FlowInterpreter.ts
1751
- var import_meta_whatsapp_contracts7 = require("@adatechnology/meta-whatsapp-contracts");
1984
+ var import_meta_whatsapp_contracts8 = require("@adatechnology/meta-whatsapp-contracts");
1752
1985
  var DEFAULT_MAX_STEPS = 50;
1753
1986
  function evaluateCondition(node, context) {
1754
1987
  if (!node.conditionContextKey || !node.conditionOperator || !node.conditionValue) return false;
@@ -1849,9 +2082,9 @@ var FlowInterpreter = class {
1849
2082
  kind: "terminal",
1850
2083
  context: input.context
1851
2084
  };
1852
- if ((0, import_meta_whatsapp_contracts7.isCrossFlowTarget)(nextNodeId)) return {
2085
+ if ((0, import_meta_whatsapp_contracts8.isCrossFlowTarget)(nextNodeId)) return {
1853
2086
  kind: "cross-flow",
1854
- flowKey: (0, import_meta_whatsapp_contracts7.crossFlowKey)(nextNodeId),
2087
+ flowKey: (0, import_meta_whatsapp_contracts8.crossFlowKey)(nextNodeId),
1855
2088
  context: input.context
1856
2089
  };
1857
2090
  if (!input.graph.nodes[nextNodeId]) return {
@@ -2194,11 +2427,11 @@ var FlowMediaIdRepository = class {
2194
2427
  };
2195
2428
 
2196
2429
  // src/channel/WhatsAppChannelAdapter.ts
2197
- var import_meta_graph_core = require("@adatechnology/meta-graph-core");
2198
- var import_meta_whatsapp_contracts9 = require("@adatechnology/meta-whatsapp-contracts");
2430
+ var import_meta_graph_core2 = require("@adatechnology/meta-graph-core");
2431
+ var import_meta_whatsapp_contracts10 = require("@adatechnology/meta-whatsapp-contracts");
2199
2432
 
2200
2433
  // src/channel/previewMedia.ts
2201
- var import_meta_whatsapp_contracts8 = require("@adatechnology/meta-whatsapp-contracts");
2434
+ var import_meta_whatsapp_contracts9 = require("@adatechnology/meta-whatsapp-contracts");
2202
2435
 
2203
2436
  // src/channel/WhatsAppChannelAdapter.ts
2204
2437
  var WhatsAppChannelAdapter = class {
@@ -2215,7 +2448,7 @@ var WhatsAppChannelAdapter = class {
2215
2448
  try {
2216
2449
  return await operation();
2217
2450
  } catch (error) {
2218
- if (error instanceof import_meta_graph_core.WhatsAppWindowExpiredError) throw new import_meta_whatsapp_contracts9.WindowExpiredError();
2451
+ if (error instanceof import_meta_graph_core2.WhatsAppWindowExpiredError) throw new import_meta_whatsapp_contracts10.WindowExpiredError();
2219
2452
  throw error;
2220
2453
  }
2221
2454
  }
@@ -2239,16 +2472,25 @@ var WhatsAppChannelAdapter = class {
2239
2472
  };
2240
2473
  }
2241
2474
  async sendInteractiveList(params) {
2475
+ const sections = (params.sections ?? [
2476
+ {
2477
+ rows: params.rows ?? []
2478
+ }
2479
+ ]).map((section) => ({
2480
+ title: section.title ?? params.buttonLabel,
2481
+ rows: section.rows.map((row) => ({
2482
+ id: row.id,
2483
+ title: row.title,
2484
+ ...row.description ? {
2485
+ description: row.description
2486
+ } : {}
2487
+ }))
2488
+ }));
2242
2489
  const result = await this.translateErrors(() => this.messages.sendInteractiveList({
2243
2490
  to: params.to,
2244
2491
  bodyText: params.body,
2245
2492
  buttonText: params.buttonLabel,
2246
- sections: [
2247
- {
2248
- title: params.buttonLabel,
2249
- rows: params.rows
2250
- }
2251
- ]
2493
+ sections
2252
2494
  }));
2253
2495
  return {
2254
2496
  externalMessageId: result.waMessageId
@@ -2285,7 +2527,7 @@ var WhatsAppChannelAdapter = class {
2285
2527
  * tentar buscá-lo lá renderia um 404 confuso em vez do áudio que o operador acabou de gravar.
2286
2528
  */
2287
2529
  async fetchMediaAsBase64(mediaId) {
2288
- const uploadId = this.previewMedia?.isEnabled ? (0, import_meta_whatsapp_contracts8.resolvePreviewUploadId)(mediaId) : void 0;
2530
+ const uploadId = this.previewMedia?.isEnabled ? (0, import_meta_whatsapp_contracts9.resolvePreviewUploadId)(mediaId) : void 0;
2289
2531
  if (uploadId) {
2290
2532
  const buffer = await this.previewMedia.objectStorage.getObject(uploadId);
2291
2533
  return {
@@ -2298,35 +2540,34 @@ var WhatsAppChannelAdapter = class {
2298
2540
  };
2299
2541
 
2300
2542
  // src/channel/ReceiveWebhook.use-case.ts
2301
- var import_meta_whatsapp_contracts12 = require("@adatechnology/meta-whatsapp-contracts");
2302
- var import_meta_graph_core3 = require("@adatechnology/meta-graph-core");
2543
+ var import_meta_whatsapp_contracts13 = require("@adatechnology/meta-whatsapp-contracts");
2303
2544
 
2304
2545
  // src/channel/webhookSecurity.ts
2305
- var import_meta_graph_core2 = require("@adatechnology/meta-graph-core");
2306
- var import_meta_whatsapp_contracts10 = require("@adatechnology/meta-whatsapp-contracts");
2546
+ var import_meta_graph_core3 = require("@adatechnology/meta-graph-core");
2547
+ var import_meta_whatsapp_contracts11 = require("@adatechnology/meta-whatsapp-contracts");
2307
2548
  var WEBHOOK_NONCE_NAMESPACE = "meta-whatsapp";
2308
2549
  function verifyWebhookChallenge(params) {
2309
- if (!(0, import_meta_graph_core2.isValidWebhookChallenge)(params)) throw new import_meta_whatsapp_contracts10.InvalidWebhookSignatureError();
2550
+ if (!(0, import_meta_graph_core3.isValidWebhookChallenge)(params)) throw new import_meta_whatsapp_contracts11.InvalidWebhookSignatureError();
2310
2551
  return params.challenge;
2311
2552
  }
2312
2553
  __name(verifyWebhookChallenge, "verifyWebhookChallenge");
2313
2554
  function verifyWebhookSignature(params) {
2314
- if (!(0, import_meta_graph_core2.isValidWebhookSignature)(params)) throw new import_meta_whatsapp_contracts10.InvalidWebhookSignatureError();
2555
+ if (!(0, import_meta_graph_core3.isValidWebhookSignature)(params)) throw new import_meta_whatsapp_contracts11.InvalidWebhookSignatureError();
2315
2556
  }
2316
2557
  __name(verifyWebhookSignature, "verifyWebhookSignature");
2317
2558
  function deliveryKey(signatureHeader) {
2318
- return (0, import_meta_graph_core2.buildWebhookDeliveryKey)({
2559
+ return (0, import_meta_graph_core3.buildWebhookDeliveryKey)({
2319
2560
  namespace: WEBHOOK_NONCE_NAMESPACE,
2320
2561
  signatureHeader
2321
2562
  });
2322
2563
  }
2323
2564
  __name(deliveryKey, "deliveryKey");
2324
2565
  async function claimWebhookDelivery(params) {
2325
- return params.nonceStore.setIfAbsent(deliveryKey(params.signatureHeader), params.ttlSeconds ?? import_meta_graph_core2.WEBHOOK_CLAIM_TTL_SECONDS);
2566
+ return params.nonceStore.setIfAbsent(deliveryKey(params.signatureHeader), params.ttlSeconds ?? import_meta_graph_core3.WEBHOOK_CLAIM_TTL_SECONDS);
2326
2567
  }
2327
2568
  __name(claimWebhookDelivery, "claimWebhookDelivery");
2328
2569
  async function confirmWebhookDelivery(params) {
2329
- await params.nonceStore.confirm?.(deliveryKey(params.signatureHeader), params.ttlSeconds ?? import_meta_graph_core2.WEBHOOK_NONCE_TTL_SECONDS);
2570
+ await params.nonceStore.confirm?.(deliveryKey(params.signatureHeader), params.ttlSeconds ?? import_meta_graph_core3.WEBHOOK_NONCE_TTL_SECONDS);
2330
2571
  }
2331
2572
  __name(confirmWebhookDelivery, "confirmWebhookDelivery");
2332
2573
 
@@ -2334,7 +2575,7 @@ __name(confirmWebhookDelivery, "confirmWebhookDelivery");
2334
2575
  var import_drizzle_orm9 = require("drizzle-orm");
2335
2576
 
2336
2577
  // src/use-cases/TranscribeAudio.use-case.ts
2337
- var import_meta_whatsapp_contracts11 = require("@adatechnology/meta-whatsapp-contracts");
2578
+ var import_meta_whatsapp_contracts12 = require("@adatechnology/meta-whatsapp-contracts");
2338
2579
 
2339
2580
  // src/transcription.types.ts
2340
2581
  var TRANSCRIPTION_STATUS = {
@@ -2395,7 +2636,7 @@ var TranscribeAudioUseCase = class {
2395
2636
  }
2396
2637
  if (this.dependencies.resolvePolicy) {
2397
2638
  const policy = await this.dependencies.resolvePolicy(params.companyId);
2398
- if (!policy.isEnabled) throw new import_meta_whatsapp_contracts11.TranscriptionDisabledError();
2639
+ if (!policy.isEnabled) throw new import_meta_whatsapp_contracts12.TranscriptionDisabledError();
2399
2640
  }
2400
2641
  const audio = extractAudioReference(message);
2401
2642
  const buffer = await this.dependencies.objectStorage.getObject(audio.uploadId);
@@ -2472,11 +2713,11 @@ function extractAudioReference(message) {
2472
2713
  const audio = payload["audio"];
2473
2714
  const mimeType = typeof payload["mimeType"] === "string" ? payload["mimeType"] : audio?.mime_type;
2474
2715
  if (!isAudioMimeType(mimeType) && !audio) {
2475
- throw new import_meta_whatsapp_contracts11.MessageNotAudioError(message.id, message.type);
2716
+ throw new import_meta_whatsapp_contracts12.MessageNotAudioError(message.id, message.type);
2476
2717
  }
2477
2718
  const uploadId = payload["uploadId"];
2478
2719
  if (typeof uploadId !== "string" || uploadId.length === 0) {
2479
- throw new import_meta_whatsapp_contracts11.AudioNotIngestedError(message.id);
2720
+ throw new import_meta_whatsapp_contracts12.AudioNotIngestedError(message.id);
2480
2721
  }
2481
2722
  return {
2482
2723
  uploadId,
@@ -2649,91 +2890,6 @@ function extractMediaDescriptor(message) {
2649
2890
  }
2650
2891
  __name(extractMediaDescriptor, "extractMediaDescriptor");
2651
2892
 
2652
- // src/channel/inboundDispatch.ts
2653
- function buildInboundJobId(job) {
2654
- return job.kind === "message" ? `wa-inbound-message:${job.message.id}` : `wa-inbound-status:${job.status.id}:${job.status.status}`;
2655
- }
2656
- __name(buildInboundJobId, "buildInboundJobId");
2657
- function toSessionContract(row) {
2658
- return {
2659
- id: row.id,
2660
- companyId: row.companyId,
2661
- whatsappNumber: row.whatsappNumber,
2662
- currentState: row.currentState,
2663
- flowKey: row.flowKey,
2664
- currentNodeId: row.currentNodeId,
2665
- context: row.context,
2666
- mode: row.mode,
2667
- assignedUserId: row.assignedUserId,
2668
- humanRequestedAt: row.humanRequestedAt?.toISOString() ?? null,
2669
- lastInboundAt: row.lastInboundAt?.toISOString() ?? null,
2670
- lastAgentReadAt: row.lastAgentReadAt?.toISOString() ?? null,
2671
- lastActivity: row.lastActivity.toISOString(),
2672
- createdAt: row.createdAt.toISOString(),
2673
- updatedAt: row.updatedAt.toISOString()
2674
- };
2675
- }
2676
- __name(toSessionContract, "toSessionContract");
2677
- function extractAnswer(message) {
2678
- const interactive = message.interactive;
2679
- if (interactive?.button_reply) return interactive.button_reply.id;
2680
- if (interactive?.list_reply) return interactive.list_reply.id;
2681
- return message.text?.body;
2682
- }
2683
- __name(extractAnswer, "extractAnswer");
2684
- var InboundEffectsDispatcher = class {
2685
- static {
2686
- __name(this, "InboundEffectsDispatcher");
2687
- }
2688
- params;
2689
- constructor(params) {
2690
- this.params = params;
2691
- }
2692
- async run(job) {
2693
- if (job.kind === "message") return this.runMessageEffects(job);
2694
- return this.runStatusEffects(job);
2695
- }
2696
- async runMessageEffects(job) {
2697
- const { companyId, message, savedMessageId, media } = job;
2698
- if (media) {
2699
- await this.params.hooks?.onMediaReceived?.({
2700
- companyId,
2701
- messageId: savedMessageId,
2702
- whatsappNumber: message.from,
2703
- sourceMediaId: media.sourceMediaId,
2704
- mimeType: media.mimeType,
2705
- ...media.filename ? {
2706
- filename: media.filename
2707
- } : {}
2708
- });
2709
- }
2710
- const sessionRow = await this.params.sessionRepository.getContext(companyId, message.from);
2711
- if (!sessionRow) return;
2712
- if (sessionRow.mode === "human") return;
2713
- const outcome = await this.params.hooks?.onMessageReceived?.(message, toSessionContract(sessionRow), job.profileName === void 0 ? {} : {
2714
- profileName: job.profileName
2715
- });
2716
- if (outcome?.outcome === "handled") return;
2717
- void extractAnswer(message);
2718
- }
2719
- async runStatusEffects(job) {
2720
- const sessionRow = await this.params.sessionRepository.getContext(job.companyId, job.whatsappNumber);
2721
- await this.params.hooks?.onStatusUpdate?.(job.status, sessionRow ? toSessionContract(sessionRow) : null);
2722
- }
2723
- };
2724
- var ProcessInboundDispatchUseCase = class {
2725
- static {
2726
- __name(this, "ProcessInboundDispatchUseCase");
2727
- }
2728
- dispatcher;
2729
- constructor(dispatcher) {
2730
- this.dispatcher = dispatcher;
2731
- }
2732
- async execute(job) {
2733
- await this.dispatcher.run(job);
2734
- }
2735
- };
2736
-
2737
2893
  // src/channel/ReceiveWebhook.use-case.ts
2738
2894
  var EMPTY_RESULT = {
2739
2895
  messagesProcessed: 0,
@@ -2777,8 +2933,8 @@ function extractPayload(message, { isLocationRedacted } = DEFAULT_EXTRACTION_OPT
2777
2933
  }
2778
2934
  __name(extractPayload, "extractPayload");
2779
2935
  var ACCOUNT_EVENT_FIELDS = [
2780
- import_meta_whatsapp_contracts12.WHATSAPP_WEBHOOK_FIELDS.TEMPLATE_STATUS_UPDATE,
2781
- import_meta_whatsapp_contracts12.WHATSAPP_WEBHOOK_FIELDS.PHONE_NUMBER_QUALITY_UPDATE
2936
+ import_meta_whatsapp_contracts13.WHATSAPP_WEBHOOK_FIELDS.TEMPLATE_STATUS_UPDATE,
2937
+ import_meta_whatsapp_contracts13.WHATSAPP_WEBHOOK_FIELDS.PHONE_NUMBER_QUALITY_UPDATE
2782
2938
  ];
2783
2939
  function isAccountEventField(field) {
2784
2940
  return field !== void 0 && ACCOUNT_EVENT_FIELDS.includes(field);
@@ -2817,7 +2973,7 @@ var ReceiveWebhookUseCase = class {
2817
2973
  ...EMPTY_RESULT
2818
2974
  };
2819
2975
  const rawText = typeof input.rawBody === "string" ? input.rawBody : input.rawBody.toString("utf8");
2820
- const parsed = import_meta_whatsapp_contracts12.whatsAppWebhookPayloadSchema.safeParse(JSON.parse(rawText));
2976
+ const parsed = import_meta_whatsapp_contracts13.whatsAppWebhookPayloadSchema.safeParse(JSON.parse(rawText));
2821
2977
  if (!parsed.success) {
2822
2978
  await this.params.hooks?.onUnhandledWebhookEvent?.({
2823
2979
  field: void 0,
@@ -2850,7 +3006,7 @@ var ReceiveWebhookUseCase = class {
2850
3006
  continue;
2851
3007
  }
2852
3008
  for (const message of change.value.messages ?? []) {
2853
- const profileName = (0, import_meta_whatsapp_contracts12.resolveContactProfileName)({
3009
+ const profileName = (0, import_meta_whatsapp_contracts13.resolveContactProfileName)({
2854
3010
  contacts: change.value.contacts,
2855
3011
  from: message.from
2856
3012
  });
@@ -2888,8 +3044,8 @@ var ReceiveWebhookUseCase = class {
2888
3044
  // Devolve `false` quando o corpo não bate com o schema do field — o chamador conta como não
2889
3045
  // tratado. O host é avisado nos dois casos, mas com `reason` diferente.
2890
3046
  async handleAccountEvent(change) {
2891
- if (change.field === import_meta_whatsapp_contracts12.WHATSAPP_WEBHOOK_FIELDS.TEMPLATE_STATUS_UPDATE) {
2892
- const update = import_meta_whatsapp_contracts12.whatsAppTemplateStatusUpdateSchema.safeParse(change.value);
3047
+ if (change.field === import_meta_whatsapp_contracts13.WHATSAPP_WEBHOOK_FIELDS.TEMPLATE_STATUS_UPDATE) {
3048
+ const update = import_meta_whatsapp_contracts13.whatsAppTemplateStatusUpdateSchema.safeParse(change.value);
2893
3049
  if (!update.success) {
2894
3050
  await this.params.hooks?.onUnhandledWebhookEvent?.({
2895
3051
  field: change.field,
@@ -2901,7 +3057,7 @@ var ReceiveWebhookUseCase = class {
2901
3057
  await this.params.hooks?.onTemplateStatusUpdate?.(update.data);
2902
3058
  return true;
2903
3059
  }
2904
- const quality = import_meta_whatsapp_contracts12.whatsAppPhoneNumberQualityUpdateSchema.safeParse(change.value);
3060
+ const quality = import_meta_whatsapp_contracts13.whatsAppPhoneNumberQualityUpdateSchema.safeParse(change.value);
2905
3061
  if (!quality.success) {
2906
3062
  await this.params.hooks?.onUnhandledWebhookEvent?.({
2907
3063
  field: change.field,
@@ -2983,24 +3139,15 @@ var ReceiveWebhookUseCase = class {
2983
3139
  });
2984
3140
  return;
2985
3141
  }
2986
- try {
2987
- await this.dispatcher.run(job);
2988
- } catch (error) {
2989
- if (!(0, import_meta_graph_core3.isDeterministicMetaRejection)(error)) throw error;
2990
- await this.params.hooks?.onInboundEffectRejected?.({
2991
- companyId: job.companyId,
2992
- kind: job.kind,
2993
- whatsappNumber: resolveJobNumber(job),
2994
- code: error.code,
2995
- error
2996
- });
2997
- }
3142
+ await runInboundEffects({
3143
+ dispatcher: this.dispatcher,
3144
+ job,
3145
+ ...this.params.hooks ? {
3146
+ hooks: this.params.hooks
3147
+ } : {}
3148
+ });
2998
3149
  }
2999
3150
  };
3000
- function resolveJobNumber(job) {
3001
- return job.kind === "message" ? job.message.from : job.whatsappNumber;
3002
- }
3003
- __name(resolveJobNumber, "resolveJobNumber");
3004
3151
 
3005
3152
  // src/use-cases/resolveTranscriptionPolicy.ts
3006
3153
  function createTranscriptionPolicyResolver(dependencies) {
@@ -3041,7 +3188,7 @@ var StorePreviewMediaUseCase = class {
3041
3188
  key
3042
3189
  });
3043
3190
  return {
3044
- mediaId: (0, import_meta_whatsapp_contracts8.toPreviewMediaId)(uploadId),
3191
+ mediaId: (0, import_meta_whatsapp_contracts9.toPreviewMediaId)(uploadId),
3045
3192
  uploadId
3046
3193
  };
3047
3194
  }
@@ -3084,11 +3231,14 @@ function createMetaWhatsAppModule(params) {
3084
3231
  startState,
3085
3232
  hooks,
3086
3233
  realtime: providers.realtime,
3234
+ ...providers.inboundQueue ? {
3235
+ inboundQueue: providers.inboundQueue
3236
+ } : {},
3087
3237
  redactInboundLocation: params.features?.redactInboundLocation ?? false
3088
3238
  });
3089
3239
  const flowInterpreter = flowEngineEnabled ? new FlowInterpreter() : void 0;
3090
3240
  if (flowInterpreter && providers.objectStorage?.getObject) {
3091
- flowInterpreter.registerFlowAction(import_meta_whatsapp_contracts13.FLOW_ACTION_KIND.SEND_MEDIA, createSendMediaAction({
3241
+ flowInterpreter.registerFlowAction(import_meta_whatsapp_contracts14.FLOW_ACTION_KIND.SEND_MEDIA, createSendMediaAction({
3092
3242
  flowMediaRepository,
3093
3243
  objectStorage: providers.objectStorage,
3094
3244
  logMessage,
@@ -3105,7 +3255,7 @@ function createMetaWhatsAppModule(params) {
3105
3255
  }));
3106
3256
  }
3107
3257
  if (flowInterpreter && providers.catalog && config.catalogId) {
3108
- flowInterpreter.registerFlowAction(import_meta_whatsapp_contracts13.FLOW_ACTION_KIND.SEND_PRODUCT_LIST, createSendProductListAction({
3258
+ flowInterpreter.registerFlowAction(import_meta_whatsapp_contracts14.FLOW_ACTION_KIND.SEND_PRODUCT_LIST, createSendProductListAction({
3109
3259
  catalog: providers.catalog,
3110
3260
  catalogId: config.catalogId,
3111
3261
  logMessage,
@@ -3154,8 +3304,10 @@ function createMetaWhatsAppModule(params) {
3154
3304
  conversations: {
3155
3305
  log: logMessage,
3156
3306
  send: sendMessage,
3157
- takeover: new TakeoverConversationUseCase(sessionRepository, providers.realtime),
3158
- release: new ReleaseConversationUseCase(sessionRepository, providers.realtime),
3307
+ takeover: new TakeoverConversationUseCase(sessionRepository, providers.realtime, hooks),
3308
+ release: new ReleaseConversationUseCase(sessionRepository, providers.realtime, hooks),
3309
+ // Marca o pedido de atendimento (fila "aguardando atendimento") e dispara `onHumanRequested`.
3310
+ requestHuman: new RequestHumanConversationUseCase(sessionRepository, providers.realtime, hooks),
3159
3311
  list: new ListConversationsUseCase(sessionRepository),
3160
3312
  listMessages: new ListMessagesUseCase(sessionRepository, messageRepository),
3161
3313
  listDocuments,
@@ -3197,7 +3349,18 @@ function createMetaWhatsAppModule(params) {
3197
3349
  verifyChallenge: /* @__PURE__ */ __name((query) => verifyWebhookChallenge({
3198
3350
  ...query,
3199
3351
  expectedToken: config.webhookVerifyToken
3200
- }), "verifyChallenge")
3352
+ }), "verifyChallenge"),
3353
+ // Lado do worker de `providers.inboundQueue`: roda os efeitos de um job já enfileirado. Existe
3354
+ // mesmo sem fila configurada — um worker de outra instância pode consumir a fila desta.
3355
+ processInboundDispatch: new ProcessInboundDispatchUseCase(new InboundEffectsDispatcher({
3356
+ sessionRepository,
3357
+ ...hooks ? {
3358
+ hooks
3359
+ } : {},
3360
+ ...providers.realtime ? {
3361
+ realtime: providers.realtime
3362
+ } : {}
3363
+ }), hooks)
3201
3364
  },
3202
3365
  // undefined quando features.flowEngine === false.
3203
3366
  flows: flowInterpreter ? {
@@ -3223,15 +3386,29 @@ __name(createMetaWhatsAppModule, "createMetaWhatsAppModule");
3223
3386
  // src/runMigrations.ts
3224
3387
  var import_node_path = require("path");
3225
3388
  var META_WHATSAPP_MIGRATIONS_TABLE = "meta_whatsapp_migrations";
3226
- function metaWhatsAppMigrationsFolder() {
3227
- return (0, import_node_path.join)(__dirname, "migrations");
3389
+ var LAYOUT_DIRECTORY = {
3390
+ v1: "migrations",
3391
+ journal: "migrations-journal"
3392
+ };
3393
+ function metaWhatsAppMigrationsFolder(params = {}) {
3394
+ return (0, import_node_path.join)(__dirname, LAYOUT_DIRECTORY[params.layout ?? "v1"]);
3228
3395
  }
3229
3396
  __name(metaWhatsAppMigrationsFolder, "metaWhatsAppMigrationsFolder");
3397
+ var MISSING_JOURNAL_REFUSAL = "meta/_journal.json";
3230
3398
  async function runMetaWhatsAppMigrations(params) {
3231
- await params.migrate(params.db, {
3232
- migrationsFolder: metaWhatsAppMigrationsFolder(),
3399
+ const run = /* @__PURE__ */ __name((layout) => params.migrate(params.db, {
3400
+ migrationsFolder: metaWhatsAppMigrationsFolder({
3401
+ layout
3402
+ }),
3233
3403
  migrationsTable: META_WHATSAPP_MIGRATIONS_TABLE
3234
- });
3404
+ }), "run");
3405
+ if (params.layout) return run(params.layout);
3406
+ try {
3407
+ await run("v1");
3408
+ } catch (error) {
3409
+ if (!(error instanceof Error) || !error.message.includes(MISSING_JOURNAL_REFUSAL)) throw error;
3410
+ await run("journal");
3411
+ }
3235
3412
  }
3236
3413
  __name(runMetaWhatsAppMigrations, "runMetaWhatsAppMigrations");
3237
3414
 
@@ -3314,6 +3491,7 @@ __name(redeemSseTicket, "redeemSseTicket");
3314
3491
  0 && (module.exports = {
3315
3492
  CountInboundLocationsUseCase,
3316
3493
  CreateFlowGraphUseCase,
3494
+ DEFAULT_FALLBACK_LIST_LABEL,
3317
3495
  DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS,
3318
3496
  DeleteConversationUseCase,
3319
3497
  DeleteFlowGraphUseCase,
@@ -3346,6 +3524,7 @@ __name(redeemSseTicket, "redeemSseTicket");
3346
3524
  ReceiveWebhookUseCase,
3347
3525
  RedactInboundLocationsUseCase,
3348
3526
  ReleaseConversationUseCase,
3527
+ RequestHumanConversationUseCase,
3349
3528
  SaveFlowGraphUseCase,
3350
3529
  SendMessageUseCase,
3351
3530
  SessionRepository,