@adatechnology/meta-whatsapp-module 0.2.0-rc.21 → 0.2.0-rc.23
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 +96 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(index_exports, {
|
|
|
45
45
|
MessageRepository: () => MessageRepository,
|
|
46
46
|
OptimisticLockError: () => OptimisticLockError,
|
|
47
47
|
PREVIEW_MEDIA_ID_PREFIX: () => import_meta_whatsapp_contracts8.PREVIEW_MEDIA_ID_PREFIX,
|
|
48
|
+
PRODUCT_LIST_LIMIT: () => PRODUCT_LIST_LIMIT,
|
|
48
49
|
PurgeExpiredDocumentsUseCase: () => PurgeExpiredDocumentsUseCase,
|
|
49
50
|
ReceiveWebhookUseCase: () => ReceiveWebhookUseCase,
|
|
50
51
|
ReleaseConversationUseCase: () => ReleaseConversationUseCase,
|
|
@@ -63,6 +64,7 @@ __export(index_exports, {
|
|
|
63
64
|
claimWebhookDelivery: () => claimWebhookDelivery,
|
|
64
65
|
createMetaWhatsAppModule: () => createMetaWhatsAppModule,
|
|
65
66
|
createSendMediaAction: () => createSendMediaAction,
|
|
67
|
+
createSendProductListAction: () => createSendProductListAction,
|
|
66
68
|
createTranscriptionPolicyResolver: () => createTranscriptionPolicyResolver,
|
|
67
69
|
documents: () => documents,
|
|
68
70
|
extractMediaDescriptor: () => extractMediaDescriptor,
|
|
@@ -1821,6 +1823,75 @@ function createSendMediaAction(params) {
|
|
|
1821
1823
|
}
|
|
1822
1824
|
__name(createSendMediaAction, "createSendMediaAction");
|
|
1823
1825
|
|
|
1826
|
+
// src/flows/createSendProductListAction.ts
|
|
1827
|
+
var PRODUCT_LIST_LIMIT = {
|
|
1828
|
+
ITEMS: 30,
|
|
1829
|
+
SECTIONS: 10
|
|
1830
|
+
};
|
|
1831
|
+
function createSendProductListAction(params) {
|
|
1832
|
+
return async ({ node, session, channel }) => {
|
|
1833
|
+
if (!channel.sendProductList) return;
|
|
1834
|
+
const actionParams = node.actionParams ?? {};
|
|
1835
|
+
try {
|
|
1836
|
+
const available = await listAvailableProducts({
|
|
1837
|
+
catalog: params.catalog,
|
|
1838
|
+
catalogId: params.catalogId,
|
|
1839
|
+
...actionParams.search ? {
|
|
1840
|
+
search: actionParams.search
|
|
1841
|
+
} : {}
|
|
1842
|
+
});
|
|
1843
|
+
if (available.length === 0) return;
|
|
1844
|
+
const bodyText = actionParams.bodyText ?? "Veja o que temos dispon\xEDvel:";
|
|
1845
|
+
const { externalMessageId } = await channel.sendProductList({
|
|
1846
|
+
to: session.whatsappNumber,
|
|
1847
|
+
headerText: actionParams.headerText ?? "Nossos produtos",
|
|
1848
|
+
body: bodyText,
|
|
1849
|
+
...actionParams.footerText ? {
|
|
1850
|
+
footerText: actionParams.footerText
|
|
1851
|
+
} : {},
|
|
1852
|
+
sections: [
|
|
1853
|
+
{
|
|
1854
|
+
title: actionParams.sectionTitle ?? "Dispon\xEDveis",
|
|
1855
|
+
retailerIds: available.map((product) => product.retailerId)
|
|
1856
|
+
}
|
|
1857
|
+
]
|
|
1858
|
+
});
|
|
1859
|
+
await params.logMessage.execute({
|
|
1860
|
+
companyId: session.companyId,
|
|
1861
|
+
whatsappNumber: session.whatsappNumber,
|
|
1862
|
+
direction: "outbound",
|
|
1863
|
+
sender: "bot",
|
|
1864
|
+
agentUserId: null,
|
|
1865
|
+
type: "interactive",
|
|
1866
|
+
content: bodyText,
|
|
1867
|
+
payload: {
|
|
1868
|
+
kind: "product_list",
|
|
1869
|
+
productCount: available.length
|
|
1870
|
+
},
|
|
1871
|
+
waMessageId: externalMessageId,
|
|
1872
|
+
status: "sent",
|
|
1873
|
+
startState: params.startState
|
|
1874
|
+
});
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
params.onError?.(error, {
|
|
1877
|
+
flowKey: session.flowKey ?? "",
|
|
1878
|
+
nodeId: node.id
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
__name(createSendProductListAction, "createSendProductListAction");
|
|
1884
|
+
async function listAvailableProducts(params) {
|
|
1885
|
+
const products = await params.catalog.listProducts({
|
|
1886
|
+
catalogId: params.catalogId,
|
|
1887
|
+
...params.search ? {
|
|
1888
|
+
search: params.search
|
|
1889
|
+
} : {}
|
|
1890
|
+
});
|
|
1891
|
+
return products.filter((product) => product.availability === "in stock").slice(0, PRODUCT_LIST_LIMIT.ITEMS);
|
|
1892
|
+
}
|
|
1893
|
+
__name(listAvailableProducts, "listAvailableProducts");
|
|
1894
|
+
|
|
1824
1895
|
// src/repositories/FlowMediaRepository.ts
|
|
1825
1896
|
var import_drizzle_orm7 = require("drizzle-orm");
|
|
1826
1897
|
var FlowMediaRepository = class {
|
|
@@ -1979,6 +2050,20 @@ var WhatsAppChannelAdapter = class {
|
|
|
1979
2050
|
externalMessageId: result.waMessageId
|
|
1980
2051
|
};
|
|
1981
2052
|
}
|
|
2053
|
+
async sendProductList(params) {
|
|
2054
|
+
const result = await this.translateErrors(() => this.messages.sendProductListMessage({
|
|
2055
|
+
to: params.to,
|
|
2056
|
+
headerText: params.headerText,
|
|
2057
|
+
bodyText: params.body,
|
|
2058
|
+
...params.footerText ? {
|
|
2059
|
+
footerText: params.footerText
|
|
2060
|
+
} : {},
|
|
2061
|
+
sections: params.sections
|
|
2062
|
+
}));
|
|
2063
|
+
return {
|
|
2064
|
+
externalMessageId: result.waMessageId
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
1982
2067
|
/**
|
|
1983
2068
|
* Busca o binário da mídia — da Meta, ou do storage quando o id é do simulador.
|
|
1984
2069
|
*
|
|
@@ -2599,6 +2684,15 @@ function createMetaWhatsAppModule(params) {
|
|
|
2599
2684
|
onError: hooks?.onFlowMediaError
|
|
2600
2685
|
}));
|
|
2601
2686
|
}
|
|
2687
|
+
if (flowInterpreter && providers.catalog && config.catalogId) {
|
|
2688
|
+
flowInterpreter.registerFlowAction(import_meta_whatsapp_contracts13.FLOW_ACTION_KIND.SEND_PRODUCT_LIST, createSendProductListAction({
|
|
2689
|
+
catalog: providers.catalog,
|
|
2690
|
+
catalogId: config.catalogId,
|
|
2691
|
+
logMessage,
|
|
2692
|
+
startState,
|
|
2693
|
+
onError: hooks?.onFlowProductListError
|
|
2694
|
+
}));
|
|
2695
|
+
}
|
|
2602
2696
|
const transcriptionMode = providers.transcription?.mode ?? TRANSCRIPTION_MODE.ON_DEMAND;
|
|
2603
2697
|
const resolveTranscriptionPolicy = providers.transcription ? createTranscriptionPolicyResolver({
|
|
2604
2698
|
settingsRepository,
|
|
@@ -2819,6 +2913,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
2819
2913
|
MessageRepository,
|
|
2820
2914
|
OptimisticLockError,
|
|
2821
2915
|
PREVIEW_MEDIA_ID_PREFIX,
|
|
2916
|
+
PRODUCT_LIST_LIMIT,
|
|
2822
2917
|
PurgeExpiredDocumentsUseCase,
|
|
2823
2918
|
ReceiveWebhookUseCase,
|
|
2824
2919
|
ReleaseConversationUseCase,
|
|
@@ -2837,6 +2932,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
2837
2932
|
claimWebhookDelivery,
|
|
2838
2933
|
createMetaWhatsAppModule,
|
|
2839
2934
|
createSendMediaAction,
|
|
2935
|
+
createSendProductListAction,
|
|
2840
2936
|
createTranscriptionPolicyResolver,
|
|
2841
2937
|
documents,
|
|
2842
2938
|
extractMediaDescriptor,
|