@adatechnology/meta-whatsapp-module 0.2.0-rc.20 → 0.2.0-rc.22
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 +106 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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 {
|
|
@@ -1969,6 +2040,30 @@ var WhatsAppChannelAdapter = class {
|
|
|
1969
2040
|
externalMessageId: result.waMessageId
|
|
1970
2041
|
};
|
|
1971
2042
|
}
|
|
2043
|
+
async sendInteractiveButtons(params) {
|
|
2044
|
+
const result = await this.translateErrors(() => this.messages.sendInteractiveButtons({
|
|
2045
|
+
to: params.to,
|
|
2046
|
+
bodyText: params.body,
|
|
2047
|
+
buttons: params.buttons
|
|
2048
|
+
}));
|
|
2049
|
+
return {
|
|
2050
|
+
externalMessageId: result.waMessageId
|
|
2051
|
+
};
|
|
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
|
+
}
|
|
1972
2067
|
/**
|
|
1973
2068
|
* Busca o binário da mídia — da Meta, ou do storage quando o id é do simulador.
|
|
1974
2069
|
*
|
|
@@ -2589,6 +2684,15 @@ function createMetaWhatsAppModule(params) {
|
|
|
2589
2684
|
onError: hooks?.onFlowMediaError
|
|
2590
2685
|
}));
|
|
2591
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
|
+
}
|
|
2592
2696
|
const transcriptionMode = providers.transcription?.mode ?? TRANSCRIPTION_MODE.ON_DEMAND;
|
|
2593
2697
|
const resolveTranscriptionPolicy = providers.transcription ? createTranscriptionPolicyResolver({
|
|
2594
2698
|
settingsRepository,
|
|
@@ -2809,6 +2913,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
2809
2913
|
MessageRepository,
|
|
2810
2914
|
OptimisticLockError,
|
|
2811
2915
|
PREVIEW_MEDIA_ID_PREFIX,
|
|
2916
|
+
PRODUCT_LIST_LIMIT,
|
|
2812
2917
|
PurgeExpiredDocumentsUseCase,
|
|
2813
2918
|
ReceiveWebhookUseCase,
|
|
2814
2919
|
ReleaseConversationUseCase,
|
|
@@ -2827,6 +2932,7 @@ __name(redeemSseTicket, "redeemSseTicket");
|
|
|
2827
2932
|
claimWebhookDelivery,
|
|
2828
2933
|
createMetaWhatsAppModule,
|
|
2829
2934
|
createSendMediaAction,
|
|
2935
|
+
createSendProductListAction,
|
|
2830
2936
|
createTranscriptionPolicyResolver,
|
|
2831
2937
|
documents,
|
|
2832
2938
|
extractMediaDescriptor,
|