@adatechnology/meta-whatsapp-module 0.2.0-rc.30 → 0.2.0-rc.31
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 +181 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -21
- package/dist/index.d.ts +100 -21
- package/dist/index.js +181 -16
- package/dist/index.js.map +1 -1
- package/dist/migrations/0010_flow_media_meta_ids.sql +10 -0
- package/package.json +3 -3
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 { PgDatabase, 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, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort } from '@adatechnology/meta-whatsapp-contracts';
|
|
4
|
+
import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort, SendChannelMediaParams } 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';
|
|
@@ -1357,6 +1357,25 @@ declare const flowMedia: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
1357
1357
|
identity: undefined;
|
|
1358
1358
|
generated: undefined;
|
|
1359
1359
|
}, {}, {}>;
|
|
1360
|
+
metaMediaIds: drizzle_orm_pg_core.PgColumn<{
|
|
1361
|
+
name: "meta_media_ids";
|
|
1362
|
+
tableName: "flow_media";
|
|
1363
|
+
dataType: "json";
|
|
1364
|
+
columnType: "PgJsonb";
|
|
1365
|
+
data: Record<string, string>;
|
|
1366
|
+
driverParam: unknown;
|
|
1367
|
+
notNull: true;
|
|
1368
|
+
hasDefault: true;
|
|
1369
|
+
isPrimaryKey: false;
|
|
1370
|
+
isAutoincrement: false;
|
|
1371
|
+
hasRuntimeDefault: false;
|
|
1372
|
+
enumValues: undefined;
|
|
1373
|
+
baseColumn: never;
|
|
1374
|
+
identity: undefined;
|
|
1375
|
+
generated: undefined;
|
|
1376
|
+
}, {}, {
|
|
1377
|
+
$type: Record<string, string>;
|
|
1378
|
+
}>;
|
|
1360
1379
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1361
1380
|
name: "created_at";
|
|
1362
1381
|
tableName: "flow_media";
|
|
@@ -2444,6 +2463,8 @@ type ReceiveWebhookResult = {
|
|
|
2444
2463
|
messagesProcessed: number;
|
|
2445
2464
|
statusesProcessed: number;
|
|
2446
2465
|
ignoredForeignNumber: number;
|
|
2466
|
+
accountEventsProcessed: number;
|
|
2467
|
+
unhandledEvents: number;
|
|
2447
2468
|
};
|
|
2448
2469
|
declare class ReceiveWebhookUseCase {
|
|
2449
2470
|
private readonly params;
|
|
@@ -2465,6 +2486,7 @@ declare class ReceiveWebhookUseCase {
|
|
|
2465
2486
|
});
|
|
2466
2487
|
private readonly dispatcher;
|
|
2467
2488
|
execute(input: ReceiveWebhookParams): Promise<ReceiveWebhookResult>;
|
|
2489
|
+
private handleAccountEvent;
|
|
2468
2490
|
private handleMessage;
|
|
2469
2491
|
private handleStatus;
|
|
2470
2492
|
private dispatch;
|
|
@@ -2836,14 +2858,9 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
|
|
|
2836
2858
|
sendText(to: string, body: string): Promise<{
|
|
2837
2859
|
externalMessageId: string | null;
|
|
2838
2860
|
}>;
|
|
2839
|
-
sendMedia(params: {
|
|
2840
|
-
to: string;
|
|
2841
|
-
buffer: Buffer;
|
|
2842
|
-
mimeType: string;
|
|
2843
|
-
filename: string;
|
|
2844
|
-
caption?: string;
|
|
2845
|
-
}): Promise<{
|
|
2861
|
+
sendMedia(params: SendChannelMediaParams): Promise<{
|
|
2846
2862
|
externalMessageId: string | null;
|
|
2863
|
+
mediaId?: string | undefined;
|
|
2847
2864
|
}>;
|
|
2848
2865
|
sendTemplate(params: {
|
|
2849
2866
|
to: string;
|
|
@@ -2943,6 +2960,39 @@ declare function redeemSseTicket(store: TicketStoreInterface, ticket: string): P
|
|
|
2943
2960
|
* sem gravar o envio numa tabela que o painel dele não lê. O que a action precisa é só de um lugar
|
|
2944
2961
|
* para registrar o que saiu.
|
|
2945
2962
|
*/
|
|
2963
|
+
/**
|
|
2964
|
+
* Onde guardar o `mediaId` que a Meta devolveu para cada arquivo da biblioteca.
|
|
2965
|
+
*
|
|
2966
|
+
* Porta, e não tabela: o módulo não sabe se o host guarda isso numa coluna, no Redis ou em memória.
|
|
2967
|
+
* O que ele precisa é reaproveitar o id em vez de ressubir o mesmo binário para cada cliente que
|
|
2968
|
+
* passa pelo nó — a Meta aceita reusar por 30 dias.
|
|
2969
|
+
*/
|
|
2970
|
+
type FlowMediaIdStore = {
|
|
2971
|
+
get(params: {
|
|
2972
|
+
flowMediaId: string;
|
|
2973
|
+
senderKey: string;
|
|
2974
|
+
}): Promise<string | undefined>;
|
|
2975
|
+
set(params: {
|
|
2976
|
+
flowMediaId: string;
|
|
2977
|
+
senderKey: string;
|
|
2978
|
+
mediaId: string;
|
|
2979
|
+
}): Promise<void>;
|
|
2980
|
+
clear(params: {
|
|
2981
|
+
flowMediaId: string;
|
|
2982
|
+
senderKey: string;
|
|
2983
|
+
}): Promise<void>;
|
|
2984
|
+
};
|
|
2985
|
+
/**
|
|
2986
|
+
* O `senderKey` vem junto do store, e não solto, para não existir a forma inválida.
|
|
2987
|
+
*
|
|
2988
|
+
* O `mediaId` é escopado ao número remetente (`phone_number_id`) na Meta: cachear sem separar por
|
|
2989
|
+
* número faz o id de um número ser mandado pelo outro, e o envio falha. Exigi-lo dentro do mesmo
|
|
2990
|
+
* objeto torna "liguei o cache e esqueci o número" impossível de escrever.
|
|
2991
|
+
*/
|
|
2992
|
+
type FlowMediaIdCache = {
|
|
2993
|
+
readonly store: FlowMediaIdStore;
|
|
2994
|
+
readonly senderKey: string;
|
|
2995
|
+
};
|
|
2946
2996
|
type FlowMediaTranscriptLogger = {
|
|
2947
2997
|
execute(params: LogMessageParams): Promise<unknown>;
|
|
2948
2998
|
};
|
|
@@ -2952,6 +3002,11 @@ type CreateSendMediaActionParams = {
|
|
|
2952
3002
|
getObject: NonNullable<ObjectStorageInterface['getObject']>;
|
|
2953
3003
|
};
|
|
2954
3004
|
logMessage: FlowMediaTranscriptLogger;
|
|
3005
|
+
/**
|
|
3006
|
+
* Reaproveitamento do arquivo já subido. Capacidade por ausência: sem o cache, cada envio ressobe
|
|
3007
|
+
* o binário — exatamente o comportamento anterior, sem flag para desligar.
|
|
3008
|
+
*/
|
|
3009
|
+
mediaIdCache?: FlowMediaIdCache;
|
|
2955
3010
|
startState: SessionState;
|
|
2956
3011
|
onError?: (error: unknown, details: {
|
|
2957
3012
|
flowKey: string;
|
|
@@ -2959,18 +3014,6 @@ type CreateSendMediaActionParams = {
|
|
|
2959
3014
|
uploadId: string;
|
|
2960
3015
|
}) => void;
|
|
2961
3016
|
};
|
|
2962
|
-
/**
|
|
2963
|
-
* Action `send_media`: ao passar pelo nó, envia os arquivos que a biblioteca tem anexados a ele.
|
|
2964
|
-
*
|
|
2965
|
-
* É a única action built-in que o módulo implementa de ponta a ponta — as outras
|
|
2966
|
-
* (`handoff`, `send_product_list`) dependem de regra de negócio do produto. Esta não: "mandar
|
|
2967
|
-
* estes arquivos ao chegar aqui" é comportamento de canal, e replicá-la em cada host seria
|
|
2968
|
-
* copiar o mesmo código com os mesmos bugs.
|
|
2969
|
-
*
|
|
2970
|
-
* O nó não guarda os arquivos em `actionParams` de propósito. Se guardasse, trocar o material
|
|
2971
|
-
* exigiria editar e republicar o grafo — e o ponto todo é o contrário: quem cuida do conteúdo
|
|
2972
|
-
* troca o arquivo na biblioteca e o fluxo continua igual.
|
|
2973
|
-
*/
|
|
2974
3017
|
declare function createSendMediaAction(params: CreateSendMediaActionParams): FlowActionHandler;
|
|
2975
3018
|
|
|
2976
3019
|
/** Tetos da Meta para `interactive.product_list`. Acima disso a mensagem inteira é recusada. */
|
|
@@ -3001,4 +3044,40 @@ type CreateSendProductListActionParams = {
|
|
|
3001
3044
|
*/
|
|
3002
3045
|
declare function createSendProductListAction(params: CreateSendProductListActionParams): FlowActionHandler;
|
|
3003
3046
|
|
|
3004
|
-
|
|
3047
|
+
/**
|
|
3048
|
+
* Store padrão do cache de `mediaId`, na própria linha da biblioteca de mídia.
|
|
3049
|
+
*
|
|
3050
|
+
* A porta `FlowMediaIdStore` existe para o host poder escolher Redis ou memória. Esta é a
|
|
3051
|
+
* implementação que o módulo já traz pronta, para o caso comum não exigir nada de quem instala: a
|
|
3052
|
+
* tabela é do módulo, a coluna é do módulo, e sem isso todo host reescreveria o mesmo repositório.
|
|
3053
|
+
*
|
|
3054
|
+
* Um mapa por `phone_number_id` na mesma linha, e não uma tabela à parte: o id não existe sem o
|
|
3055
|
+
* arquivo, morre com ele, e a linha é lida de qualquer forma no envio.
|
|
3056
|
+
*/
|
|
3057
|
+
declare class FlowMediaIdRepository implements FlowMediaIdStore {
|
|
3058
|
+
private readonly db;
|
|
3059
|
+
constructor(db: MetaWhatsAppDatabase);
|
|
3060
|
+
get(params: {
|
|
3061
|
+
flowMediaId: string;
|
|
3062
|
+
senderKey: string;
|
|
3063
|
+
}): Promise<string | undefined>;
|
|
3064
|
+
/**
|
|
3065
|
+
* Grava só a chave deste número.
|
|
3066
|
+
*
|
|
3067
|
+
* `jsonb_set` no banco, e não ler-alterar-escrever na aplicação: dois clientes passando pelo nó
|
|
3068
|
+
* ao mesmo tempo com números diferentes leriam o mesmo mapa e o último gravaria por cima,
|
|
3069
|
+
* apagando o id do outro. A escrita atômica não tem essa janela.
|
|
3070
|
+
*/
|
|
3071
|
+
set(params: {
|
|
3072
|
+
flowMediaId: string;
|
|
3073
|
+
senderKey: string;
|
|
3074
|
+
mediaId: string;
|
|
3075
|
+
}): Promise<void>;
|
|
3076
|
+
/** Remove só a chave deste número — o id do outro número continua válido. */
|
|
3077
|
+
clear(params: {
|
|
3078
|
+
flowMediaId: string;
|
|
3079
|
+
senderKey: string;
|
|
3080
|
+
}): Promise<void>;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, 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, 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 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 };
|
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 { PgDatabase, 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, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort } from '@adatechnology/meta-whatsapp-contracts';
|
|
4
|
+
import { TranscriptionMode, SessionState, SessionMode, ConversationSummary, MessageDirection, MessageSender, MessageStatus, CacheInterface, FlowGraphData, FlowGraphSummary, LiveFlowPosition, WhatsAppSettings, RealtimeNotifierInterface, ChannelAdapterInterface, ObjectStorageInterface, FlowActionKind, FlowActionHandler, ConversationSession, WhatsAppMessage, WhatsAppStatus, MetaWhatsAppHooks, SubjectResolverInterface, CatalogPort, SendChannelMediaParams } 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';
|
|
@@ -1357,6 +1357,25 @@ declare const flowMedia: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
1357
1357
|
identity: undefined;
|
|
1358
1358
|
generated: undefined;
|
|
1359
1359
|
}, {}, {}>;
|
|
1360
|
+
metaMediaIds: drizzle_orm_pg_core.PgColumn<{
|
|
1361
|
+
name: "meta_media_ids";
|
|
1362
|
+
tableName: "flow_media";
|
|
1363
|
+
dataType: "json";
|
|
1364
|
+
columnType: "PgJsonb";
|
|
1365
|
+
data: Record<string, string>;
|
|
1366
|
+
driverParam: unknown;
|
|
1367
|
+
notNull: true;
|
|
1368
|
+
hasDefault: true;
|
|
1369
|
+
isPrimaryKey: false;
|
|
1370
|
+
isAutoincrement: false;
|
|
1371
|
+
hasRuntimeDefault: false;
|
|
1372
|
+
enumValues: undefined;
|
|
1373
|
+
baseColumn: never;
|
|
1374
|
+
identity: undefined;
|
|
1375
|
+
generated: undefined;
|
|
1376
|
+
}, {}, {
|
|
1377
|
+
$type: Record<string, string>;
|
|
1378
|
+
}>;
|
|
1360
1379
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1361
1380
|
name: "created_at";
|
|
1362
1381
|
tableName: "flow_media";
|
|
@@ -2444,6 +2463,8 @@ type ReceiveWebhookResult = {
|
|
|
2444
2463
|
messagesProcessed: number;
|
|
2445
2464
|
statusesProcessed: number;
|
|
2446
2465
|
ignoredForeignNumber: number;
|
|
2466
|
+
accountEventsProcessed: number;
|
|
2467
|
+
unhandledEvents: number;
|
|
2447
2468
|
};
|
|
2448
2469
|
declare class ReceiveWebhookUseCase {
|
|
2449
2470
|
private readonly params;
|
|
@@ -2465,6 +2486,7 @@ declare class ReceiveWebhookUseCase {
|
|
|
2465
2486
|
});
|
|
2466
2487
|
private readonly dispatcher;
|
|
2467
2488
|
execute(input: ReceiveWebhookParams): Promise<ReceiveWebhookResult>;
|
|
2489
|
+
private handleAccountEvent;
|
|
2468
2490
|
private handleMessage;
|
|
2469
2491
|
private handleStatus;
|
|
2470
2492
|
private dispatch;
|
|
@@ -2836,14 +2858,9 @@ declare class WhatsAppChannelAdapter implements ChannelAdapterInterface {
|
|
|
2836
2858
|
sendText(to: string, body: string): Promise<{
|
|
2837
2859
|
externalMessageId: string | null;
|
|
2838
2860
|
}>;
|
|
2839
|
-
sendMedia(params: {
|
|
2840
|
-
to: string;
|
|
2841
|
-
buffer: Buffer;
|
|
2842
|
-
mimeType: string;
|
|
2843
|
-
filename: string;
|
|
2844
|
-
caption?: string;
|
|
2845
|
-
}): Promise<{
|
|
2861
|
+
sendMedia(params: SendChannelMediaParams): Promise<{
|
|
2846
2862
|
externalMessageId: string | null;
|
|
2863
|
+
mediaId?: string | undefined;
|
|
2847
2864
|
}>;
|
|
2848
2865
|
sendTemplate(params: {
|
|
2849
2866
|
to: string;
|
|
@@ -2943,6 +2960,39 @@ declare function redeemSseTicket(store: TicketStoreInterface, ticket: string): P
|
|
|
2943
2960
|
* sem gravar o envio numa tabela que o painel dele não lê. O que a action precisa é só de um lugar
|
|
2944
2961
|
* para registrar o que saiu.
|
|
2945
2962
|
*/
|
|
2963
|
+
/**
|
|
2964
|
+
* Onde guardar o `mediaId` que a Meta devolveu para cada arquivo da biblioteca.
|
|
2965
|
+
*
|
|
2966
|
+
* Porta, e não tabela: o módulo não sabe se o host guarda isso numa coluna, no Redis ou em memória.
|
|
2967
|
+
* O que ele precisa é reaproveitar o id em vez de ressubir o mesmo binário para cada cliente que
|
|
2968
|
+
* passa pelo nó — a Meta aceita reusar por 30 dias.
|
|
2969
|
+
*/
|
|
2970
|
+
type FlowMediaIdStore = {
|
|
2971
|
+
get(params: {
|
|
2972
|
+
flowMediaId: string;
|
|
2973
|
+
senderKey: string;
|
|
2974
|
+
}): Promise<string | undefined>;
|
|
2975
|
+
set(params: {
|
|
2976
|
+
flowMediaId: string;
|
|
2977
|
+
senderKey: string;
|
|
2978
|
+
mediaId: string;
|
|
2979
|
+
}): Promise<void>;
|
|
2980
|
+
clear(params: {
|
|
2981
|
+
flowMediaId: string;
|
|
2982
|
+
senderKey: string;
|
|
2983
|
+
}): Promise<void>;
|
|
2984
|
+
};
|
|
2985
|
+
/**
|
|
2986
|
+
* O `senderKey` vem junto do store, e não solto, para não existir a forma inválida.
|
|
2987
|
+
*
|
|
2988
|
+
* O `mediaId` é escopado ao número remetente (`phone_number_id`) na Meta: cachear sem separar por
|
|
2989
|
+
* número faz o id de um número ser mandado pelo outro, e o envio falha. Exigi-lo dentro do mesmo
|
|
2990
|
+
* objeto torna "liguei o cache e esqueci o número" impossível de escrever.
|
|
2991
|
+
*/
|
|
2992
|
+
type FlowMediaIdCache = {
|
|
2993
|
+
readonly store: FlowMediaIdStore;
|
|
2994
|
+
readonly senderKey: string;
|
|
2995
|
+
};
|
|
2946
2996
|
type FlowMediaTranscriptLogger = {
|
|
2947
2997
|
execute(params: LogMessageParams): Promise<unknown>;
|
|
2948
2998
|
};
|
|
@@ -2952,6 +3002,11 @@ type CreateSendMediaActionParams = {
|
|
|
2952
3002
|
getObject: NonNullable<ObjectStorageInterface['getObject']>;
|
|
2953
3003
|
};
|
|
2954
3004
|
logMessage: FlowMediaTranscriptLogger;
|
|
3005
|
+
/**
|
|
3006
|
+
* Reaproveitamento do arquivo já subido. Capacidade por ausência: sem o cache, cada envio ressobe
|
|
3007
|
+
* o binário — exatamente o comportamento anterior, sem flag para desligar.
|
|
3008
|
+
*/
|
|
3009
|
+
mediaIdCache?: FlowMediaIdCache;
|
|
2955
3010
|
startState: SessionState;
|
|
2956
3011
|
onError?: (error: unknown, details: {
|
|
2957
3012
|
flowKey: string;
|
|
@@ -2959,18 +3014,6 @@ type CreateSendMediaActionParams = {
|
|
|
2959
3014
|
uploadId: string;
|
|
2960
3015
|
}) => void;
|
|
2961
3016
|
};
|
|
2962
|
-
/**
|
|
2963
|
-
* Action `send_media`: ao passar pelo nó, envia os arquivos que a biblioteca tem anexados a ele.
|
|
2964
|
-
*
|
|
2965
|
-
* É a única action built-in que o módulo implementa de ponta a ponta — as outras
|
|
2966
|
-
* (`handoff`, `send_product_list`) dependem de regra de negócio do produto. Esta não: "mandar
|
|
2967
|
-
* estes arquivos ao chegar aqui" é comportamento de canal, e replicá-la em cada host seria
|
|
2968
|
-
* copiar o mesmo código com os mesmos bugs.
|
|
2969
|
-
*
|
|
2970
|
-
* O nó não guarda os arquivos em `actionParams` de propósito. Se guardasse, trocar o material
|
|
2971
|
-
* exigiria editar e republicar o grafo — e o ponto todo é o contrário: quem cuida do conteúdo
|
|
2972
|
-
* troca o arquivo na biblioteca e o fluxo continua igual.
|
|
2973
|
-
*/
|
|
2974
3017
|
declare function createSendMediaAction(params: CreateSendMediaActionParams): FlowActionHandler;
|
|
2975
3018
|
|
|
2976
3019
|
/** Tetos da Meta para `interactive.product_list`. Acima disso a mensagem inteira é recusada. */
|
|
@@ -3001,4 +3044,40 @@ type CreateSendProductListActionParams = {
|
|
|
3001
3044
|
*/
|
|
3002
3045
|
declare function createSendProductListAction(params: CreateSendProductListActionParams): FlowActionHandler;
|
|
3003
3046
|
|
|
3004
|
-
|
|
3047
|
+
/**
|
|
3048
|
+
* Store padrão do cache de `mediaId`, na própria linha da biblioteca de mídia.
|
|
3049
|
+
*
|
|
3050
|
+
* A porta `FlowMediaIdStore` existe para o host poder escolher Redis ou memória. Esta é a
|
|
3051
|
+
* implementação que o módulo já traz pronta, para o caso comum não exigir nada de quem instala: a
|
|
3052
|
+
* tabela é do módulo, a coluna é do módulo, e sem isso todo host reescreveria o mesmo repositório.
|
|
3053
|
+
*
|
|
3054
|
+
* Um mapa por `phone_number_id` na mesma linha, e não uma tabela à parte: o id não existe sem o
|
|
3055
|
+
* arquivo, morre com ele, e a linha é lida de qualquer forma no envio.
|
|
3056
|
+
*/
|
|
3057
|
+
declare class FlowMediaIdRepository implements FlowMediaIdStore {
|
|
3058
|
+
private readonly db;
|
|
3059
|
+
constructor(db: MetaWhatsAppDatabase);
|
|
3060
|
+
get(params: {
|
|
3061
|
+
flowMediaId: string;
|
|
3062
|
+
senderKey: string;
|
|
3063
|
+
}): Promise<string | undefined>;
|
|
3064
|
+
/**
|
|
3065
|
+
* Grava só a chave deste número.
|
|
3066
|
+
*
|
|
3067
|
+
* `jsonb_set` no banco, e não ler-alterar-escrever na aplicação: dois clientes passando pelo nó
|
|
3068
|
+
* ao mesmo tempo com números diferentes leriam o mesmo mapa e o último gravaria por cima,
|
|
3069
|
+
* apagando o id do outro. A escrita atômica não tem essa janela.
|
|
3070
|
+
*/
|
|
3071
|
+
set(params: {
|
|
3072
|
+
flowMediaId: string;
|
|
3073
|
+
senderKey: string;
|
|
3074
|
+
mediaId: string;
|
|
3075
|
+
}): Promise<void>;
|
|
3076
|
+
/** Remove só a chave deste número — o id do outro número continua válido. */
|
|
3077
|
+
clear(params: {
|
|
3078
|
+
flowMediaId: string;
|
|
3079
|
+
senderKey: string;
|
|
3080
|
+
}): Promise<void>;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
export { type AttachFlowMediaParams, type AudioTranscriber, type CompanyDocumentView, type CompanyDocumentsPage, type ConversationDocumentView, type ConversationDocumentsPage, 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, 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 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 };
|