@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.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
2
  import { PgAsyncDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
3
3
  import * as _adatechnology_meta_whatsapp_contracts from '@adatechnology/meta-whatsapp-contracts';
4
- import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, WhatsAppStatusError, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort, SendChannelMediaParams } from '@adatechnology/meta-whatsapp-contracts';
4
+ import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, WhatsAppStatusError, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, InteractiveMessage, MetaWhatsAppHooks, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, SubjectResolverInterface, CatalogPort, SendChannelMediaParams, ChannelInteractiveListParams, ChannelInteractiveButtonsParams } from '@adatechnology/meta-whatsapp-contracts';
5
5
  export { PREVIEW_MEDIA_ID_PREFIX, TranscriptionMode, resolvePreviewUploadId, toPreviewMediaId } from '@adatechnology/meta-whatsapp-contracts';
6
6
  import { WhatsAppMessageProvider } from '@adatechnology/meta-whatsapp-provider';
7
7
  export { WEBHOOK_CLAIM_TTL_SECONDS, WEBHOOK_NONCE_TTL_SECONDS } from '@adatechnology/meta-graph-core';
@@ -1746,6 +1746,8 @@ declare class DocumentRepository {
1746
1746
  deleteById(companyId: string, id: string): Promise<void>;
1747
1747
  }
1748
1748
 
1749
+ /** Rótulo da lista quando o canal não sabe enviar botão e os botões viram lista. */
1750
+ declare const DEFAULT_FALLBACK_LIST_LABEL = "Op\u00E7\u00F5es";
1749
1751
  type SendTextParams = {
1750
1752
  companyId: string;
1751
1753
  whatsappNumber: string;
@@ -1775,6 +1777,20 @@ type SendTemplateParams = {
1775
1777
  agentUserId?: string;
1776
1778
  startState: SessionState;
1777
1779
  };
1780
+ type SendInteractiveParams = {
1781
+ companyId: string;
1782
+ whatsappNumber: string;
1783
+ /** Botões (até 3) ou lista (até 10 linhas em até 10 seções). Validado contra `WHATSAPP_CHOICE_LIMIT`. */
1784
+ interactive: InteractiveMessage;
1785
+ sender: 'bot' | 'agent';
1786
+ agentUserId?: string;
1787
+ startState: SessionState;
1788
+ /**
1789
+ * Rótulo da lista quando `interactive.kind === 'buttons'` e o canal não implementa
1790
+ * `sendInteractiveButtons` — os botões saem como lista. Padrão `DEFAULT_FALLBACK_LIST_LABEL`.
1791
+ */
1792
+ fallbackListLabel?: string;
1793
+ };
1778
1794
  declare class SendMessageUseCase {
1779
1795
  private readonly channel;
1780
1796
  private readonly sessionRepository;
@@ -1785,6 +1801,16 @@ declare class SendMessageUseCase {
1785
1801
  private assertWithinWindow;
1786
1802
  sendText(params: SendTextParams): Promise<MessageRow | undefined>;
1787
1803
  sendMedia(params: SendMediaParams): Promise<MessageRow | undefined>;
1804
+ /**
1805
+ * Botões ou lista, pelo mesmo caminho do `sendText`: janela, envio, transcript (idempotente pelo
1806
+ * `waMessageId`). Os limites da Meta são conferidos ANTES de tudo — mensagem fora do teto a Graph
1807
+ * API recusa inteira, e o erro local (`InteractiveLimitExceededError`) diz qual campo corrigir.
1808
+ *
1809
+ * O transcript guarda `type: 'interactive'`, o corpo em `content` e a mensagem inteira (ids e
1810
+ * títulos das opções) em `payload.interactive`, para o histórico mostrar o que foi oferecido.
1811
+ */
1812
+ sendInteractive(params: SendInteractiveParams): Promise<MessageRow | undefined>;
1813
+ private sendInteractiveThroughChannel;
1788
1814
  sendTemplate(params: SendTemplateParams): Promise<MessageRow | undefined>;
1789
1815
  }
1790
1816
 
@@ -1792,25 +1818,53 @@ type TakeoverConversationParams = {
1792
1818
  companyId: string;
1793
1819
  whatsappNumber: string;
1794
1820
  agentUserId: string;
1821
+ /**
1822
+ * Quem executou a ação, quando não é o próprio atendente (ex.: supervisor atribuindo a conversa a
1823
+ * outra pessoa). Omitido, o ator é `agentUserId`.
1824
+ */
1825
+ actorId?: string;
1795
1826
  };
1796
1827
  declare class TakeoverConversationUseCase {
1797
1828
  private readonly sessionRepository;
1798
1829
  private readonly realtime?;
1799
- constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined);
1830
+ private readonly hooks?;
1831
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onConversationModeChanged"> | undefined);
1800
1832
  execute(params: TakeoverConversationParams): Promise<void>;
1801
1833
  }
1802
1834
 
1803
1835
  type ReleaseConversationParams = {
1804
1836
  companyId: string;
1805
1837
  whatsappNumber: string;
1838
+ /** Quem devolveu a conversa ao bot. Omitido, `null` — o próprio sistema (ex.: job de inatividade). */
1839
+ actorId?: string | null;
1806
1840
  };
1807
1841
  declare class ReleaseConversationUseCase {
1808
1842
  private readonly sessionRepository;
1809
1843
  private readonly realtime?;
1810
- constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined);
1844
+ private readonly hooks?;
1845
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onConversationModeChanged"> | undefined);
1811
1846
  execute(params: ReleaseConversationParams): Promise<void>;
1812
1847
  }
1813
1848
 
1849
+ type RequestHumanConversationParams = {
1850
+ companyId: string;
1851
+ whatsappNumber: string;
1852
+ /** Quem pediu. Omitido, `null` — o cliente pelo menu ou o bot decidindo encaminhar. */
1853
+ actorId?: string | null;
1854
+ };
1855
+ /**
1856
+ * Coloca a conversa na fila "aguardando atendimento" (`humanRequestedAt`) sem tirá-la do bot: quem
1857
+ * assume é o `takeover`. Dispara `onHumanRequested` (o host decide como avisar a equipe) e
1858
+ * `onConversationModeChanged` com `kind: 'human-requested'` (trilha de auditoria).
1859
+ */
1860
+ declare class RequestHumanConversationUseCase {
1861
+ private readonly sessionRepository;
1862
+ private readonly realtime?;
1863
+ private readonly hooks?;
1864
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onHumanRequested" | "onConversationModeChanged"> | undefined);
1865
+ execute(params: RequestHumanConversationParams): Promise<void>;
1866
+ }
1867
+
1814
1868
  type ListConversationsParams = {
1815
1869
  companyId: string;
1816
1870
  filters?: ListConversationsFilters;
@@ -2315,7 +2369,8 @@ declare class InboundEffectsDispatcher {
2315
2369
  */
2316
2370
  declare class ProcessInboundDispatchUseCase {
2317
2371
  private readonly dispatcher;
2318
- constructor(dispatcher: InboundEffectsDispatcher);
2372
+ private readonly hooks?;
2373
+ constructor(dispatcher: InboundEffectsDispatcher, hooks?: Pick<MetaWhatsAppHooks, "onInboundEffectRejected"> | undefined);
2319
2374
  execute(job: InboundDispatchJob): Promise<void>;
2320
2375
  }
2321
2376
 
@@ -2633,6 +2688,13 @@ interface MetaWhatsAppTranscriptionConfig {
2633
2688
  languageHint?: string;
2634
2689
  }
2635
2690
  interface MetaWhatsAppModuleProviders {
2691
+ /**
2692
+ * Fila durável para os efeitos do webhook (hooks, realtime). Ausente, rodam dentro da requisição,
2693
+ * como sempre. Presente, o webhook só persiste e enfileira; o worker do host chama
2694
+ * `webhook.processInboundDispatch.execute(job)`. Ver docs/webhook-durability.md — qualquer fila
2695
+ * com durabilidade e retentativa serve, inclusive uma tabela no Postgres.
2696
+ */
2697
+ inboundQueue?: InboundDispatchQueueInterface;
2636
2698
  objectStorage?: ObjectStorageInterface;
2637
2699
  cache?: CacheInterface;
2638
2700
  realtime?: RealtimeNotifierInterface;
@@ -2662,6 +2724,7 @@ declare function createMetaWhatsAppModule(params: CreateMetaWhatsAppModuleParams
2662
2724
  send: SendMessageUseCase;
2663
2725
  takeover: TakeoverConversationUseCase;
2664
2726
  release: ReleaseConversationUseCase;
2727
+ requestHuman: RequestHumanConversationUseCase;
2665
2728
  list: ListConversationsUseCase;
2666
2729
  listMessages: ListMessagesUseCase;
2667
2730
  listDocuments: ListConversationDocumentsUseCase;
@@ -2698,6 +2761,7 @@ declare function createMetaWhatsAppModule(params: CreateMetaWhatsAppModuleParams
2698
2761
  token: string | null;
2699
2762
  challenge: string | null;
2700
2763
  }) => string;
2764
+ processInboundDispatch: ProcessInboundDispatchUseCase;
2701
2765
  };
2702
2766
  flows: {
2703
2767
  interpreter: FlowInterpreter;
@@ -2761,25 +2825,10 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
2761
2825
  }): Promise<{
2762
2826
  externalMessageId: string | null;
2763
2827
  }>;
2764
- sendInteractiveList(params: {
2765
- to: string;
2766
- body: string;
2767
- buttonLabel: string;
2768
- rows: {
2769
- id: string;
2770
- title: string;
2771
- }[];
2772
- }): Promise<{
2828
+ sendInteractiveList(params: ChannelInteractiveListParams): Promise<{
2773
2829
  externalMessageId: string | null;
2774
2830
  }>;
2775
- sendInteractiveButtons(params: {
2776
- to: string;
2777
- body: string;
2778
- buttons: {
2779
- id: string;
2780
- title: string;
2781
- }[];
2782
- }): Promise<{
2831
+ sendInteractiveButtons(params: ChannelInteractiveButtonsParams): Promise<{
2783
2832
  externalMessageId: string | null;
2784
2833
  }>;
2785
2834
  sendProductList(params: {
@@ -2813,13 +2862,18 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
2813
2862
  declare const INBOUND_LOCATION_CONTENT = "\uD83D\uDCCD Localiza\u00E7\u00E3o";
2814
2863
 
2815
2864
  declare const META_WHATSAPP_MIGRATIONS_TABLE = "meta_whatsapp_migrations";
2816
- declare function metaWhatsAppMigrationsFolder(): string;
2865
+ type MetaWhatsAppMigrationsLayout = 'v1' | 'journal';
2866
+ type MetaWhatsAppMigrationsFolderParams = {
2867
+ readonly layout?: MetaWhatsAppMigrationsLayout;
2868
+ };
2869
+ declare function metaWhatsAppMigrationsFolder(params?: MetaWhatsAppMigrationsFolderParams): string;
2817
2870
  type RunMetaWhatsAppMigrationsParams = {
2818
2871
  db: MetaWhatsAppDatabase;
2819
2872
  migrate: (db: never, config: {
2820
2873
  migrationsFolder: string;
2821
2874
  migrationsTable?: string;
2822
2875
  }) => Promise<void>;
2876
+ layout?: MetaWhatsAppMigrationsLayout;
2823
2877
  };
2824
2878
  declare function runMetaWhatsAppMigrations(params: RunMetaWhatsAppMigrationsParams): Promise<void>;
2825
2879
 
@@ -2977,4 +3031,4 @@ declare class FlowMediaIdRepository implements FlowMediaIdStore {
2977
3031
  }): Promise<void>;
2978
3032
  }
2979
3033
 
2980
- export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, type CountInboundLocationsParams, type CountInboundLocationsResult, CountInboundLocationsUseCase, type CreateFlowGraphParams, CreateFlowGraphUseCase, type CreateMetaWhatsAppModuleParams, type CreateSendMediaActionParams, type CreateSendProductListActionParams, DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS, type DeleteConversationParams, type DeleteConversationResult, DeleteConversationUseCase, DeleteFlowGraphUseCase, DocumentRepository, type DocumentRow, type DrizzleMigrateFunction, type ExportConversationParams, type ExportConversationResult, ExportConversationUseCase, FlowGraphCache, FlowGraphRepository, type FlowGraphRow, FlowInterpreter, type FlowMediaIdCache, FlowMediaIdRepository, type FlowMediaIdStore, type FlowMediaLocation, FlowMediaRepository, type FlowMediaRow, type FlowMediaTranscriptLogger, type FlowRunResult, type FlowStepInput, type FlowStepResult, GetFlowGraphUseCase, GetLiveFlowPositionsUseCase, INBOUND_LOCATION_CONTENT, type InboundDispatchJob, type InboundDispatchQueueInterface, InboundEffectsDispatcher, type InboundMediaDescriptor, type InboundMessageEffectsJob, type InboundStatusEffectsJob, type IngestInboundMediaParams, type IngestInboundMediaResult, IngestInboundMediaUseCase, type IngestTranscriptionOptions, type InsertMessageParams, InvalidFlowGraphError, type LinkDocumentParams, type ListCompanyDocumentsParams, ListCompanyDocumentsUseCase, type ListConversationDocumentsParams, ListConversationDocumentsUseCase, type ListConversationsFilters, type ListConversationsParams, ListConversationsUseCase, type ListDocumentsParams, type ListDocumentsResult, ListFlowGraphsUseCase, type ListMessagesParams, ListMessagesUseCase, type LogMessageParams, LogMessageUseCase, META_WHATSAPP_MIGRATIONS_TABLE, type MessageModerator, MessageRepository, type MessageRow, type MetaWhatsAppDatabase, type MetaWhatsAppModule, type MetaWhatsAppModuleConfig, type MetaWhatsAppModuleFeatures, type MetaWhatsAppModuleProviders, type MetaWhatsAppTranscriptionConfig, type NewDocumentRow, type NewFlowGraphRow, type NewFlowMediaRow, type NewMessageRow, type NewSessionRow, type NewSettingsRow, type NonceStoreInterface, OptimisticLockError, PRODUCT_LIST_LIMIT, type PreviewMediaSupport, ProcessInboundDispatchUseCase, type PurgeExpiredDocumentsParams, type PurgeExpiredDocumentsResult, PurgeExpiredDocumentsUseCase, type RealtimeRelay, type ReceiveWebhookParams, type ReceiveWebhookResult, ReceiveWebhookUseCase, type RedactInboundLocationsParams, type RedactInboundLocationsResult, RedactInboundLocationsUseCase, type ReleaseConversationParams, ReleaseConversationUseCase, type ListMessagesParams$1 as RepositoryListMessagesParams, type ResolveTranscriptionPolicyDependencies, type RunMetaWhatsAppMigrationsParams, type SaveFlowGraphParams, SaveFlowGraphUseCase, type SaveTranscriptionByWaMessageIdParams, type SaveTranscriptionParams, type SendMediaParams, SendMessageUseCase, type SendTemplateParams, type SendTextParams, SessionRepository, type SessionRow, SettingsRepository, type SettingsRow, SseHub, type SseListener, type StorePreviewMediaParams, type StorePreviewMediaResult, StorePreviewMediaUseCase, TRANSCRIPTION_MODE, TRANSCRIPTION_STATUS, type TakeoverConversationParams, TakeoverConversationUseCase, type TicketStoreInterface, type TranscribeAudioDependencies, type TranscribeAudioParams, type TranscribeAudioResult, TranscribeAudioUseCase, type TranscriptionPolicy, type TranscriptionPolicyDefaults, type TranscriptionPolicyResolver, type TranscriptionStatus, type UpdateFlowMediaParams, WhatsAppChannelAdapter, buildInboundJobId, claimWebhookDelivery, confirmWebhookDelivery, createMetaWhatsAppModule, createSendMediaAction, createSendProductListAction, createTranscriptionPolicyResolver, documents, extractMediaDescriptor, flowGraphs, flowMedia, isAudioMimeType, isRetriableTranscriptionError, isUnsupportedTranscriptionError, issueSseTicket, messages, metaWhatsAppMigrationsFolder, metaWhatsAppSchema, redeemSseTicket, resolveFailureStatus, runMetaWhatsAppMigrations, sessions, settings, toSessionContract, transcriptionRetryAfterSeconds, verifyWebhookChallenge, verifyWebhookSignature };
3034
+ export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, type CountInboundLocationsParams, type CountInboundLocationsResult, CountInboundLocationsUseCase, type CreateFlowGraphParams, CreateFlowGraphUseCase, type CreateMetaWhatsAppModuleParams, type CreateSendMediaActionParams, type CreateSendProductListActionParams, DEFAULT_FALLBACK_LIST_LABEL, DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS, type DeleteConversationParams, type DeleteConversationResult, DeleteConversationUseCase, DeleteFlowGraphUseCase, DocumentRepository, type DocumentRow, type DrizzleMigrateFunction, type ExportConversationParams, type ExportConversationResult, ExportConversationUseCase, FlowGraphCache, FlowGraphRepository, type FlowGraphRow, FlowInterpreter, type FlowMediaIdCache, FlowMediaIdRepository, type FlowMediaIdStore, type FlowMediaLocation, FlowMediaRepository, type FlowMediaRow, type FlowMediaTranscriptLogger, type FlowRunResult, type FlowStepInput, type FlowStepResult, GetFlowGraphUseCase, GetLiveFlowPositionsUseCase, INBOUND_LOCATION_CONTENT, type InboundDispatchJob, type InboundDispatchQueueInterface, InboundEffectsDispatcher, type InboundMediaDescriptor, type InboundMessageEffectsJob, type InboundStatusEffectsJob, type IngestInboundMediaParams, type IngestInboundMediaResult, IngestInboundMediaUseCase, type IngestTranscriptionOptions, type InsertMessageParams, InvalidFlowGraphError, type LinkDocumentParams, type ListCompanyDocumentsParams, ListCompanyDocumentsUseCase, type ListConversationDocumentsParams, ListConversationDocumentsUseCase, type ListConversationsFilters, type ListConversationsParams, ListConversationsUseCase, type ListDocumentsParams, type ListDocumentsResult, ListFlowGraphsUseCase, type ListMessagesParams, ListMessagesUseCase, type LogMessageParams, LogMessageUseCase, META_WHATSAPP_MIGRATIONS_TABLE, type MessageModerator, MessageRepository, type MessageRow, type MetaWhatsAppDatabase, type MetaWhatsAppMigrationsFolderParams, type MetaWhatsAppMigrationsLayout, type MetaWhatsAppModule, type MetaWhatsAppModuleConfig, type MetaWhatsAppModuleFeatures, type MetaWhatsAppModuleProviders, type MetaWhatsAppTranscriptionConfig, type NewDocumentRow, type NewFlowGraphRow, type NewFlowMediaRow, type NewMessageRow, type NewSessionRow, type NewSettingsRow, type NonceStoreInterface, OptimisticLockError, PRODUCT_LIST_LIMIT, type PreviewMediaSupport, ProcessInboundDispatchUseCase, type PurgeExpiredDocumentsParams, type PurgeExpiredDocumentsResult, PurgeExpiredDocumentsUseCase, type RealtimeRelay, type ReceiveWebhookParams, type ReceiveWebhookResult, ReceiveWebhookUseCase, type RedactInboundLocationsParams, type RedactInboundLocationsResult, RedactInboundLocationsUseCase, type ReleaseConversationParams, ReleaseConversationUseCase, type ListMessagesParams$1 as RepositoryListMessagesParams, type RequestHumanConversationParams, RequestHumanConversationUseCase, type ResolveTranscriptionPolicyDependencies, type RunMetaWhatsAppMigrationsParams, type SaveFlowGraphParams, SaveFlowGraphUseCase, type SaveTranscriptionByWaMessageIdParams, type SaveTranscriptionParams, type SendInteractiveParams, type SendMediaParams, SendMessageUseCase, type SendTemplateParams, type SendTextParams, SessionRepository, type SessionRow, SettingsRepository, type SettingsRow, SseHub, type SseListener, type StorePreviewMediaParams, type StorePreviewMediaResult, StorePreviewMediaUseCase, TRANSCRIPTION_MODE, TRANSCRIPTION_STATUS, type TakeoverConversationParams, TakeoverConversationUseCase, type TicketStoreInterface, type TranscribeAudioDependencies, type TranscribeAudioParams, type TranscribeAudioResult, TranscribeAudioUseCase, type TranscriptionPolicy, type TranscriptionPolicyDefaults, type TranscriptionPolicyResolver, type TranscriptionStatus, type UpdateFlowMediaParams, WhatsAppChannelAdapter, buildInboundJobId, claimWebhookDelivery, confirmWebhookDelivery, createMetaWhatsAppModule, createSendMediaAction, createSendProductListAction, createTranscriptionPolicyResolver, documents, extractMediaDescriptor, flowGraphs, flowMedia, isAudioMimeType, isRetriableTranscriptionError, isUnsupportedTranscriptionError, issueSseTicket, messages, metaWhatsAppMigrationsFolder, metaWhatsAppSchema, redeemSseTicket, resolveFailureStatus, runMetaWhatsAppMigrations, sessions, settings, toSessionContract, transcriptionRetryAfterSeconds, verifyWebhookChallenge, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
2
  import { PgAsyncDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
3
3
  import * as _adatechnology_meta_whatsapp_contracts from '@adatechnology/meta-whatsapp-contracts';
4
- import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, WhatsAppStatusError, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort, SendChannelMediaParams } from '@adatechnology/meta-whatsapp-contracts';
4
+ import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, WhatsAppStatusError, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, InteractiveMessage, MetaWhatsAppHooks, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, SubjectResolverInterface, CatalogPort, SendChannelMediaParams, ChannelInteractiveListParams, ChannelInteractiveButtonsParams } from '@adatechnology/meta-whatsapp-contracts';
5
5
  export { PREVIEW_MEDIA_ID_PREFIX, TranscriptionMode, resolvePreviewUploadId, toPreviewMediaId } from '@adatechnology/meta-whatsapp-contracts';
6
6
  import { WhatsAppMessageProvider } from '@adatechnology/meta-whatsapp-provider';
7
7
  export { WEBHOOK_CLAIM_TTL_SECONDS, WEBHOOK_NONCE_TTL_SECONDS } from '@adatechnology/meta-graph-core';
@@ -1746,6 +1746,8 @@ declare class DocumentRepository {
1746
1746
  deleteById(companyId: string, id: string): Promise<void>;
1747
1747
  }
1748
1748
 
1749
+ /** Rótulo da lista quando o canal não sabe enviar botão e os botões viram lista. */
1750
+ declare const DEFAULT_FALLBACK_LIST_LABEL = "Op\u00E7\u00F5es";
1749
1751
  type SendTextParams = {
1750
1752
  companyId: string;
1751
1753
  whatsappNumber: string;
@@ -1775,6 +1777,20 @@ type SendTemplateParams = {
1775
1777
  agentUserId?: string;
1776
1778
  startState: SessionState;
1777
1779
  };
1780
+ type SendInteractiveParams = {
1781
+ companyId: string;
1782
+ whatsappNumber: string;
1783
+ /** Botões (até 3) ou lista (até 10 linhas em até 10 seções). Validado contra `WHATSAPP_CHOICE_LIMIT`. */
1784
+ interactive: InteractiveMessage;
1785
+ sender: 'bot' | 'agent';
1786
+ agentUserId?: string;
1787
+ startState: SessionState;
1788
+ /**
1789
+ * Rótulo da lista quando `interactive.kind === 'buttons'` e o canal não implementa
1790
+ * `sendInteractiveButtons` — os botões saem como lista. Padrão `DEFAULT_FALLBACK_LIST_LABEL`.
1791
+ */
1792
+ fallbackListLabel?: string;
1793
+ };
1778
1794
  declare class SendMessageUseCase {
1779
1795
  private readonly channel;
1780
1796
  private readonly sessionRepository;
@@ -1785,6 +1801,16 @@ declare class SendMessageUseCase {
1785
1801
  private assertWithinWindow;
1786
1802
  sendText(params: SendTextParams): Promise<MessageRow | undefined>;
1787
1803
  sendMedia(params: SendMediaParams): Promise<MessageRow | undefined>;
1804
+ /**
1805
+ * Botões ou lista, pelo mesmo caminho do `sendText`: janela, envio, transcript (idempotente pelo
1806
+ * `waMessageId`). Os limites da Meta são conferidos ANTES de tudo — mensagem fora do teto a Graph
1807
+ * API recusa inteira, e o erro local (`InteractiveLimitExceededError`) diz qual campo corrigir.
1808
+ *
1809
+ * O transcript guarda `type: 'interactive'`, o corpo em `content` e a mensagem inteira (ids e
1810
+ * títulos das opções) em `payload.interactive`, para o histórico mostrar o que foi oferecido.
1811
+ */
1812
+ sendInteractive(params: SendInteractiveParams): Promise<MessageRow | undefined>;
1813
+ private sendInteractiveThroughChannel;
1788
1814
  sendTemplate(params: SendTemplateParams): Promise<MessageRow | undefined>;
1789
1815
  }
1790
1816
 
@@ -1792,25 +1818,53 @@ type TakeoverConversationParams = {
1792
1818
  companyId: string;
1793
1819
  whatsappNumber: string;
1794
1820
  agentUserId: string;
1821
+ /**
1822
+ * Quem executou a ação, quando não é o próprio atendente (ex.: supervisor atribuindo a conversa a
1823
+ * outra pessoa). Omitido, o ator é `agentUserId`.
1824
+ */
1825
+ actorId?: string;
1795
1826
  };
1796
1827
  declare class TakeoverConversationUseCase {
1797
1828
  private readonly sessionRepository;
1798
1829
  private readonly realtime?;
1799
- constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined);
1830
+ private readonly hooks?;
1831
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onConversationModeChanged"> | undefined);
1800
1832
  execute(params: TakeoverConversationParams): Promise<void>;
1801
1833
  }
1802
1834
 
1803
1835
  type ReleaseConversationParams = {
1804
1836
  companyId: string;
1805
1837
  whatsappNumber: string;
1838
+ /** Quem devolveu a conversa ao bot. Omitido, `null` — o próprio sistema (ex.: job de inatividade). */
1839
+ actorId?: string | null;
1806
1840
  };
1807
1841
  declare class ReleaseConversationUseCase {
1808
1842
  private readonly sessionRepository;
1809
1843
  private readonly realtime?;
1810
- constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined);
1844
+ private readonly hooks?;
1845
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onConversationModeChanged"> | undefined);
1811
1846
  execute(params: ReleaseConversationParams): Promise<void>;
1812
1847
  }
1813
1848
 
1849
+ type RequestHumanConversationParams = {
1850
+ companyId: string;
1851
+ whatsappNumber: string;
1852
+ /** Quem pediu. Omitido, `null` — o cliente pelo menu ou o bot decidindo encaminhar. */
1853
+ actorId?: string | null;
1854
+ };
1855
+ /**
1856
+ * Coloca a conversa na fila "aguardando atendimento" (`humanRequestedAt`) sem tirá-la do bot: quem
1857
+ * assume é o `takeover`. Dispara `onHumanRequested` (o host decide como avisar a equipe) e
1858
+ * `onConversationModeChanged` com `kind: 'human-requested'` (trilha de auditoria).
1859
+ */
1860
+ declare class RequestHumanConversationUseCase {
1861
+ private readonly sessionRepository;
1862
+ private readonly realtime?;
1863
+ private readonly hooks?;
1864
+ constructor(sessionRepository: SessionRepository, realtime?: RealtimeNotifierInterface | undefined, hooks?: Pick<MetaWhatsAppHooks, "onHumanRequested" | "onConversationModeChanged"> | undefined);
1865
+ execute(params: RequestHumanConversationParams): Promise<void>;
1866
+ }
1867
+
1814
1868
  type ListConversationsParams = {
1815
1869
  companyId: string;
1816
1870
  filters?: ListConversationsFilters;
@@ -2315,7 +2369,8 @@ declare class InboundEffectsDispatcher {
2315
2369
  */
2316
2370
  declare class ProcessInboundDispatchUseCase {
2317
2371
  private readonly dispatcher;
2318
- constructor(dispatcher: InboundEffectsDispatcher);
2372
+ private readonly hooks?;
2373
+ constructor(dispatcher: InboundEffectsDispatcher, hooks?: Pick<MetaWhatsAppHooks, "onInboundEffectRejected"> | undefined);
2319
2374
  execute(job: InboundDispatchJob): Promise<void>;
2320
2375
  }
2321
2376
 
@@ -2633,6 +2688,13 @@ interface MetaWhatsAppTranscriptionConfig {
2633
2688
  languageHint?: string;
2634
2689
  }
2635
2690
  interface MetaWhatsAppModuleProviders {
2691
+ /**
2692
+ * Fila durável para os efeitos do webhook (hooks, realtime). Ausente, rodam dentro da requisição,
2693
+ * como sempre. Presente, o webhook só persiste e enfileira; o worker do host chama
2694
+ * `webhook.processInboundDispatch.execute(job)`. Ver docs/webhook-durability.md — qualquer fila
2695
+ * com durabilidade e retentativa serve, inclusive uma tabela no Postgres.
2696
+ */
2697
+ inboundQueue?: InboundDispatchQueueInterface;
2636
2698
  objectStorage?: ObjectStorageInterface;
2637
2699
  cache?: CacheInterface;
2638
2700
  realtime?: RealtimeNotifierInterface;
@@ -2662,6 +2724,7 @@ declare function createMetaWhatsAppModule(params: CreateMetaWhatsAppModuleParams
2662
2724
  send: SendMessageUseCase;
2663
2725
  takeover: TakeoverConversationUseCase;
2664
2726
  release: ReleaseConversationUseCase;
2727
+ requestHuman: RequestHumanConversationUseCase;
2665
2728
  list: ListConversationsUseCase;
2666
2729
  listMessages: ListMessagesUseCase;
2667
2730
  listDocuments: ListConversationDocumentsUseCase;
@@ -2698,6 +2761,7 @@ declare function createMetaWhatsAppModule(params: CreateMetaWhatsAppModuleParams
2698
2761
  token: string | null;
2699
2762
  challenge: string | null;
2700
2763
  }) => string;
2764
+ processInboundDispatch: ProcessInboundDispatchUseCase;
2701
2765
  };
2702
2766
  flows: {
2703
2767
  interpreter: FlowInterpreter;
@@ -2761,25 +2825,10 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
2761
2825
  }): Promise<{
2762
2826
  externalMessageId: string | null;
2763
2827
  }>;
2764
- sendInteractiveList(params: {
2765
- to: string;
2766
- body: string;
2767
- buttonLabel: string;
2768
- rows: {
2769
- id: string;
2770
- title: string;
2771
- }[];
2772
- }): Promise<{
2828
+ sendInteractiveList(params: ChannelInteractiveListParams): Promise<{
2773
2829
  externalMessageId: string | null;
2774
2830
  }>;
2775
- sendInteractiveButtons(params: {
2776
- to: string;
2777
- body: string;
2778
- buttons: {
2779
- id: string;
2780
- title: string;
2781
- }[];
2782
- }): Promise<{
2831
+ sendInteractiveButtons(params: ChannelInteractiveButtonsParams): Promise<{
2783
2832
  externalMessageId: string | null;
2784
2833
  }>;
2785
2834
  sendProductList(params: {
@@ -2813,13 +2862,18 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
2813
2862
  declare const INBOUND_LOCATION_CONTENT = "\uD83D\uDCCD Localiza\u00E7\u00E3o";
2814
2863
 
2815
2864
  declare const META_WHATSAPP_MIGRATIONS_TABLE = "meta_whatsapp_migrations";
2816
- declare function metaWhatsAppMigrationsFolder(): string;
2865
+ type MetaWhatsAppMigrationsLayout = 'v1' | 'journal';
2866
+ type MetaWhatsAppMigrationsFolderParams = {
2867
+ readonly layout?: MetaWhatsAppMigrationsLayout;
2868
+ };
2869
+ declare function metaWhatsAppMigrationsFolder(params?: MetaWhatsAppMigrationsFolderParams): string;
2817
2870
  type RunMetaWhatsAppMigrationsParams = {
2818
2871
  db: MetaWhatsAppDatabase;
2819
2872
  migrate: (db: never, config: {
2820
2873
  migrationsFolder: string;
2821
2874
  migrationsTable?: string;
2822
2875
  }) => Promise<void>;
2876
+ layout?: MetaWhatsAppMigrationsLayout;
2823
2877
  };
2824
2878
  declare function runMetaWhatsAppMigrations(params: RunMetaWhatsAppMigrationsParams): Promise<void>;
2825
2879
 
@@ -2977,4 +3031,4 @@ declare class FlowMediaIdRepository implements FlowMediaIdStore {
2977
3031
  }): Promise<void>;
2978
3032
  }
2979
3033
 
2980
- export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, type CountInboundLocationsParams, type CountInboundLocationsResult, CountInboundLocationsUseCase, type CreateFlowGraphParams, CreateFlowGraphUseCase, type CreateMetaWhatsAppModuleParams, type CreateSendMediaActionParams, type CreateSendProductListActionParams, DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS, type DeleteConversationParams, type DeleteConversationResult, DeleteConversationUseCase, DeleteFlowGraphUseCase, DocumentRepository, type DocumentRow, type DrizzleMigrateFunction, type ExportConversationParams, type ExportConversationResult, ExportConversationUseCase, FlowGraphCache, FlowGraphRepository, type FlowGraphRow, FlowInterpreter, type FlowMediaIdCache, FlowMediaIdRepository, type FlowMediaIdStore, type FlowMediaLocation, FlowMediaRepository, type FlowMediaRow, type FlowMediaTranscriptLogger, type FlowRunResult, type FlowStepInput, type FlowStepResult, GetFlowGraphUseCase, GetLiveFlowPositionsUseCase, INBOUND_LOCATION_CONTENT, type InboundDispatchJob, type InboundDispatchQueueInterface, InboundEffectsDispatcher, type InboundMediaDescriptor, type InboundMessageEffectsJob, type InboundStatusEffectsJob, type IngestInboundMediaParams, type IngestInboundMediaResult, IngestInboundMediaUseCase, type IngestTranscriptionOptions, type InsertMessageParams, InvalidFlowGraphError, type LinkDocumentParams, type ListCompanyDocumentsParams, ListCompanyDocumentsUseCase, type ListConversationDocumentsParams, ListConversationDocumentsUseCase, type ListConversationsFilters, type ListConversationsParams, ListConversationsUseCase, type ListDocumentsParams, type ListDocumentsResult, ListFlowGraphsUseCase, type ListMessagesParams, ListMessagesUseCase, type LogMessageParams, LogMessageUseCase, META_WHATSAPP_MIGRATIONS_TABLE, type MessageModerator, MessageRepository, type MessageRow, type MetaWhatsAppDatabase, type MetaWhatsAppModule, type MetaWhatsAppModuleConfig, type MetaWhatsAppModuleFeatures, type MetaWhatsAppModuleProviders, type MetaWhatsAppTranscriptionConfig, type NewDocumentRow, type NewFlowGraphRow, type NewFlowMediaRow, type NewMessageRow, type NewSessionRow, type NewSettingsRow, type NonceStoreInterface, OptimisticLockError, PRODUCT_LIST_LIMIT, type PreviewMediaSupport, ProcessInboundDispatchUseCase, type PurgeExpiredDocumentsParams, type PurgeExpiredDocumentsResult, PurgeExpiredDocumentsUseCase, type RealtimeRelay, type ReceiveWebhookParams, type ReceiveWebhookResult, ReceiveWebhookUseCase, type RedactInboundLocationsParams, type RedactInboundLocationsResult, RedactInboundLocationsUseCase, type ReleaseConversationParams, ReleaseConversationUseCase, type ListMessagesParams$1 as RepositoryListMessagesParams, type ResolveTranscriptionPolicyDependencies, type RunMetaWhatsAppMigrationsParams, type SaveFlowGraphParams, SaveFlowGraphUseCase, type SaveTranscriptionByWaMessageIdParams, type SaveTranscriptionParams, type SendMediaParams, SendMessageUseCase, type SendTemplateParams, type SendTextParams, SessionRepository, type SessionRow, SettingsRepository, type SettingsRow, SseHub, type SseListener, type StorePreviewMediaParams, type StorePreviewMediaResult, StorePreviewMediaUseCase, TRANSCRIPTION_MODE, TRANSCRIPTION_STATUS, type TakeoverConversationParams, TakeoverConversationUseCase, type TicketStoreInterface, type TranscribeAudioDependencies, type TranscribeAudioParams, type TranscribeAudioResult, TranscribeAudioUseCase, type TranscriptionPolicy, type TranscriptionPolicyDefaults, type TranscriptionPolicyResolver, type TranscriptionStatus, type UpdateFlowMediaParams, WhatsAppChannelAdapter, buildInboundJobId, claimWebhookDelivery, confirmWebhookDelivery, createMetaWhatsAppModule, createSendMediaAction, createSendProductListAction, createTranscriptionPolicyResolver, documents, extractMediaDescriptor, flowGraphs, flowMedia, isAudioMimeType, isRetriableTranscriptionError, isUnsupportedTranscriptionError, issueSseTicket, messages, metaWhatsAppMigrationsFolder, metaWhatsAppSchema, redeemSseTicket, resolveFailureStatus, runMetaWhatsAppMigrations, sessions, settings, toSessionContract, transcriptionRetryAfterSeconds, verifyWebhookChallenge, verifyWebhookSignature };
3034
+ export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, type CountInboundLocationsParams, type CountInboundLocationsResult, CountInboundLocationsUseCase, type CreateFlowGraphParams, CreateFlowGraphUseCase, type CreateMetaWhatsAppModuleParams, type CreateSendMediaActionParams, type CreateSendProductListActionParams, DEFAULT_FALLBACK_LIST_LABEL, DEFAULT_FLOW_GRAPH_CACHE_TTL_SECONDS, type DeleteConversationParams, type DeleteConversationResult, DeleteConversationUseCase, DeleteFlowGraphUseCase, DocumentRepository, type DocumentRow, type DrizzleMigrateFunction, type ExportConversationParams, type ExportConversationResult, ExportConversationUseCase, FlowGraphCache, FlowGraphRepository, type FlowGraphRow, FlowInterpreter, type FlowMediaIdCache, FlowMediaIdRepository, type FlowMediaIdStore, type FlowMediaLocation, FlowMediaRepository, type FlowMediaRow, type FlowMediaTranscriptLogger, type FlowRunResult, type FlowStepInput, type FlowStepResult, GetFlowGraphUseCase, GetLiveFlowPositionsUseCase, INBOUND_LOCATION_CONTENT, type InboundDispatchJob, type InboundDispatchQueueInterface, InboundEffectsDispatcher, type InboundMediaDescriptor, type InboundMessageEffectsJob, type InboundStatusEffectsJob, type IngestInboundMediaParams, type IngestInboundMediaResult, IngestInboundMediaUseCase, type IngestTranscriptionOptions, type InsertMessageParams, InvalidFlowGraphError, type LinkDocumentParams, type ListCompanyDocumentsParams, ListCompanyDocumentsUseCase, type ListConversationDocumentsParams, ListConversationDocumentsUseCase, type ListConversationsFilters, type ListConversationsParams, ListConversationsUseCase, type ListDocumentsParams, type ListDocumentsResult, ListFlowGraphsUseCase, type ListMessagesParams, ListMessagesUseCase, type LogMessageParams, LogMessageUseCase, META_WHATSAPP_MIGRATIONS_TABLE, type MessageModerator, MessageRepository, type MessageRow, type MetaWhatsAppDatabase, type MetaWhatsAppMigrationsFolderParams, type MetaWhatsAppMigrationsLayout, type MetaWhatsAppModule, type MetaWhatsAppModuleConfig, type MetaWhatsAppModuleFeatures, type MetaWhatsAppModuleProviders, type MetaWhatsAppTranscriptionConfig, type NewDocumentRow, type NewFlowGraphRow, type NewFlowMediaRow, type NewMessageRow, type NewSessionRow, type NewSettingsRow, type NonceStoreInterface, OptimisticLockError, PRODUCT_LIST_LIMIT, type PreviewMediaSupport, ProcessInboundDispatchUseCase, type PurgeExpiredDocumentsParams, type PurgeExpiredDocumentsResult, PurgeExpiredDocumentsUseCase, type RealtimeRelay, type ReceiveWebhookParams, type ReceiveWebhookResult, ReceiveWebhookUseCase, type RedactInboundLocationsParams, type RedactInboundLocationsResult, RedactInboundLocationsUseCase, type ReleaseConversationParams, ReleaseConversationUseCase, type ListMessagesParams$1 as RepositoryListMessagesParams, type RequestHumanConversationParams, RequestHumanConversationUseCase, type ResolveTranscriptionPolicyDependencies, type RunMetaWhatsAppMigrationsParams, type SaveFlowGraphParams, SaveFlowGraphUseCase, type SaveTranscriptionByWaMessageIdParams, type SaveTranscriptionParams, type SendInteractiveParams, type SendMediaParams, SendMessageUseCase, type SendTemplateParams, type SendTextParams, SessionRepository, type SessionRow, SettingsRepository, type SettingsRow, SseHub, type SseListener, type StorePreviewMediaParams, type StorePreviewMediaResult, StorePreviewMediaUseCase, TRANSCRIPTION_MODE, TRANSCRIPTION_STATUS, type TakeoverConversationParams, TakeoverConversationUseCase, type TicketStoreInterface, type TranscribeAudioDependencies, type TranscribeAudioParams, type TranscribeAudioResult, TranscribeAudioUseCase, type TranscriptionPolicy, type TranscriptionPolicyDefaults, type TranscriptionPolicyResolver, type TranscriptionStatus, type UpdateFlowMediaParams, WhatsAppChannelAdapter, buildInboundJobId, claimWebhookDelivery, confirmWebhookDelivery, createMetaWhatsAppModule, createSendMediaAction, createSendProductListAction, createTranscriptionPolicyResolver, documents, extractMediaDescriptor, flowGraphs, flowMedia, isAudioMimeType, isRetriableTranscriptionError, isUnsupportedTranscriptionError, issueSseTicket, messages, metaWhatsAppMigrationsFolder, metaWhatsAppSchema, redeemSseTicket, resolveFailureStatus, runMetaWhatsAppMigrations, sessions, settings, toSessionContract, transcriptionRetryAfterSeconds, verifyWebhookChallenge, verifyWebhookSignature };