meta-cloud-api 1.1.4 → 1.1.5

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.
Files changed (152) hide show
  1. package/dist/base.d.ts +19 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/chunk-PECeCxCb.js +15 -0
  4. package/dist/config.d.ts +80 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/{base-CfDkvT1x.d.ts → enums.d.ts} +3 -142
  7. package/dist/enums.d.ts.map +1 -0
  8. package/dist/enums.js +681 -0
  9. package/dist/enums.js.map +1 -0
  10. package/dist/{index-DQkgkiB6.d.ts → httpsClient.d.ts} +3 -12
  11. package/dist/httpsClient.d.ts.map +1 -0
  12. package/dist/index.d.ts +4386 -21
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +3436 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/logger.d.ts +11 -0
  17. package/dist/logger.d.ts.map +1 -0
  18. package/dist/request.d.ts +52 -0
  19. package/dist/request.d.ts.map +1 -0
  20. package/package.json +13 -22
  21. package/dist/WebhookProcessor-BUZFeZD_.js +0 -3
  22. package/dist/WebhookProcessor-BUZFeZD_.js.map +0 -1
  23. package/dist/WebhookProcessor-Dq2Pa2cY.d.ts +0 -718
  24. package/dist/WebhookProcessor-Dq2Pa2cY.d.ts.map +0 -1
  25. package/dist/api/encryption/index.d.ts +0 -3
  26. package/dist/api/encryption/index.js +0 -1
  27. package/dist/api/flow/index.d.ts +0 -5
  28. package/dist/api/flow/index.js +0 -1
  29. package/dist/api/index.d.ts +0 -17
  30. package/dist/api/index.js +0 -1
  31. package/dist/api/media/index.d.ts +0 -3
  32. package/dist/api/media/index.js +0 -1
  33. package/dist/api/messages/builders/index.d.ts +0 -539
  34. package/dist/api/messages/builders/index.d.ts.map +0 -1
  35. package/dist/api/messages/builders/index.js +0 -2
  36. package/dist/api/messages/builders/index.js.map +0 -1
  37. package/dist/api/messages/index.d.ts +0 -4
  38. package/dist/api/messages/index.js +0 -1
  39. package/dist/api/phone/index.d.ts +0 -3
  40. package/dist/api/phone/index.js +0 -1
  41. package/dist/api/profile/index.d.ts +0 -3
  42. package/dist/api/profile/index.js +0 -1
  43. package/dist/api/qrCode/index.d.ts +0 -3
  44. package/dist/api/qrCode/index.js +0 -1
  45. package/dist/api/registration/index.d.ts +0 -3
  46. package/dist/api/registration/index.js +0 -1
  47. package/dist/api/template/index.d.ts +0 -3
  48. package/dist/api/template/index.js +0 -1
  49. package/dist/api/twoStepVerification/index.d.ts +0 -3
  50. package/dist/api/twoStepVerification/index.js +0 -1
  51. package/dist/api/waba/index.d.ts +0 -3
  52. package/dist/api/waba/index.js +0 -1
  53. package/dist/api-8hRAOyaL.js +0 -1
  54. package/dist/base-CfDkvT1x.d.ts.map +0 -1
  55. package/dist/base-D-cXu_lA.js +0 -2
  56. package/dist/base-D-cXu_lA.js.map +0 -1
  57. package/dist/buildFieldsQueryString-Cr-jz3p0.js +0 -2
  58. package/dist/buildFieldsQueryString-Cr-jz3p0.js.map +0 -1
  59. package/dist/chunk-CTAAG5j7.js +0 -1
  60. package/dist/common-C6FXBDm7.js +0 -2
  61. package/dist/common-C6FXBDm7.js.map +0 -1
  62. package/dist/common-CVbsmD26.d.ts +0 -426
  63. package/dist/common-CVbsmD26.d.ts.map +0 -1
  64. package/dist/common-CvPVD1o6.d.ts +0 -406
  65. package/dist/common-CvPVD1o6.d.ts.map +0 -1
  66. package/dist/core/webhook/frameworks/express.d.ts +0 -20
  67. package/dist/core/webhook/frameworks/express.js +0 -1
  68. package/dist/core/webhook/frameworks/nextjs-app.d.ts +0 -45
  69. package/dist/core/webhook/frameworks/nextjs-app.d.ts.map +0 -1
  70. package/dist/core/webhook/frameworks/nextjs-app.js +0 -2
  71. package/dist/core/webhook/frameworks/nextjs-app.js.map +0 -1
  72. package/dist/core/webhook/frameworks/nextjs.d.ts +0 -20
  73. package/dist/core/webhook/frameworks/nextjs.js +0 -1
  74. package/dist/core/webhook/index.d.ts +0 -20
  75. package/dist/core/webhook/index.js +0 -1
  76. package/dist/core/whatsapp/index.d.ts +0 -18
  77. package/dist/core/whatsapp/index.js +0 -1
  78. package/dist/encryption-Cwc0xcVL.js +0 -2
  79. package/dist/encryption-Cwc0xcVL.js.map +0 -1
  80. package/dist/enums-CSUpFXb8.js +0 -2
  81. package/dist/enums-CSUpFXb8.js.map +0 -1
  82. package/dist/express-B6fQdflY.d.ts +0 -78
  83. package/dist/express-B6fQdflY.d.ts.map +0 -1
  84. package/dist/express-CrfNLYMM.js +0 -2
  85. package/dist/express-CrfNLYMM.js.map +0 -1
  86. package/dist/flow-CVes0Qus.js +0 -2
  87. package/dist/flow-CVes0Qus.js.map +0 -1
  88. package/dist/flowTypeGuards-Gn3-slCW.js +0 -2
  89. package/dist/flowTypeGuards-Gn3-slCW.js.map +0 -1
  90. package/dist/handler-BGqjZ0xg.js +0 -2
  91. package/dist/handler-BGqjZ0xg.js.map +0 -1
  92. package/dist/index-3KglHVAg.d.ts +0 -354
  93. package/dist/index-3KglHVAg.d.ts.map +0 -1
  94. package/dist/index-BNeg6hHx.d.ts +0 -99
  95. package/dist/index-BNeg6hHx.d.ts.map +0 -1
  96. package/dist/index-BiTq23oi.d.ts +0 -34
  97. package/dist/index-BiTq23oi.d.ts.map +0 -1
  98. package/dist/index-BmfnREgM.d.ts +0 -47
  99. package/dist/index-BmfnREgM.d.ts.map +0 -1
  100. package/dist/index-CaGffSja.d.ts +0 -24
  101. package/dist/index-CaGffSja.d.ts.map +0 -1
  102. package/dist/index-CeTmbIXi.d.ts +0 -180
  103. package/dist/index-CeTmbIXi.d.ts.map +0 -1
  104. package/dist/index-CoyByMuM.d.ts +0 -137
  105. package/dist/index-CoyByMuM.d.ts.map +0 -1
  106. package/dist/index-CwujtcvH.d.ts +0 -370
  107. package/dist/index-CwujtcvH.d.ts.map +0 -1
  108. package/dist/index-DQ7z58xp.d.ts +0 -104
  109. package/dist/index-DQ7z58xp.d.ts.map +0 -1
  110. package/dist/index-DQkgkiB6.d.ts.map +0 -1
  111. package/dist/index-LKrIp3Oo.d.ts +0 -1
  112. package/dist/index-_-06JPan.d.ts +0 -143
  113. package/dist/index-_-06JPan.d.ts.map +0 -1
  114. package/dist/index-a_YS40Iv.d.ts +0 -91
  115. package/dist/index-a_YS40Iv.d.ts.map +0 -1
  116. package/dist/index-d7TLqtYh.d.ts +0 -171
  117. package/dist/index-d7TLqtYh.d.ts.map +0 -1
  118. package/dist/isMetaError-B3AglYeY.d.ts +0 -66
  119. package/dist/isMetaError-B3AglYeY.d.ts.map +0 -1
  120. package/dist/media-Dw5OGzDD.js +0 -2
  121. package/dist/media-Dw5OGzDD.js.map +0 -1
  122. package/dist/messages-h5-NW8QO.js +0 -2
  123. package/dist/messages-h5-NW8QO.js.map +0 -1
  124. package/dist/nextjs-DxRCL4t3.js +0 -2
  125. package/dist/nextjs-DxRCL4t3.js.map +0 -1
  126. package/dist/objectToQueryString-CAHI0qTs.js +0 -2
  127. package/dist/objectToQueryString-CAHI0qTs.js.map +0 -1
  128. package/dist/phone-CZyWLyWB.js +0 -2
  129. package/dist/phone-CZyWLyWB.js.map +0 -1
  130. package/dist/profile-Bb7GDP0n.js +0 -2
  131. package/dist/profile-Bb7GDP0n.js.map +0 -1
  132. package/dist/qrCode-CeZEtX9J.js +0 -2
  133. package/dist/qrCode-CeZEtX9J.js.map +0 -1
  134. package/dist/registration-BkjhC3xw.js +0 -2
  135. package/dist/registration-BkjhC3xw.js.map +0 -1
  136. package/dist/template-Bgy-BCXJ.js +0 -2
  137. package/dist/template-Bgy-BCXJ.js.map +0 -1
  138. package/dist/twoStepVerification-DYlYF_P5.js +0 -2
  139. package/dist/twoStepVerification-DYlYF_P5.js.map +0 -1
  140. package/dist/types/index.d.ts +0 -3
  141. package/dist/types/index.js +0 -1
  142. package/dist/utils/index.d.ts +0 -43
  143. package/dist/utils/index.d.ts.map +0 -1
  144. package/dist/utils/index.js +0 -1
  145. package/dist/version-BUuqrHc6.js +0 -3
  146. package/dist/version-BUuqrHc6.js.map +0 -1
  147. package/dist/waba-SF2W3z2U.js +0 -2
  148. package/dist/waba-SF2W3z2U.js.map +0 -1
  149. package/dist/webhook-D4DQ01Xq.js +0 -2
  150. package/dist/webhook-D4DQ01Xq.js.map +0 -1
  151. package/dist/whatsapp-B85mxH5f.js +0 -10
  152. package/dist/whatsapp-B85mxH5f.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,2 +1,3437 @@
1
- import{AudioMediaTypesEnum as e,BusinessVerticalEnum as t,ButtonPositionEnum as n,CategoryEnum as r,ComponentTypesEnum as i,ConversationTypesEnum as a,CurrencyCodesEnum as o,DataLocalizationRegionEnum as s,DocumentMediaTypesEnum as c,HttpMethodsEnum as l,ImageMediaTypesEnum as u,InteractiveTypesEnum as d,LanguagesEnum as f,MessageTypesEnum as p,ParametersTypesEnum as m,RequestCodeMethodsEnum as h,StatusEnum as g,StickerMediaTypesEnum as _,SubTypeEnum as v,SystemChangeTypesEnum as y,TemplateStatusEnum as b,VideoMediaTypesEnum as x,WabaConfigEnum as S,WebhookTypesEnum as C}from"./enums-CSUpFXb8.js";import{isMetaError as w}from"./version-BUuqrHc6.js";import{WhatsApp as T}from"./whatsapp-B85mxH5f.js";import"./base-D-cXu_lA.js";import{encryption_default as E}from"./encryption-Cwc0xcVL.js";import{flow_default as D}from"./flow-CVes0Qus.js";import{FlowActionEnum as O,FlowCategoryEnum as k,FlowStatusEnum as A,FlowTypeEnum as j}from"./common-C6FXBDm7.js";import{media_default as M}from"./media-Dw5OGzDD.js";import{messages_default as N}from"./messages-h5-NW8QO.js";import"./objectToQueryString-CAHI0qTs.js";import{phone_default as P}from"./phone-CZyWLyWB.js";import"./buildFieldsQueryString-Cr-jz3p0.js";import{profile_default as F}from"./profile-Bb7GDP0n.js";import{qrCode_default as I}from"./qrCode-CeZEtX9J.js";import{registration_default as L}from"./registration-BkjhC3xw.js";import{TemplateApi as R}from"./template-Bgy-BCXJ.js";import{twoStepVerification_default as z}from"./twoStepVerification-DYlYF_P5.js";import{waba_default as B}from"./waba-SF2W3z2U.js";import"./api-8hRAOyaL.js";import{isFlowDataExchangeRequest as V,isFlowErrorRequest as H,isFlowPingRequest as U}from"./flowTypeGuards-Gn3-slCW.js";import"./WebhookProcessor-BUZFeZD_.js";import"./handler-BGqjZ0xg.js";import{webhookHandler as W}from"./express-CrfNLYMM.js";import{webhookHandler as G}from"./nextjs-DxRCL4t3.js";import"./webhook-D4DQ01Xq.js";let K=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),q=function(e){return e.Blocked=`BLOCKED`,e.Limited=`LIMITED`,e.Available=`AVAILABLE`,e}({}),J=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),Y=function(e){return e.Verified=`verified`,e.PendingSubmission=`pending_submission`,e.Unverified=`unverified`,e.Rejected=`rejected`,e}({});export{e as AudioMediaTypesEnum,F as BusinessProfileApi,t as BusinessVerticalEnum,n as ButtonPositionEnum,r as CategoryEnum,i as ComponentTypesEnum,a as ConversationTypesEnum,o as CurrencyCodesEnum,s as DataLocalizationRegionEnum,c as DocumentMediaTypesEnum,E as EncryptionApi,W as ExpressWebhook,O as FlowActionEnum,D as FlowApi,k as FlowCategoryEnum,A as FlowStatusEnum,j as FlowTypeEnum,l as HttpMethodsEnum,u as ImageMediaTypesEnum,d as InteractiveTypesEnum,f as LanguagesEnum,M as MediaApi,p as MessageTypesEnum,N as MessagesApi,G as NextJsWebhook,m as ParametersTypesEnum,P as PhoneNumberApi,I as QrCodeApi,L as RegistrationApi,h as RequestCodeMethodsEnum,g as StatusEnum,_ as StickerMediaTypesEnum,v as SubTypeEnum,y as SystemChangeTypesEnum,R as TemplateApi,b as TemplateStatusEnum,z as TwoStepVerificationApi,x as VideoMediaTypesEnum,K as WabaAccountReviewStatus,J as WabaAccountStatus,B as WabaApi,Y as WabaBusinessVerificationStatus,S as WabaConfigEnum,q as WabaHealthStatusCanSendMessage,C as WebhookTypesEnum,T as WhatsApp,T as WhatsAppLegacy,V as isFlowDataExchangeRequest,H as isFlowErrorRequest,U as isFlowPingRequest,w as isMetaError};
1
+ import { __export } from "./chunk-PECeCxCb.js";
2
+ import { Agent } from "https";
3
+ import { readFileSync } from "fs";
4
+ import { join } from "path";
5
+ import * as crypto$1 from "crypto";
6
+ import crypto from "crypto";
7
+
8
+ //#region src/types/enums.ts
9
+ var enums_exports = __export({
10
+ AudioMediaTypesEnum: () => AudioMediaTypesEnum,
11
+ BusinessVerticalEnum: () => BusinessVerticalEnum,
12
+ ButtonPositionEnum: () => ButtonPositionEnum,
13
+ CategoryEnum: () => CategoryEnum,
14
+ ComponentTypesEnum: () => ComponentTypesEnum,
15
+ ConversationTypesEnum: () => ConversationTypesEnum,
16
+ CurrencyCodesEnum: () => CurrencyCodesEnum,
17
+ DataLocalizationRegionEnum: () => DataLocalizationRegionEnum,
18
+ DocumentMediaTypesEnum: () => DocumentMediaTypesEnum,
19
+ HttpMethodsEnum: () => HttpMethodsEnum,
20
+ ImageMediaTypesEnum: () => ImageMediaTypesEnum,
21
+ InteractiveTypesEnum: () => InteractiveTypesEnum,
22
+ LanguagesEnum: () => LanguagesEnum,
23
+ MessageTypesEnum: () => MessageTypesEnum,
24
+ ParametersTypesEnum: () => ParametersTypesEnum,
25
+ ReferralSourceTypesEnum: () => ReferralSourceTypesEnum,
26
+ RequestCodeMethodsEnum: () => RequestCodeMethodsEnum,
27
+ StatusEnum: () => StatusEnum,
28
+ StickerMediaTypesEnum: () => StickerMediaTypesEnum,
29
+ SubTypeEnum: () => SubTypeEnum,
30
+ SystemChangeTypesEnum: () => SystemChangeTypesEnum,
31
+ TemplateStatusEnum: () => TemplateStatusEnum,
32
+ VideoMediaTypesEnum: () => VideoMediaTypesEnum,
33
+ WabaConfigEnum: () => WabaConfigEnum,
34
+ WebhookTypesEnum: () => WebhookTypesEnum
35
+ });
36
+ let CategoryEnum = /* @__PURE__ */ function(CategoryEnum$1) {
37
+ CategoryEnum$1["Authentication"] = "AUTHENTICATION";
38
+ CategoryEnum$1["Marketing"] = "MARKETING";
39
+ CategoryEnum$1["Utility"] = "UTILITY";
40
+ return CategoryEnum$1;
41
+ }({});
42
+ let TemplateStatusEnum = /* @__PURE__ */ function(TemplateStatusEnum$1) {
43
+ TemplateStatusEnum$1["Approved"] = "APPROVED";
44
+ TemplateStatusEnum$1["Pending"] = "PENDING";
45
+ TemplateStatusEnum$1["Rejected"] = "REJECTED";
46
+ return TemplateStatusEnum$1;
47
+ }({});
48
+ let HttpMethodsEnum = /* @__PURE__ */ function(HttpMethodsEnum$1) {
49
+ HttpMethodsEnum$1["Get"] = "GET";
50
+ HttpMethodsEnum$1["Post"] = "POST";
51
+ HttpMethodsEnum$1["Put"] = "PUT";
52
+ HttpMethodsEnum$1["Delete"] = "DELETE";
53
+ return HttpMethodsEnum$1;
54
+ }({});
55
+ let MessageTypesEnum = /* @__PURE__ */ function(MessageTypesEnum$1) {
56
+ MessageTypesEnum$1["Audio"] = "audio";
57
+ MessageTypesEnum$1["Contacts"] = "contacts";
58
+ MessageTypesEnum$1["Document"] = "document";
59
+ MessageTypesEnum$1["Image"] = "image";
60
+ MessageTypesEnum$1["Interactive"] = "interactive";
61
+ MessageTypesEnum$1["Location"] = "location";
62
+ MessageTypesEnum$1["Reaction"] = "reaction";
63
+ MessageTypesEnum$1["Sticker"] = "sticker";
64
+ MessageTypesEnum$1["Template"] = "template";
65
+ MessageTypesEnum$1["Text"] = "text";
66
+ MessageTypesEnum$1["Video"] = "video";
67
+ MessageTypesEnum$1["Button"] = "button";
68
+ MessageTypesEnum$1["Order"] = "order";
69
+ MessageTypesEnum$1["System"] = "system";
70
+ MessageTypesEnum$1["Unknown"] = "unknown";
71
+ MessageTypesEnum$1["Statuses"] = "statuses";
72
+ MessageTypesEnum$1["*"] = "*";
73
+ return MessageTypesEnum$1;
74
+ }({});
75
+ let ParametersTypesEnum = /* @__PURE__ */ function(ParametersTypesEnum$1) {
76
+ ParametersTypesEnum$1["Action"] = "ACTION";
77
+ ParametersTypesEnum$1["CouponCode"] = "COUPON_CODE";
78
+ ParametersTypesEnum$1["Currency"] = "CURRENCY";
79
+ ParametersTypesEnum$1["DateTime"] = "DATE_TIME";
80
+ ParametersTypesEnum$1["Document"] = "DOCUMENT";
81
+ ParametersTypesEnum$1["ExpirationTimeMs"] = "EXPIRATION_TIME_MS";
82
+ ParametersTypesEnum$1["Image"] = "IMAGE";
83
+ ParametersTypesEnum$1["LimitedTimeOffer"] = "LIMITED_TIME_OFFER";
84
+ ParametersTypesEnum$1["Location"] = "LOCATION";
85
+ ParametersTypesEnum$1["OrderStatus"] = "ORDER_STATUS";
86
+ ParametersTypesEnum$1["Payload"] = "PAYLOAD";
87
+ ParametersTypesEnum$1["Product"] = "PRODUCT";
88
+ ParametersTypesEnum$1["Text"] = "TEXT";
89
+ ParametersTypesEnum$1["TtlMinutes"] = "TTL_MINUTES";
90
+ ParametersTypesEnum$1["Video"] = "VIDEO";
91
+ ParametersTypesEnum$1["WebviewInteraction"] = "WEBVIEW_INTERACTION";
92
+ ParametersTypesEnum$1["WebviewPresentation"] = "WEBVIEW_PRESENTATION";
93
+ return ParametersTypesEnum$1;
94
+ }({});
95
+ let InteractiveTypesEnum = /* @__PURE__ */ function(InteractiveTypesEnum$1) {
96
+ InteractiveTypesEnum$1["Button"] = "button";
97
+ InteractiveTypesEnum$1["List"] = "list";
98
+ InteractiveTypesEnum$1["Product"] = "product";
99
+ InteractiveTypesEnum$1["ProductList"] = "product_list";
100
+ InteractiveTypesEnum$1["CtaUrl"] = "cta_url";
101
+ InteractiveTypesEnum$1["LocationRequest"] = "location_request_message";
102
+ InteractiveTypesEnum$1["AddressMessage"] = "address_message";
103
+ InteractiveTypesEnum$1["Flow"] = "flow";
104
+ return InteractiveTypesEnum$1;
105
+ }({});
106
+ let ButtonPositionEnum = /* @__PURE__ */ function(ButtonPositionEnum$1) {
107
+ ButtonPositionEnum$1[ButtonPositionEnum$1["First"] = 1] = "First";
108
+ ButtonPositionEnum$1[ButtonPositionEnum$1["Second"] = 2] = "Second";
109
+ ButtonPositionEnum$1[ButtonPositionEnum$1["Third"] = 3] = "Third";
110
+ ButtonPositionEnum$1[ButtonPositionEnum$1["Fourth"] = 4] = "Fourth";
111
+ ButtonPositionEnum$1[ButtonPositionEnum$1["Fifth"] = 5] = "Fifth";
112
+ return ButtonPositionEnum$1;
113
+ }({});
114
+ let SubTypeEnum = /* @__PURE__ */ function(SubTypeEnum$1) {
115
+ SubTypeEnum$1["Catalog"] = "CATALOG";
116
+ SubTypeEnum$1["CopyCode"] = "COPY_CODE";
117
+ SubTypeEnum$1["Flow"] = "FLOW";
118
+ SubTypeEnum$1["Mpm"] = "MPM";
119
+ SubTypeEnum$1["OrderDetails"] = "ORDER_DETAILS";
120
+ SubTypeEnum$1["QuickReply"] = "QUICK_REPLY";
121
+ SubTypeEnum$1["Reminder"] = "REMINDER";
122
+ SubTypeEnum$1["Url"] = "URL";
123
+ SubTypeEnum$1["VoiceCall"] = "VOICE_CALL";
124
+ return SubTypeEnum$1;
125
+ }({});
126
+ let ComponentTypesEnum = /* @__PURE__ */ function(ComponentTypesEnum$1) {
127
+ ComponentTypesEnum$1["Header"] = "HEADER";
128
+ ComponentTypesEnum$1["Body"] = "BODY";
129
+ ComponentTypesEnum$1["Button"] = "BUTTON";
130
+ ComponentTypesEnum$1["Footer"] = "FOOTER";
131
+ return ComponentTypesEnum$1;
132
+ }({});
133
+ let WabaConfigEnum = /* @__PURE__ */ function(WabaConfigEnum$1) {
134
+ WabaConfigEnum$1["AppId"] = "M4D_APP_ID";
135
+ WabaConfigEnum$1["Port"] = "WA_PORT";
136
+ WabaConfigEnum$1["AppSecret"] = "M4D_APP_SECRET";
137
+ WabaConfigEnum$1["PhoneNumberId"] = "WA_PHONE_NUMBER_ID";
138
+ WabaConfigEnum$1["BusinessAcctId"] = "WA_BUSINESS_ACCOUNT_ID";
139
+ WabaConfigEnum$1["APIVersion"] = "CLOUD_API_VERSION";
140
+ WabaConfigEnum$1["AccessToken"] = "CLOUD_API_ACCESS_TOKEN";
141
+ WabaConfigEnum$1["WebhookEndpoint"] = "WEBHOOK_ENDPOINT";
142
+ WabaConfigEnum$1["WebhookVerificationToken"] = "WEBHOOK_VERIFICATION_TOKEN";
143
+ WabaConfigEnum$1["ListenerPort"] = "LISTENER_PORT";
144
+ WabaConfigEnum$1["MaxRetriesAfterWait"] = "MAX_RETRIES_AFTER_WAIT";
145
+ WabaConfigEnum$1["RequestTimeout"] = "REQUEST_TIMEOUT";
146
+ WabaConfigEnum$1["Debug"] = "DEBUG";
147
+ WabaConfigEnum$1["PrivatePem"] = "FLOW_API_PRIVATE_PEM";
148
+ WabaConfigEnum$1["Passphrase"] = "FLOW_API_PASSPHRASE";
149
+ return WabaConfigEnum$1;
150
+ }({});
151
+ let ConversationTypesEnum = /* @__PURE__ */ function(ConversationTypesEnum$1) {
152
+ ConversationTypesEnum$1["BusinessInitiated"] = "business_initiated";
153
+ ConversationTypesEnum$1["CustomerInitiated"] = "customer_initiated";
154
+ ConversationTypesEnum$1["ReferralConversion"] = "referral_conversion";
155
+ return ConversationTypesEnum$1;
156
+ }({});
157
+ let StatusEnum = /* @__PURE__ */ function(StatusEnum$1) {
158
+ StatusEnum$1["Delivered"] = "delivered";
159
+ StatusEnum$1["Read"] = "read";
160
+ StatusEnum$1["Sent"] = "sent";
161
+ return StatusEnum$1;
162
+ }({});
163
+ let VideoMediaTypesEnum = /* @__PURE__ */ function(VideoMediaTypesEnum$1) {
164
+ VideoMediaTypesEnum$1["Mp4"] = "video/mp4";
165
+ VideoMediaTypesEnum$1["Threegp"] = "video/3gp";
166
+ return VideoMediaTypesEnum$1;
167
+ }({});
168
+ let StickerMediaTypesEnum = /* @__PURE__ */ function(StickerMediaTypesEnum$1) {
169
+ StickerMediaTypesEnum$1["Webp"] = "image/webp";
170
+ return StickerMediaTypesEnum$1;
171
+ }({});
172
+ let ImageMediaTypesEnum = /* @__PURE__ */ function(ImageMediaTypesEnum$1) {
173
+ ImageMediaTypesEnum$1["Jpeg"] = "image/jpeg";
174
+ ImageMediaTypesEnum$1["Png"] = "image/png";
175
+ return ImageMediaTypesEnum$1;
176
+ }({});
177
+ let DocumentMediaTypesEnum = /* @__PURE__ */ function(DocumentMediaTypesEnum$1) {
178
+ DocumentMediaTypesEnum$1["Text"] = "text/plain";
179
+ DocumentMediaTypesEnum$1["Pdf"] = "application/pdf";
180
+ DocumentMediaTypesEnum$1["Ppt"] = "application/vnd.ms-powerpoint";
181
+ DocumentMediaTypesEnum$1["Word"] = "application/msword";
182
+ DocumentMediaTypesEnum$1["Excel"] = "application/vnd.ms-excel";
183
+ DocumentMediaTypesEnum$1["OpenDoc"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
184
+ DocumentMediaTypesEnum$1["OpenPres"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
185
+ DocumentMediaTypesEnum$1["OpenSheet"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
186
+ return DocumentMediaTypesEnum$1;
187
+ }({});
188
+ let AudioMediaTypesEnum = /* @__PURE__ */ function(AudioMediaTypesEnum$1) {
189
+ AudioMediaTypesEnum$1["Aac"] = "audio/aac";
190
+ AudioMediaTypesEnum$1["Mp4"] = "audio/mp4";
191
+ AudioMediaTypesEnum$1["Mpeg"] = "audio/mpeg";
192
+ AudioMediaTypesEnum$1["Amr"] = "audio/amr";
193
+ AudioMediaTypesEnum$1["Ogg"] = "audio/ogg";
194
+ return AudioMediaTypesEnum$1;
195
+ }({});
196
+ let WebhookTypesEnum = /* @__PURE__ */ function(WebhookTypesEnum$1) {
197
+ WebhookTypesEnum$1["Audio"] = "audio";
198
+ WebhookTypesEnum$1["Button"] = "button";
199
+ WebhookTypesEnum$1["Document"] = "document";
200
+ WebhookTypesEnum$1["Text"] = "text";
201
+ WebhookTypesEnum$1["Image"] = "image";
202
+ WebhookTypesEnum$1["Interactive"] = "interactive";
203
+ WebhookTypesEnum$1["Order"] = "order";
204
+ WebhookTypesEnum$1["Sticker"] = "sticker";
205
+ WebhookTypesEnum$1["System"] = "system";
206
+ WebhookTypesEnum$1["Unknown"] = "unknown";
207
+ WebhookTypesEnum$1["Video"] = "video";
208
+ return WebhookTypesEnum$1;
209
+ }({});
210
+ let SystemChangeTypesEnum = /* @__PURE__ */ function(SystemChangeTypesEnum$1) {
211
+ SystemChangeTypesEnum$1["CustomerChangedNumber"] = "customer_changed_number";
212
+ SystemChangeTypesEnum$1["CustomerIdentityChanged"] = "customer_identity_changed";
213
+ return SystemChangeTypesEnum$1;
214
+ }({});
215
+ let ReferralSourceTypesEnum = /* @__PURE__ */ function(ReferralSourceTypesEnum$1) {
216
+ ReferralSourceTypesEnum$1["Ad"] = "ad";
217
+ ReferralSourceTypesEnum$1["Post"] = "post";
218
+ return ReferralSourceTypesEnum$1;
219
+ }({});
220
+ let RequestCodeMethodsEnum = /* @__PURE__ */ function(RequestCodeMethodsEnum$1) {
221
+ RequestCodeMethodsEnum$1["Sms"] = "SMS";
222
+ RequestCodeMethodsEnum$1["Voice"] = "VOICE";
223
+ return RequestCodeMethodsEnum$1;
224
+ }({});
225
+ let LanguagesEnum = /* @__PURE__ */ function(LanguagesEnum$1) {
226
+ LanguagesEnum$1["Afrikaans"] = "af";
227
+ LanguagesEnum$1["Albanian"] = "sq";
228
+ LanguagesEnum$1["Arabic"] = "ar";
229
+ LanguagesEnum$1["Azerbaijani"] = "az";
230
+ LanguagesEnum$1["Bengali"] = "bn";
231
+ LanguagesEnum$1["Bulgarian"] = "bg";
232
+ LanguagesEnum$1["Catalan"] = "ca";
233
+ LanguagesEnum$1["Chinese_CHN"] = "zh_CN";
234
+ LanguagesEnum$1["Chinese_HKG"] = "zh_HK";
235
+ LanguagesEnum$1["Chinese_TAI"] = "zh_TW";
236
+ LanguagesEnum$1["Croatian"] = "hr";
237
+ LanguagesEnum$1["Czech"] = "cs";
238
+ LanguagesEnum$1["Danish"] = "da";
239
+ LanguagesEnum$1["Dutch"] = "nl";
240
+ LanguagesEnum$1["English"] = "en";
241
+ LanguagesEnum$1["English_UK"] = "en_GB";
242
+ LanguagesEnum$1["English_US"] = "en_US";
243
+ LanguagesEnum$1["Estonian"] = "et";
244
+ LanguagesEnum$1["Filipino"] = "fil";
245
+ LanguagesEnum$1["Finnish"] = "fi";
246
+ LanguagesEnum$1["French"] = "fr";
247
+ LanguagesEnum$1["Georgian"] = "ka";
248
+ LanguagesEnum$1["German"] = "de";
249
+ LanguagesEnum$1["Greek"] = "el";
250
+ LanguagesEnum$1["Gujarati"] = "gu";
251
+ LanguagesEnum$1["Hausa"] = "ha";
252
+ LanguagesEnum$1["Hebrew"] = "he";
253
+ LanguagesEnum$1["Hindi"] = "hi";
254
+ LanguagesEnum$1["Hungarian"] = "hu";
255
+ LanguagesEnum$1["Indonesian"] = "id";
256
+ LanguagesEnum$1["Irish"] = "ga";
257
+ LanguagesEnum$1["Italian"] = "it";
258
+ LanguagesEnum$1["Japanese"] = "ja";
259
+ LanguagesEnum$1["Kannada"] = "kn";
260
+ LanguagesEnum$1["Kazakh"] = "kk";
261
+ LanguagesEnum$1["Kinyarwanda"] = "rw_RW";
262
+ LanguagesEnum$1["Korean"] = "ko";
263
+ LanguagesEnum$1["Kyrgyz_Kyrgyzstan"] = "ky_KG";
264
+ LanguagesEnum$1["Lao"] = "lo";
265
+ LanguagesEnum$1["Latvian"] = "lv";
266
+ LanguagesEnum$1["Lithuanian"] = "lt";
267
+ LanguagesEnum$1["Macedonian"] = "mk";
268
+ LanguagesEnum$1["Malay"] = "ms";
269
+ LanguagesEnum$1["Malayalam"] = "ml";
270
+ LanguagesEnum$1["Marathi"] = "mr";
271
+ LanguagesEnum$1["Norwegian"] = "nb";
272
+ LanguagesEnum$1["Persian"] = "fa";
273
+ LanguagesEnum$1["Polish"] = "pl";
274
+ LanguagesEnum$1["Portuguese_BR"] = "pt_BR";
275
+ LanguagesEnum$1["Portuguese_POR"] = "pt_PT";
276
+ LanguagesEnum$1["Punjabi"] = "pa";
277
+ LanguagesEnum$1["Romanian"] = "ro";
278
+ LanguagesEnum$1["Russian"] = "ru";
279
+ LanguagesEnum$1["Serbian"] = "sr";
280
+ LanguagesEnum$1["Slovak"] = "sk";
281
+ LanguagesEnum$1["Slovenian"] = "sl";
282
+ LanguagesEnum$1["Spanish"] = "es";
283
+ LanguagesEnum$1["Spanish_ARG"] = "es_AR";
284
+ LanguagesEnum$1["Spanish_SPA"] = "es_ES";
285
+ LanguagesEnum$1["Spanish_MEX"] = "es_MX";
286
+ LanguagesEnum$1["Swahili"] = "sw";
287
+ LanguagesEnum$1["Swedish"] = "sv";
288
+ LanguagesEnum$1["Tamil"] = "ta";
289
+ LanguagesEnum$1["Telugu"] = "te";
290
+ LanguagesEnum$1["Thai"] = "th";
291
+ LanguagesEnum$1["Turkish"] = "tr";
292
+ LanguagesEnum$1["Ukrainian"] = "uk";
293
+ LanguagesEnum$1["Urdu"] = "ur";
294
+ LanguagesEnum$1["Uzbek"] = "uz";
295
+ LanguagesEnum$1["Vietnamese"] = "vi";
296
+ LanguagesEnum$1["Zulu"] = "zu";
297
+ return LanguagesEnum$1;
298
+ }({});
299
+ let CurrencyCodesEnum = /* @__PURE__ */ function(CurrencyCodesEnum$1) {
300
+ CurrencyCodesEnum$1["AFN"] = "AFN";
301
+ CurrencyCodesEnum$1["EUR"] = "EUR";
302
+ CurrencyCodesEnum$1["ALL"] = "ALL";
303
+ CurrencyCodesEnum$1["DZD"] = "DZD";
304
+ CurrencyCodesEnum$1["USD"] = "USD";
305
+ CurrencyCodesEnum$1["AOA"] = "AOA";
306
+ CurrencyCodesEnum$1["XCD"] = "XCD";
307
+ CurrencyCodesEnum$1["ARS"] = "ARS";
308
+ CurrencyCodesEnum$1["AMD"] = "AMD";
309
+ CurrencyCodesEnum$1["AWG"] = "AWG";
310
+ CurrencyCodesEnum$1["AUD"] = "AUD";
311
+ CurrencyCodesEnum$1["AZN"] = "AZN";
312
+ CurrencyCodesEnum$1["BSD"] = "BSD";
313
+ CurrencyCodesEnum$1["BHD"] = "BHD";
314
+ CurrencyCodesEnum$1["BDT"] = "BDT";
315
+ CurrencyCodesEnum$1["BBD"] = "BBD";
316
+ CurrencyCodesEnum$1["BYN"] = "BYN";
317
+ CurrencyCodesEnum$1["BZD"] = "BZD";
318
+ CurrencyCodesEnum$1["XOF"] = "XOF";
319
+ CurrencyCodesEnum$1["BMD"] = "BMD";
320
+ CurrencyCodesEnum$1["INR"] = "INR";
321
+ CurrencyCodesEnum$1["BTN"] = "BTN";
322
+ CurrencyCodesEnum$1["BOB"] = "BOB";
323
+ CurrencyCodesEnum$1["BOV"] = "BOV";
324
+ CurrencyCodesEnum$1["BAM"] = "BAM";
325
+ CurrencyCodesEnum$1["BWP"] = "BWP";
326
+ CurrencyCodesEnum$1["NOK"] = "NOK";
327
+ CurrencyCodesEnum$1["BRL"] = "BRL";
328
+ CurrencyCodesEnum$1["BND"] = "BND";
329
+ CurrencyCodesEnum$1["BGN"] = "BGN";
330
+ CurrencyCodesEnum$1["BIF"] = "BIF";
331
+ CurrencyCodesEnum$1["CVE"] = "CVE";
332
+ CurrencyCodesEnum$1["KHR"] = "KHR";
333
+ CurrencyCodesEnum$1["XAF"] = "XAF";
334
+ CurrencyCodesEnum$1["CAD"] = "CAD";
335
+ CurrencyCodesEnum$1["KYD"] = "KYD";
336
+ CurrencyCodesEnum$1["CLP"] = "CLP";
337
+ CurrencyCodesEnum$1["CLF"] = "CLF";
338
+ CurrencyCodesEnum$1["CNY"] = "CNY";
339
+ CurrencyCodesEnum$1["COP"] = "COP";
340
+ CurrencyCodesEnum$1["COU"] = "COU";
341
+ CurrencyCodesEnum$1["KMF"] = "KMF";
342
+ CurrencyCodesEnum$1["CDF"] = "CDF";
343
+ CurrencyCodesEnum$1["NZD"] = "NZD";
344
+ CurrencyCodesEnum$1["CRC"] = "CRC";
345
+ CurrencyCodesEnum$1["HRK"] = "HRK";
346
+ CurrencyCodesEnum$1["CUP"] = "CUP";
347
+ CurrencyCodesEnum$1["CUC"] = "CUC";
348
+ CurrencyCodesEnum$1["ANG"] = "ANG";
349
+ CurrencyCodesEnum$1["CZK"] = "CZK";
350
+ CurrencyCodesEnum$1["DKK"] = "DKK";
351
+ CurrencyCodesEnum$1["DJF"] = "DJF";
352
+ CurrencyCodesEnum$1["DOP"] = "DOP";
353
+ CurrencyCodesEnum$1["EGP"] = "EGP";
354
+ CurrencyCodesEnum$1["SVC"] = "SVC";
355
+ CurrencyCodesEnum$1["ERN"] = "ERN";
356
+ CurrencyCodesEnum$1["SZL"] = "SZL";
357
+ CurrencyCodesEnum$1["ETB"] = "ETB";
358
+ CurrencyCodesEnum$1["FKP"] = "FKP";
359
+ CurrencyCodesEnum$1["FJD"] = "FJD";
360
+ CurrencyCodesEnum$1["XPF"] = "XPF";
361
+ CurrencyCodesEnum$1["GMD"] = "GMD";
362
+ CurrencyCodesEnum$1["GEL"] = "GEL";
363
+ CurrencyCodesEnum$1["GHS"] = "GHS";
364
+ CurrencyCodesEnum$1["GIP"] = "GIP";
365
+ CurrencyCodesEnum$1["GTQ"] = "GTQ";
366
+ CurrencyCodesEnum$1["GBP"] = "GBP";
367
+ CurrencyCodesEnum$1["GNF"] = "GNF";
368
+ CurrencyCodesEnum$1["GYD"] = "GYD";
369
+ CurrencyCodesEnum$1["HTG"] = "HTG";
370
+ CurrencyCodesEnum$1["HNL"] = "HNL";
371
+ CurrencyCodesEnum$1["HKD"] = "HKD";
372
+ CurrencyCodesEnum$1["HUF"] = "HUF";
373
+ CurrencyCodesEnum$1["ISK"] = "ISK";
374
+ CurrencyCodesEnum$1["IDR"] = "IDR";
375
+ CurrencyCodesEnum$1["XDR"] = "XDR";
376
+ CurrencyCodesEnum$1["IRR"] = "IRR";
377
+ CurrencyCodesEnum$1["IQD"] = "IQD";
378
+ CurrencyCodesEnum$1["ILS"] = "ILS";
379
+ CurrencyCodesEnum$1["JMD"] = "JMD";
380
+ CurrencyCodesEnum$1["JPY"] = "JPY";
381
+ CurrencyCodesEnum$1["JOD"] = "JOD";
382
+ CurrencyCodesEnum$1["KZT"] = "KZT";
383
+ CurrencyCodesEnum$1["KES"] = "KES";
384
+ CurrencyCodesEnum$1["KPW"] = "KPW";
385
+ CurrencyCodesEnum$1["KRW"] = "KRW";
386
+ CurrencyCodesEnum$1["KWD"] = "KWD";
387
+ CurrencyCodesEnum$1["KGS"] = "KGS";
388
+ CurrencyCodesEnum$1["LAK"] = "LAK";
389
+ CurrencyCodesEnum$1["LBP"] = "LBP";
390
+ CurrencyCodesEnum$1["LSL"] = "LSL";
391
+ CurrencyCodesEnum$1["ZAR"] = "ZAR";
392
+ CurrencyCodesEnum$1["LRD"] = "LRD";
393
+ CurrencyCodesEnum$1["LYD"] = "LYD";
394
+ CurrencyCodesEnum$1["CHF"] = "CHF";
395
+ CurrencyCodesEnum$1["MOP"] = "MOP";
396
+ CurrencyCodesEnum$1["MKD"] = "MKD";
397
+ CurrencyCodesEnum$1["MGA"] = "MGA";
398
+ CurrencyCodesEnum$1["MWK"] = "MWK";
399
+ CurrencyCodesEnum$1["MYR"] = "MYR";
400
+ CurrencyCodesEnum$1["MVR"] = "MVR";
401
+ CurrencyCodesEnum$1["MRU"] = "MRU";
402
+ CurrencyCodesEnum$1["MUR"] = "MUR";
403
+ CurrencyCodesEnum$1["XUA"] = "XUA";
404
+ CurrencyCodesEnum$1["MXN"] = "MXN";
405
+ CurrencyCodesEnum$1["MXV"] = "MXV";
406
+ CurrencyCodesEnum$1["MDL"] = "MDL";
407
+ CurrencyCodesEnum$1["MNT"] = "MNT";
408
+ CurrencyCodesEnum$1["MAD"] = "MAD";
409
+ CurrencyCodesEnum$1["MZN"] = "MZN";
410
+ CurrencyCodesEnum$1["MMK"] = "MMK";
411
+ CurrencyCodesEnum$1["NAD"] = "NAD";
412
+ CurrencyCodesEnum$1["NPR"] = "NPR";
413
+ CurrencyCodesEnum$1["NIO"] = "NIO";
414
+ CurrencyCodesEnum$1["NGN"] = "NGN";
415
+ CurrencyCodesEnum$1["OMR"] = "OMR";
416
+ CurrencyCodesEnum$1["PKR"] = "PKR";
417
+ CurrencyCodesEnum$1["PAB"] = "PAB";
418
+ CurrencyCodesEnum$1["PGK"] = "PGK";
419
+ CurrencyCodesEnum$1["PYG"] = "PYG";
420
+ CurrencyCodesEnum$1["PEN"] = "PEN";
421
+ CurrencyCodesEnum$1["PHP"] = "PHP";
422
+ CurrencyCodesEnum$1["PLN"] = "PLN";
423
+ CurrencyCodesEnum$1["QAR"] = "QAR";
424
+ CurrencyCodesEnum$1["RON"] = "RON";
425
+ CurrencyCodesEnum$1["RUB"] = "RUB";
426
+ CurrencyCodesEnum$1["RWF"] = "RWF";
427
+ CurrencyCodesEnum$1["SHP"] = "SHP";
428
+ CurrencyCodesEnum$1["WST"] = "WST";
429
+ CurrencyCodesEnum$1["STN"] = "STN";
430
+ CurrencyCodesEnum$1["SAR"] = "SAR";
431
+ CurrencyCodesEnum$1["RSD"] = "RSD";
432
+ CurrencyCodesEnum$1["SCR"] = "SCR";
433
+ CurrencyCodesEnum$1["SLL"] = "SLL";
434
+ CurrencyCodesEnum$1["SGD"] = "SGD";
435
+ CurrencyCodesEnum$1["XSU"] = "XSU";
436
+ CurrencyCodesEnum$1["SBD"] = "SBD";
437
+ CurrencyCodesEnum$1["SOS"] = "SOS";
438
+ CurrencyCodesEnum$1["SSP"] = "SSP";
439
+ CurrencyCodesEnum$1["LKR"] = "LKR";
440
+ CurrencyCodesEnum$1["SDG"] = "SDG";
441
+ CurrencyCodesEnum$1["SRD"] = "SRD";
442
+ CurrencyCodesEnum$1["SEK"] = "SEK";
443
+ CurrencyCodesEnum$1["CHE"] = "CHE";
444
+ CurrencyCodesEnum$1["CHW"] = "CHW";
445
+ CurrencyCodesEnum$1["SYP"] = "SYP";
446
+ CurrencyCodesEnum$1["TWD"] = "TWD";
447
+ CurrencyCodesEnum$1["TJS"] = "TJS";
448
+ CurrencyCodesEnum$1["TZS"] = "TZS";
449
+ CurrencyCodesEnum$1["THB"] = "THB";
450
+ CurrencyCodesEnum$1["TOP"] = "TOP";
451
+ CurrencyCodesEnum$1["TTD"] = "TTD";
452
+ CurrencyCodesEnum$1["TND"] = "TND";
453
+ CurrencyCodesEnum$1["TRY"] = "TRY";
454
+ CurrencyCodesEnum$1["TMT"] = "TMT";
455
+ CurrencyCodesEnum$1["UGX"] = "UGX";
456
+ CurrencyCodesEnum$1["UAH"] = "UAH";
457
+ CurrencyCodesEnum$1["AED"] = "AED";
458
+ CurrencyCodesEnum$1["USN"] = "USN";
459
+ CurrencyCodesEnum$1["UYU"] = "UYU";
460
+ CurrencyCodesEnum$1["UYI"] = "UYI";
461
+ CurrencyCodesEnum$1["UYW"] = "UYW";
462
+ CurrencyCodesEnum$1["UZS"] = "UZS";
463
+ CurrencyCodesEnum$1["VUV"] = "VUV";
464
+ CurrencyCodesEnum$1["VES"] = "VES";
465
+ CurrencyCodesEnum$1["VND"] = "VND";
466
+ CurrencyCodesEnum$1["YER"] = "YER";
467
+ CurrencyCodesEnum$1["ZMW"] = "ZMW";
468
+ CurrencyCodesEnum$1["ZWL"] = "ZWL";
469
+ CurrencyCodesEnum$1["XBA"] = "XBA";
470
+ CurrencyCodesEnum$1["XBB"] = "XBB";
471
+ CurrencyCodesEnum$1["XBC"] = "XBC";
472
+ CurrencyCodesEnum$1["XBD"] = "XBD";
473
+ CurrencyCodesEnum$1["XTS"] = "XTS";
474
+ CurrencyCodesEnum$1["XXX"] = "XXX";
475
+ CurrencyCodesEnum$1["XAU"] = "XAU";
476
+ CurrencyCodesEnum$1["XPD"] = "XPD";
477
+ CurrencyCodesEnum$1["XPT"] = "XPT";
478
+ CurrencyCodesEnum$1["XAG"] = "XAG";
479
+ CurrencyCodesEnum$1["AFA"] = "AFA";
480
+ CurrencyCodesEnum$1["FIM"] = "FIM";
481
+ CurrencyCodesEnum$1["ALK"] = "ALK";
482
+ CurrencyCodesEnum$1["ADP"] = "ADP";
483
+ CurrencyCodesEnum$1["ESP"] = "ESP";
484
+ CurrencyCodesEnum$1["FRF"] = "FRF";
485
+ CurrencyCodesEnum$1["AOK"] = "AOK";
486
+ CurrencyCodesEnum$1["AON"] = "AON";
487
+ CurrencyCodesEnum$1["AOR"] = "AOR";
488
+ CurrencyCodesEnum$1["ARA"] = "ARA";
489
+ CurrencyCodesEnum$1["ARP"] = "ARP";
490
+ CurrencyCodesEnum$1["ARY"] = "ARY";
491
+ CurrencyCodesEnum$1["RUR"] = "RUR";
492
+ CurrencyCodesEnum$1["ATS"] = "ATS";
493
+ CurrencyCodesEnum$1["AYM"] = "AYM";
494
+ CurrencyCodesEnum$1["AZM"] = "AZM";
495
+ CurrencyCodesEnum$1["BYB"] = "BYB";
496
+ CurrencyCodesEnum$1["BYR"] = "BYR";
497
+ CurrencyCodesEnum$1["BEC"] = "BEC";
498
+ CurrencyCodesEnum$1["BEF"] = "BEF";
499
+ CurrencyCodesEnum$1["BEL"] = "BEL";
500
+ CurrencyCodesEnum$1["BOP"] = "BOP";
501
+ CurrencyCodesEnum$1["BAD"] = "BAD";
502
+ CurrencyCodesEnum$1["BRB"] = "BRB";
503
+ CurrencyCodesEnum$1["BRC"] = "BRC";
504
+ CurrencyCodesEnum$1["BRE"] = "BRE";
505
+ CurrencyCodesEnum$1["BRN"] = "BRN";
506
+ CurrencyCodesEnum$1["BRR"] = "BRR";
507
+ CurrencyCodesEnum$1["BGJ"] = "BGJ";
508
+ CurrencyCodesEnum$1["BGK"] = "BGK";
509
+ CurrencyCodesEnum$1["BGL"] = "BGL";
510
+ CurrencyCodesEnum$1["BUK"] = "BUK";
511
+ CurrencyCodesEnum$1["HRD"] = "HRD";
512
+ CurrencyCodesEnum$1["CYP"] = "CYP";
513
+ CurrencyCodesEnum$1["CSJ"] = "CSJ";
514
+ CurrencyCodesEnum$1["CSK"] = "CSK";
515
+ CurrencyCodesEnum$1["ECS"] = "ECS";
516
+ CurrencyCodesEnum$1["ECV"] = "ECV";
517
+ CurrencyCodesEnum$1["GQE"] = "GQE";
518
+ CurrencyCodesEnum$1["EEK"] = "EEK";
519
+ CurrencyCodesEnum$1["XEU"] = "XEU";
520
+ CurrencyCodesEnum$1["GEK"] = "GEK";
521
+ CurrencyCodesEnum$1["DDM"] = "DDM";
522
+ CurrencyCodesEnum$1["DEM"] = "DEM";
523
+ CurrencyCodesEnum$1["GHC"] = "GHC";
524
+ CurrencyCodesEnum$1["GHP"] = "GHP";
525
+ CurrencyCodesEnum$1["GRD"] = "GRD";
526
+ CurrencyCodesEnum$1["GNE"] = "GNE";
527
+ CurrencyCodesEnum$1["GNS"] = "GNS";
528
+ CurrencyCodesEnum$1["GWE"] = "GWE";
529
+ CurrencyCodesEnum$1["GWP"] = "GWP";
530
+ CurrencyCodesEnum$1["ITL"] = "ITL";
531
+ CurrencyCodesEnum$1["ISJ"] = "ISJ";
532
+ CurrencyCodesEnum$1["IEP"] = "IEP";
533
+ CurrencyCodesEnum$1["ILP"] = "ILP";
534
+ CurrencyCodesEnum$1["ILR"] = "ILR";
535
+ CurrencyCodesEnum$1["LAJ"] = "LAJ";
536
+ CurrencyCodesEnum$1["LVL"] = "LVL";
537
+ CurrencyCodesEnum$1["LVR"] = "LVR";
538
+ CurrencyCodesEnum$1["LSM"] = "LSM";
539
+ CurrencyCodesEnum$1["ZAL"] = "ZAL";
540
+ CurrencyCodesEnum$1["LTL"] = "LTL";
541
+ CurrencyCodesEnum$1["LTT"] = "LTT";
542
+ CurrencyCodesEnum$1["LUC"] = "LUC";
543
+ CurrencyCodesEnum$1["LUF"] = "LUF";
544
+ CurrencyCodesEnum$1["LUL"] = "LUL";
545
+ CurrencyCodesEnum$1["MGF"] = "MGF";
546
+ CurrencyCodesEnum$1["MVQ"] = "MVQ";
547
+ CurrencyCodesEnum$1["MLF"] = "MLF";
548
+ CurrencyCodesEnum$1["MTL"] = "MTL";
549
+ CurrencyCodesEnum$1["MTP"] = "MTP";
550
+ CurrencyCodesEnum$1["MRO"] = "MRO";
551
+ CurrencyCodesEnum$1["MXP"] = "MXP";
552
+ CurrencyCodesEnum$1["MZE"] = "MZE";
553
+ CurrencyCodesEnum$1["MZM"] = "MZM";
554
+ CurrencyCodesEnum$1["NLG"] = "NLG";
555
+ CurrencyCodesEnum$1["NIC"] = "NIC";
556
+ CurrencyCodesEnum$1["PEH"] = "PEH";
557
+ CurrencyCodesEnum$1["PEI"] = "PEI";
558
+ CurrencyCodesEnum$1["PES"] = "PES";
559
+ CurrencyCodesEnum$1["PLZ"] = "PLZ";
560
+ CurrencyCodesEnum$1["PTE"] = "PTE";
561
+ CurrencyCodesEnum$1["ROK"] = "ROK";
562
+ CurrencyCodesEnum$1["ROL"] = "ROL";
563
+ CurrencyCodesEnum$1["STD"] = "STD";
564
+ CurrencyCodesEnum$1["CSD"] = "CSD";
565
+ CurrencyCodesEnum$1["SKK"] = "SKK";
566
+ CurrencyCodesEnum$1["SIT"] = "SIT";
567
+ CurrencyCodesEnum$1["RHD"] = "RHD";
568
+ CurrencyCodesEnum$1["ESA"] = "ESA";
569
+ CurrencyCodesEnum$1["ESB"] = "ESB";
570
+ CurrencyCodesEnum$1["SDD"] = "SDD";
571
+ CurrencyCodesEnum$1["SDP"] = "SDP";
572
+ CurrencyCodesEnum$1["SRG"] = "SRG";
573
+ CurrencyCodesEnum$1["CHC"] = "CHC";
574
+ CurrencyCodesEnum$1["TJR"] = "TJR";
575
+ CurrencyCodesEnum$1["TPE"] = "TPE";
576
+ CurrencyCodesEnum$1["TRL"] = "TRL";
577
+ CurrencyCodesEnum$1["TMM"] = "TMM";
578
+ CurrencyCodesEnum$1["UGS"] = "UGS";
579
+ CurrencyCodesEnum$1["UGW"] = "UGW";
580
+ CurrencyCodesEnum$1["UAK"] = "UAK";
581
+ CurrencyCodesEnum$1["SUR"] = "SUR";
582
+ CurrencyCodesEnum$1["USS"] = "USS";
583
+ CurrencyCodesEnum$1["UYN"] = "UYN";
584
+ CurrencyCodesEnum$1["UYP"] = "UYP";
585
+ CurrencyCodesEnum$1["VEB"] = "VEB";
586
+ CurrencyCodesEnum$1["VEF"] = "VEF";
587
+ CurrencyCodesEnum$1["VNC"] = "VNC";
588
+ CurrencyCodesEnum$1["YDD"] = "YDD";
589
+ CurrencyCodesEnum$1["YUD"] = "YUD";
590
+ CurrencyCodesEnum$1["YUM"] = "YUM";
591
+ CurrencyCodesEnum$1["YUN"] = "YUN";
592
+ CurrencyCodesEnum$1["ZRN"] = "ZRN";
593
+ CurrencyCodesEnum$1["ZRZ"] = "ZRZ";
594
+ CurrencyCodesEnum$1["ZMK"] = "ZMK";
595
+ CurrencyCodesEnum$1["ZWC"] = "ZWC";
596
+ CurrencyCodesEnum$1["ZWD"] = "ZWD";
597
+ CurrencyCodesEnum$1["ZWN"] = "ZWN";
598
+ CurrencyCodesEnum$1["ZWR"] = "ZWR";
599
+ CurrencyCodesEnum$1["XFO"] = "XFO";
600
+ CurrencyCodesEnum$1["XRE"] = "XRE";
601
+ CurrencyCodesEnum$1["XFU"] = "XFU";
602
+ return CurrencyCodesEnum$1;
603
+ }({});
604
+ let DataLocalizationRegionEnum = /* @__PURE__ */ function(DataLocalizationRegionEnum$1) {
605
+ DataLocalizationRegionEnum$1["AU"] = "AU";
606
+ DataLocalizationRegionEnum$1["ID"] = "ID";
607
+ DataLocalizationRegionEnum$1["IN"] = "IN";
608
+ DataLocalizationRegionEnum$1["JP"] = "JP";
609
+ DataLocalizationRegionEnum$1["SG"] = "SG";
610
+ DataLocalizationRegionEnum$1["KR"] = "KR";
611
+ DataLocalizationRegionEnum$1["DE"] = "DE";
612
+ DataLocalizationRegionEnum$1["CH"] = "CH";
613
+ DataLocalizationRegionEnum$1["GB"] = "GB";
614
+ DataLocalizationRegionEnum$1["BR"] = "BR";
615
+ DataLocalizationRegionEnum$1["BH"] = "BH";
616
+ DataLocalizationRegionEnum$1["ZA"] = "ZA";
617
+ DataLocalizationRegionEnum$1["AE"] = "AE";
618
+ DataLocalizationRegionEnum$1["CA"] = "CA";
619
+ return DataLocalizationRegionEnum$1;
620
+ }({});
621
+ /**
622
+ * Business category values for WhatsApp Business Profile.
623
+ * These values map to specific strings displayed in the WhatsApp client.
624
+ */
625
+ let BusinessVerticalEnum = /* @__PURE__ */ function(BusinessVerticalEnum$1) {
626
+ /**
627
+ * Alcoholic Beverages
628
+ */
629
+ BusinessVerticalEnum$1["ALCOHOL"] = "ALCOHOL";
630
+ /**
631
+ * Clothing and Apparel
632
+ */
633
+ BusinessVerticalEnum$1["APPAREL"] = "APPAREL";
634
+ /**
635
+ * Automotive
636
+ */
637
+ BusinessVerticalEnum$1["AUTO"] = "AUTO";
638
+ /**
639
+ * Beauty, Spa and Salon
640
+ */
641
+ BusinessVerticalEnum$1["BEAUTY"] = "BEAUTY";
642
+ /**
643
+ * Education
644
+ */
645
+ BusinessVerticalEnum$1["EDU"] = "EDU";
646
+ /**
647
+ * Entertainment
648
+ */
649
+ BusinessVerticalEnum$1["ENTERTAIN"] = "ENTERTAIN";
650
+ /**
651
+ * Event Planning and Service
652
+ */
653
+ BusinessVerticalEnum$1["EVENT_PLAN"] = "EVENT_PLAN";
654
+ /**
655
+ * Finance and Banking
656
+ */
657
+ BusinessVerticalEnum$1["FINANCE"] = "FINANCE";
658
+ /**
659
+ * Public Service
660
+ */
661
+ BusinessVerticalEnum$1["GOVT"] = "GOVT";
662
+ /**
663
+ * Food and Grocery
664
+ */
665
+ BusinessVerticalEnum$1["GROCERY"] = "GROCERY";
666
+ /**
667
+ * Medical and Health
668
+ */
669
+ BusinessVerticalEnum$1["HEALTH"] = "HEALTH";
670
+ /**
671
+ * Hotel and Lodging
672
+ */
673
+ BusinessVerticalEnum$1["HOTEL"] = "HOTEL";
674
+ /**
675
+ * Non-profit
676
+ */
677
+ BusinessVerticalEnum$1["NONPROFIT"] = "NONPROFIT";
678
+ /**
679
+ * Online Gambling & Gaming
680
+ */
681
+ BusinessVerticalEnum$1["ONLINE_GAMBLING"] = "ONLINE_GAMBLING";
682
+ /**
683
+ * Over-the-Counter Drugs
684
+ */
685
+ BusinessVerticalEnum$1["OTC_DRUGS"] = "OTC_DRUGS";
686
+ /**
687
+ * Other
688
+ */
689
+ BusinessVerticalEnum$1["OTHER"] = "OTHER";
690
+ /**
691
+ * Non-Online Gambling & Gaming (E.g. Brick and mortar)
692
+ */
693
+ BusinessVerticalEnum$1["PHYSICAL_GAMBLING"] = "PHYSICAL_GAMBLING";
694
+ /**
695
+ * Professional Services
696
+ */
697
+ BusinessVerticalEnum$1["PROF_SERVICES"] = "PROF_SERVICES";
698
+ /**
699
+ * Restaurant
700
+ */
701
+ BusinessVerticalEnum$1["RESTAURANT"] = "RESTAURANT";
702
+ /**
703
+ * Shopping and Retail
704
+ */
705
+ BusinessVerticalEnum$1["RETAIL"] = "RETAIL";
706
+ /**
707
+ * Travel and Transportation
708
+ */
709
+ BusinessVerticalEnum$1["TRAVEL"] = "TRAVEL";
710
+ return BusinessVerticalEnum$1;
711
+ }({});
712
+
713
+ //#endregion
714
+ //#region src/utils/logger.ts
715
+ var Logger = class {
716
+ name;
717
+ debug;
718
+ constructor(name, debug = false) {
719
+ this.name = name;
720
+ this.debug = debug;
721
+ }
722
+ log(...data) {
723
+ if (this.debug) {
724
+ let prefix = `[ ${Date.now()} ]`;
725
+ if (this.name) {
726
+ prefix += ` - ${this.name}`;
727
+ }
728
+ console.log.apply(console, [
729
+ prefix,
730
+ ": ",
731
+ ...data
732
+ ]);
733
+ }
734
+ }
735
+ error(...data) {
736
+ let prefix = `[ ${Date.now()} ] - ERROR`;
737
+ if (this.name) {
738
+ prefix += ` - ${this.name}`;
739
+ }
740
+ console.error.apply(console, [
741
+ prefix,
742
+ ": ",
743
+ ...data
744
+ ]);
745
+ }
746
+ warn(...data) {
747
+ let prefix = `[ ${Date.now()} ] - WARN`;
748
+ if (this.name) {
749
+ prefix += ` - ${this.name}`;
750
+ }
751
+ console.warn.apply(console, [
752
+ prefix,
753
+ ": ",
754
+ ...data
755
+ ]);
756
+ }
757
+ info(...data) {
758
+ let prefix = `[ ${Date.now()} ] - INFO`;
759
+ if (this.name) {
760
+ prefix += ` - ${this.name}`;
761
+ }
762
+ console.info.apply(console, [
763
+ prefix,
764
+ ": ",
765
+ ...data
766
+ ]);
767
+ }
768
+ };
769
+
770
+ //#endregion
771
+ //#region src/config/importConfig.ts
772
+ const LIB_NAME$4 = "UTILS";
773
+ const LOG_LOCAL$2 = false;
774
+ const LOGGER$5 = new Logger(LIB_NAME$4, process.env.DEBUG === "true" || LOG_LOCAL$2);
775
+ const DEFAULT_LISTENER_PORT = 3e3;
776
+ const DEFAULT_MAX_RETRIES_AFTER_WAIT = 30;
777
+ const DEFAULT_REQUEST_TIMEOUT = 2e4;
778
+ const emptyConfigChecker = (config) => {
779
+ if (!process.env[WabaConfigEnum.AccessToken] && !config?.accessToken) {
780
+ LOGGER$5.log(`Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined.`);
781
+ throw new Error("Missing WhatsApp access token.");
782
+ }
783
+ };
784
+ const importConfig = (inputConfig) => {
785
+ emptyConfigChecker(inputConfig);
786
+ const wabaConfig = {
787
+ [WabaConfigEnum.AppId]: inputConfig?.appId || process.env.M4D_APP_ID || "",
788
+ [WabaConfigEnum.AppSecret]: inputConfig?.appSecret || process.env.M4D_APP_SECRET || "",
789
+ [WabaConfigEnum.PhoneNumberId]: inputConfig?.phoneNumberId || Number(process.env.WA_PHONE_NUMBER_ID),
790
+ [WabaConfigEnum.BusinessAcctId]: inputConfig?.businessAcctId || process.env.WA_BUSINESS_ACCOUNT_ID || "",
791
+ [WabaConfigEnum.APIVersion]: inputConfig?.apiVersion || process.env.CLOUD_API_VERSION || "",
792
+ [WabaConfigEnum.AccessToken]: inputConfig?.accessToken || process.env.CLOUD_API_ACCESS_TOKEN || "",
793
+ [WabaConfigEnum.WebhookEndpoint]: inputConfig?.webhookEndpoint || process.env.WEBHOOK_ENDPOINT || "",
794
+ [WabaConfigEnum.WebhookVerificationToken]: inputConfig?.webhookVerificationToken || process.env.WEBHOOK_VERIFICATION_TOKEN || "",
795
+ [WabaConfigEnum.ListenerPort]: inputConfig?.listenerPort || parseInt(process.env.LISTENER_PORT || "") || DEFAULT_LISTENER_PORT,
796
+ [WabaConfigEnum.MaxRetriesAfterWait]: inputConfig?.maxRetriesAfterWait || parseInt(process.env.MAX_RETRIES_AFTER_WAIT || "") || DEFAULT_MAX_RETRIES_AFTER_WAIT,
797
+ [WabaConfigEnum.RequestTimeout]: inputConfig?.requestTimeout || parseInt(process.env.REQUEST_TIMEOUT || "") || DEFAULT_REQUEST_TIMEOUT,
798
+ [WabaConfigEnum.Debug]: inputConfig?.debug || process.env.DEBUG === "true",
799
+ [WabaConfigEnum.PrivatePem]: inputConfig?.privatePem || process.env.FLOW_API_PRIVATE_PEM || "",
800
+ [WabaConfigEnum.Passphrase]: inputConfig?.passphrase || process.env.FLOW_API_PASSPHRASE || ""
801
+ };
802
+ return wabaConfig;
803
+ };
804
+
805
+ //#endregion
806
+ //#region src/utils/configTable.ts
807
+ /**
808
+ * Formats configuration as a terminal table
809
+ * @param config - The WABA configuration object
810
+ * @param apiName - The name of the API being initialized
811
+ * @returns Formatted table string
812
+ */
813
+ function formatConfigTable(config) {
814
+ const configData = [
815
+ ["App ID", config[WabaConfigEnum.AppId] || "Not Set"],
816
+ ["Phone Number ID", config[WabaConfigEnum.PhoneNumberId]?.toString() || "Not Set"],
817
+ ["Business Account ID", config[WabaConfigEnum.BusinessAcctId] || "Not Set"],
818
+ ["API Version", config[WabaConfigEnum.APIVersion] || "Not Set"],
819
+ ["Access Token", config[WabaConfigEnum.AccessToken] ? `${config[WabaConfigEnum.AccessToken].substring(0, 20)}...` : "Not Set"],
820
+ ["Webhook Endpoint", config[WabaConfigEnum.WebhookEndpoint] || "Not Set"],
821
+ ["Webhook Verification Token", config[WabaConfigEnum.WebhookVerificationToken] ? `${config[WabaConfigEnum.WebhookVerificationToken].substring(0, 10)}...` : "Not Set"],
822
+ ["Listener Port", config[WabaConfigEnum.ListenerPort]?.toString() || "Not Set"],
823
+ ["Debug Mode", config[WabaConfigEnum.Debug] ? "Enabled" : "Disabled"],
824
+ ["Max Retries", config[WabaConfigEnum.MaxRetriesAfterWait]?.toString() || "Not Set"],
825
+ ["Request Timeout", config[WabaConfigEnum.RequestTimeout] ? `${config[WabaConfigEnum.RequestTimeout]}ms` : "Not Set"],
826
+ ["Private PEM", config[WabaConfigEnum.PrivatePem] ? "Configured" : "Not Set"],
827
+ ["Passphrase", config[WabaConfigEnum.Passphrase] ? "Configured" : "Not Set"]
828
+ ];
829
+ const maxKeyLength = Math.max(...configData.map(([key]) => key?.length || 0));
830
+ const maxValueLength = Math.max(...configData.map(([, value]) => value?.length || 0));
831
+ const keyWidth = Math.max(maxKeyLength, 20);
832
+ const valueWidth = Math.max(maxValueLength, 30);
833
+ const horizontalLine = `┌${"─".repeat(keyWidth + 2)}┬${"─".repeat(valueWidth + 2)}┐`;
834
+ const separator = `├${"─".repeat(keyWidth + 2)}┼${"─".repeat(valueWidth + 2)}┤`;
835
+ const bottomLine = `└${"─".repeat(keyWidth + 2)}┴${"─".repeat(valueWidth + 2)}┘`;
836
+ const header = `│ ${"Configuration".padEnd(keyWidth)} │ ${"Value".padEnd(valueWidth)} │`;
837
+ const rows = configData.map(([key, value]) => `│ ${key?.padEnd(keyWidth)} │ ${value?.padEnd(valueWidth)} │`);
838
+ return [
839
+ horizontalLine,
840
+ header,
841
+ separator,
842
+ ...rows,
843
+ bottomLine
844
+ ].join("\n");
845
+ }
846
+
847
+ //#endregion
848
+ //#region src/utils/isMetaError.ts
849
+ /**
850
+ * Determines if the error is a Meta API error response
851
+ * @param error Any error object to check
852
+ * @returns Type guard indicating if error is a Meta API error
853
+ */
854
+ function isMetaError(error) {
855
+ return error != null && typeof error === "object" && "error" in error && typeof error.error === "object" && error.error != null && "message" in error.error && typeof error.error.message === "string" && "type" in error.error && typeof error.error.type === "string" && "code" in error.error && typeof error.error.code === "number" && "fbtrace_id" in error.error && typeof error.error.fbtrace_id === "string" && (!("error_data" in error.error) || typeof error.error.error_data === "object" && error.error.error_data != null && "messaging_product" in error.error.error_data && error.error.error_data.messaging_product === "whatsapp" && "details" in error.error.error_data && typeof error.error.error_data.details === "string") && (!("error_subcode" in error.error) || typeof error.error.error_subcode === "number");
856
+ }
857
+
858
+ //#endregion
859
+ //#region src/utils/http/httpsClient.ts
860
+ const LIB_NAME$3 = "HttpsClient";
861
+ const LOG_LOCAL$1 = false;
862
+ const LOGGER$4 = new Logger(LIB_NAME$3, process.env.DEBUG === "true" || LOG_LOCAL$1);
863
+ var HttpsClient = class {
864
+ agent;
865
+ constructor() {
866
+ this.agent = new Agent({ keepAlive: true });
867
+ }
868
+ clearSockets() {
869
+ this.agent.destroy();
870
+ return true;
871
+ }
872
+ async sendRequest(hostname, path, method, headers, timeout, body) {
873
+ const url = `https://${hostname}/${path}`;
874
+ const controller = new AbortController();
875
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
876
+ try {
877
+ const response = await fetch(url, {
878
+ method,
879
+ headers,
880
+ body,
881
+ signal: controller.signal
882
+ });
883
+ LOGGER$4.log(`${method} : ${url} - ${JSON.stringify(response)}`);
884
+ clearTimeout(timeoutId);
885
+ return new HttpsClientResponse(response);
886
+ } catch (error) {
887
+ LOGGER$4.error(`${method} : ${url} - ${JSON.stringify(error)}`);
888
+ throw error;
889
+ }
890
+ }
891
+ };
892
+ var HttpsClientResponse = class {
893
+ res;
894
+ respStatusCode;
895
+ respHeaders;
896
+ constructor(resp) {
897
+ this.res = resp;
898
+ this.respStatusCode = resp.status;
899
+ this.respHeaders = Object.fromEntries(resp.headers.entries());
900
+ }
901
+ statusCode() {
902
+ return this.respStatusCode;
903
+ }
904
+ headers() {
905
+ return this.respHeaders;
906
+ }
907
+ rawResponse() {
908
+ return this.res;
909
+ }
910
+ async json() {
911
+ try {
912
+ return await this.res.json();
913
+ } catch (err) {
914
+ throw new Error("Failed to parse response body to JSON: " + err.message);
915
+ }
916
+ }
917
+ };
918
+
919
+ //#endregion
920
+ //#region src/utils/http/request.ts
921
+ const LIB_NAME$2 = "REQUESTER";
922
+ const LOG_LOCAL = false;
923
+ const LOGGER$3 = new Logger(LIB_NAME$2, process.env.DEBUG === "true" || LOG_LOCAL);
924
+ var Requester = class {
925
+ client;
926
+ accessToken;
927
+ phoneNumberId;
928
+ businessAcctId;
929
+ apiVersion;
930
+ userAgent;
931
+ host;
932
+ protocol = "https:";
933
+ constructor(apiVersion, phoneNumberId, accessToken, businessAcctId, userAgent) {
934
+ this.client = new HttpsClient();
935
+ this.host = "graph.facebook.com";
936
+ this.apiVersion = apiVersion || "22";
937
+ this.phoneNumberId = phoneNumberId;
938
+ this.accessToken = accessToken;
939
+ this.businessAcctId = businessAcctId;
940
+ this.userAgent = userAgent;
941
+ }
942
+ buildHeader(contentType, additionalHeaders) {
943
+ const headers = {
944
+ Authorization: `Bearer ${this.accessToken}`,
945
+ "User-Agent": this.userAgent
946
+ };
947
+ if (contentType !== "multipart/form-data") {
948
+ headers["Content-Type"] = contentType;
949
+ }
950
+ if (additionalHeaders) {
951
+ Object.assign(headers, additionalHeaders);
952
+ }
953
+ return headers;
954
+ }
955
+ buildCAPIPath(endpoint) {
956
+ return `v${this.apiVersion}.0/${endpoint}`;
957
+ }
958
+ async sendRequest(method, endpoint, timeout, body, contentType = "application/json", additionalHeaders) {
959
+ let effectiveContentType = contentType;
960
+ if (body instanceof FormData) {
961
+ effectiveContentType = "multipart/form-data";
962
+ } else if (typeof body === "string" && body.startsWith("<?xml")) {
963
+ effectiveContentType = "application/xml";
964
+ }
965
+ const path = `${this.protocol.toLowerCase()}//${this.host}/${this.buildCAPIPath(endpoint)}`;
966
+ LOGGER$3.log(`${method} : ${path} (${effectiveContentType})`);
967
+ try {
968
+ const response = await this.client.sendRequest(this.host, this.buildCAPIPath(endpoint), method, this.buildHeader(effectiveContentType, additionalHeaders), timeout, method === "POST" || method === "PUT" ? body : undefined);
969
+ if (!response.rawResponse().ok) {
970
+ const errorData = await response.json();
971
+ if (isMetaError(errorData)) {
972
+ throw errorData;
973
+ }
974
+ throw {
975
+ name: "MetaError",
976
+ message: "Unknown error occurred",
977
+ error: {
978
+ message: errorData.message || "Unknown error occurred",
979
+ type: "UnknownError",
980
+ code: response.statusCode(),
981
+ fbtrace_id: ""
982
+ }
983
+ };
984
+ }
985
+ return response;
986
+ } catch (error) {
987
+ if (isMetaError(error)) {
988
+ throw error;
989
+ }
990
+ throw {
991
+ name: "MetaError",
992
+ message: error instanceof Error ? error.message : "Network error occurred",
993
+ error: {
994
+ message: error instanceof Error ? error.message : "Network error occurred",
995
+ type: "NetworkError",
996
+ code: 500,
997
+ fbtrace_id: ""
998
+ }
999
+ };
1000
+ }
1001
+ }
1002
+ async getJson(method, endpoint, timeout, body, additionalHeaders) {
1003
+ const res = await this.sendRequest(method, endpoint, timeout, body, "application/json", additionalHeaders);
1004
+ return await res.json();
1005
+ }
1006
+ async sendFormData(method, endpoint, timeout, formData, additionalHeaders) {
1007
+ const res = await this.sendRequest(method, endpoint, timeout, formData, "multipart/form-data", additionalHeaders);
1008
+ return await res.json();
1009
+ }
1010
+ async sendUrlEncodedForm(method, endpoint, timeout, formData, additionalHeaders) {
1011
+ const urlEncodedBody = new URLSearchParams(formData).toString();
1012
+ const res = await this.sendRequest(method, endpoint, timeout, urlEncodedBody, "application/x-www-form-urlencoded", additionalHeaders);
1013
+ return await res.json();
1014
+ }
1015
+ };
1016
+
1017
+ //#endregion
1018
+ //#region src/utils/version.ts
1019
+ /**
1020
+ * Get SDK version from package.json
1021
+ */
1022
+ function getVersion() {
1023
+ try {
1024
+ const packagePath = join(__dirname, "../../package.json");
1025
+ const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
1026
+ return packageJson.version;
1027
+ } catch (error) {
1028
+ return "unknown";
1029
+ }
1030
+ }
1031
+ /**
1032
+ * Generate User-Agent string following official SDK pattern
1033
+ */
1034
+ function getUserAgent() {
1035
+ const version = getVersion();
1036
+ const nodeVersion = process.version;
1037
+ return `WhatsApp-Nodejs-SDK/${version} (Node.js ${nodeVersion})`;
1038
+ }
1039
+
1040
+ //#endregion
1041
+ //#region src/types/base.ts
1042
+ var BaseAPI = class {
1043
+ config;
1044
+ client;
1045
+ constructor(config, client) {
1046
+ this.config = config;
1047
+ this.client = client;
1048
+ }
1049
+ sendJson(method, endpoint, timeout, body) {
1050
+ return this.client.getJson(method, endpoint, timeout, body);
1051
+ }
1052
+ sendFormData(method, endpoint, timeout, body) {
1053
+ return this.client.sendFormData(method, endpoint, timeout, body);
1054
+ }
1055
+ sendUrlEncodedForm(method, endpoint, timeout, body) {
1056
+ return this.client.sendUrlEncodedForm(method, endpoint, timeout, body);
1057
+ }
1058
+ };
1059
+
1060
+ //#endregion
1061
+ //#region src/api/encryption/EncryptionApi.ts
1062
+ var EncryptionApi = class extends BaseAPI {
1063
+ endpoint = "whatsapp_business_encryption";
1064
+ constructor(config, client) {
1065
+ super(config, client);
1066
+ }
1067
+ async getEncryptionPublicKey() {
1068
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], null);
1069
+ }
1070
+ async setEncryptionPublicKey(businessPublicKey) {
1071
+ const formData = new FormData();
1072
+ formData.append("business_public_key", businessPublicKey);
1073
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], formData);
1074
+ }
1075
+ };
1076
+
1077
+ //#endregion
1078
+ //#region src/api/encryption/index.ts
1079
+ var encryption_default = EncryptionApi;
1080
+
1081
+ //#endregion
1082
+ //#region src/api/flow/FlowApi.ts
1083
+ /**
1084
+ * API for managing WhatsApp Flows.
1085
+ *
1086
+ * This API allows you to:
1087
+ * - List flows
1088
+ * - Create flows
1089
+ * - Get flow details and previews
1090
+ * - Update flow metadata and JSON
1091
+ * - Delete flows
1092
+ * - Publish and deprecate flows
1093
+ * - Migrate flows between WABAs
1094
+ * - Validate flow JSON
1095
+ */
1096
+ var FlowApi = class extends BaseAPI {
1097
+ constructor(config, client) {
1098
+ super(config, client);
1099
+ }
1100
+ /**
1101
+ * List Flows
1102
+ *
1103
+ * @param wabaId - The WABA ID
1104
+ * @returns Promise with the list of flows
1105
+ */
1106
+ async listFlows(wabaId) {
1107
+ return this.sendJson(HttpMethodsEnum.Get, `/${wabaId}/flows`, this.config[WabaConfigEnum.RequestTimeout], null);
1108
+ }
1109
+ /**
1110
+ * Create Flow
1111
+ *
1112
+ * @param wabaId - The WABA ID
1113
+ * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
1114
+ * @returns Promise with the created flow ID and validation errors if any
1115
+ */
1116
+ async createFlow(wabaId, data) {
1117
+ const payload = {
1118
+ name: data.name,
1119
+ categories: data.categories,
1120
+ ...data.endpoint_uri && { endpoint_uri: data.endpoint_uri },
1121
+ ...data.clone_flow_id && { clone_flow_id: data.clone_flow_id },
1122
+ ...data.flow_json && { flow_json: data.flow_json },
1123
+ ...data.publish !== undefined && { publish: data.publish }
1124
+ };
1125
+ return this.sendJson(HttpMethodsEnum.Post, `/${wabaId}/flows`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(payload));
1126
+ }
1127
+ /**
1128
+ * Get Flow details
1129
+ *
1130
+ * @param flowId - The flow ID
1131
+ * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')
1132
+ * @param dateFormat - Optional date format
1133
+ * @returns Promise with the flow details or preview response
1134
+ */
1135
+ async getFlow(flowId, fields, dateFormat) {
1136
+ const params = new URLSearchParams();
1137
+ if (fields) params.append("fields", fields);
1138
+ if (dateFormat) params.append("date_format", dateFormat);
1139
+ const queryString = params.toString() ? `?${params.toString()}` : "";
1140
+ return this.sendJson(HttpMethodsEnum.Get, `/${flowId}${queryString}`, this.config[WabaConfigEnum.RequestTimeout], null);
1141
+ }
1142
+ /**
1143
+ * Get Flow Preview URL
1144
+ *
1145
+ * @param flowId - The flow ID
1146
+ * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.
1147
+ * @returns Promise with the flow preview details
1148
+ */
1149
+ async getFlowPreview(flowId, invalidate = false) {
1150
+ const fields = `preview.invalidate(${invalidate})`;
1151
+ return this.getFlow(flowId, fields);
1152
+ }
1153
+ /**
1154
+ * Update Flow Metadata
1155
+ *
1156
+ * @param flowId - The flow ID
1157
+ * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)
1158
+ * @returns Promise with the success status
1159
+ */
1160
+ async updateFlowMetadata(flowId, data) {
1161
+ const payload = {
1162
+ ...data.name && { name: data.name },
1163
+ ...data.categories && { categories: data.categories },
1164
+ ...data.endpoint_uri && { endpoint_uri: data.endpoint_uri },
1165
+ ...data.application_id && { application_id: data.application_id }
1166
+ };
1167
+ return this.sendJson(HttpMethodsEnum.Post, `/${flowId}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(payload));
1168
+ }
1169
+ /**
1170
+ * Delete Flow (only works if the Flow is in DRAFT status)
1171
+ *
1172
+ * @param flowId - The flow ID
1173
+ * @returns Promise with the success status
1174
+ */
1175
+ async deleteFlow(flowId) {
1176
+ return this.sendJson(HttpMethodsEnum.Delete, `/${flowId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1177
+ }
1178
+ /**
1179
+ * List Assets (e.g., get Flow JSON download URL)
1180
+ *
1181
+ * @param flowId - The flow ID
1182
+ * @returns Promise with the list of assets
1183
+ */
1184
+ async listAssets(flowId) {
1185
+ return this.sendJson(HttpMethodsEnum.Get, `/${flowId}/assets`, this.config[WabaConfigEnum.RequestTimeout], null);
1186
+ }
1187
+ /**
1188
+ * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.
1189
+ *
1190
+ * @param flowId - The flow ID
1191
+ * @param data - Object containing the file data and optional name.
1192
+ * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.
1193
+ * @param data.name - Optional name for the asset, defaults to 'flow.json'.
1194
+ * @returns Promise with the success status and validation errors, if any.
1195
+ */
1196
+ async updateFlowJson(flowId, data) {
1197
+ const formData = new FormData();
1198
+ let fileContent;
1199
+ if (data.file instanceof Buffer) {
1200
+ fileContent = new globalThis.Blob([data.file]);
1201
+ formData.append("file", fileContent);
1202
+ } else if (typeof data.file === "object" && !(data.file instanceof Blob)) {
1203
+ try {
1204
+ fileContent = new globalThis.Blob([JSON.stringify(data.file, null, 2)], { type: "application/json" });
1205
+ formData.append("file", fileContent);
1206
+ } catch (e) {
1207
+ throw new Error("Failed to stringify JSON object for Flow JSON update.");
1208
+ }
1209
+ } else if (data.file instanceof Blob) {
1210
+ fileContent = data.file;
1211
+ formData.append("file", fileContent);
1212
+ } else {
1213
+ throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");
1214
+ }
1215
+ formData.append("asset_type", "FLOW_JSON");
1216
+ formData.append("name", data.name || "flow.json");
1217
+ return this.sendFormData(HttpMethodsEnum.Post, `/${flowId}/assets`, this.config[WabaConfigEnum.RequestTimeout], formData);
1218
+ }
1219
+ /**
1220
+ * Validate Flow JSON by attempting an update without publishing.
1221
+ * This is a convenience method; the API doesn't have a dedicated validation endpoint.
1222
+ *
1223
+ * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
1224
+ * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.
1225
+ * @returns Promise indicating if the JSON is valid and includes validation errors if any.
1226
+ */
1227
+ async validateFlowJson(flowId, flowJsonData) {
1228
+ try {
1229
+ const result = await this.updateFlowJson(flowId, { file: flowJsonData });
1230
+ const isValid = !result.validation_errors || result.validation_errors.length === 0;
1231
+ const enhancedResponse = {
1232
+ ...result,
1233
+ valid: isValid
1234
+ };
1235
+ return enhancedResponse;
1236
+ } catch (error) {
1237
+ throw error;
1238
+ }
1239
+ }
1240
+ /**
1241
+ * Publish Flow
1242
+ *
1243
+ * @param flowId - The flow ID
1244
+ * @returns Promise with the success status
1245
+ */
1246
+ async publishFlow(flowId) {
1247
+ return this.sendJson(HttpMethodsEnum.Post, `/${flowId}/publish`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify({}));
1248
+ }
1249
+ /**
1250
+ * Deprecate Flow
1251
+ *
1252
+ * @param flowId - The flow ID
1253
+ * @returns Promise with the success status
1254
+ */
1255
+ async deprecateFlow(flowId) {
1256
+ return this.sendJson(HttpMethodsEnum.Post, `/${flowId}/deprecate`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify({}));
1257
+ }
1258
+ /**
1259
+ * Migrate Flows between WABAs
1260
+ *
1261
+ * @param destinationWabaId - The destination WABA ID
1262
+ * @param data - The migration data including source_waba_id and optional source_flow_names
1263
+ * @returns Promise with migration results (successes and failures)
1264
+ */
1265
+ async migrateFlows(destinationWabaId, data) {
1266
+ const payload = {
1267
+ source_waba_id: data.source_waba_id,
1268
+ ...data.source_flow_names && { source_flow_names: data.source_flow_names }
1269
+ };
1270
+ return this.sendJson(HttpMethodsEnum.Post, `/${destinationWabaId}/migrate_flows`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(payload));
1271
+ }
1272
+ };
1273
+
1274
+ //#endregion
1275
+ //#region src/api/flow/types/common.ts
1276
+ /**
1277
+ * Enum for Flow Status
1278
+ */
1279
+ let FlowStatusEnum = /* @__PURE__ */ function(FlowStatusEnum$1) {
1280
+ FlowStatusEnum$1["Draft"] = "DRAFT";
1281
+ FlowStatusEnum$1["Published"] = "PUBLISHED";
1282
+ FlowStatusEnum$1["Throttled"] = "THROTTLED";
1283
+ FlowStatusEnum$1["Blocked"] = "BLOCKED";
1284
+ FlowStatusEnum$1["Deprecated"] = "DEPRECATED";
1285
+ return FlowStatusEnum$1;
1286
+ }({});
1287
+ /**
1288
+ * Enum for Flow Categories
1289
+ */
1290
+ let FlowCategoryEnum = /* @__PURE__ */ function(FlowCategoryEnum$1) {
1291
+ FlowCategoryEnum$1["SignUp"] = "SIGN_UP";
1292
+ FlowCategoryEnum$1["SignIn"] = "SIGN_IN";
1293
+ FlowCategoryEnum$1["AppointmentBooking"] = "APPOINTMENT_BOOKING";
1294
+ FlowCategoryEnum$1["LeadGeneration"] = "LEAD_GENERATION";
1295
+ FlowCategoryEnum$1["ContactUs"] = "CONTACT_US";
1296
+ FlowCategoryEnum$1["CustomerSupport"] = "CUSTOMER_SUPPORT";
1297
+ FlowCategoryEnum$1["Survey"] = "SURVEY";
1298
+ FlowCategoryEnum$1["Other"] = "OTHER";
1299
+ return FlowCategoryEnum$1;
1300
+ }({});
1301
+ let FlowActionEnum = /* @__PURE__ */ function(FlowActionEnum$1) {
1302
+ FlowActionEnum$1["INIT"] = "INIT";
1303
+ FlowActionEnum$1["BACK"] = "BACK";
1304
+ FlowActionEnum$1["DATA_EXCHANGE"] = "data_exchange";
1305
+ return FlowActionEnum$1;
1306
+ }({});
1307
+ /**
1308
+ * Enum for Flow Types in webhook handlers
1309
+ * Used to register handlers for specific flow events
1310
+ */
1311
+ let FlowTypeEnum = /* @__PURE__ */ function(FlowTypeEnum$1) {
1312
+ /** Health check/ping requests */
1313
+ FlowTypeEnum$1["Ping"] = "ping";
1314
+ /** Data exchange requests */
1315
+ FlowTypeEnum$1["Change"] = "data_exchange";
1316
+ /** Error notification requests */
1317
+ FlowTypeEnum$1["Error"] = "error";
1318
+ /** Match all flow action types */
1319
+ FlowTypeEnum$1["All"] = "*";
1320
+ return FlowTypeEnum$1;
1321
+ }({});
1322
+
1323
+ //#endregion
1324
+ //#region src/api/flow/index.ts
1325
+ var flow_default = FlowApi;
1326
+
1327
+ //#endregion
1328
+ //#region src/api/media/MediaApi.ts
1329
+ /**
1330
+ * API for managing WhatsApp Media.
1331
+ *
1332
+ * This API allows you to:
1333
+ * - Get media information by ID
1334
+ * - Upload media files
1335
+ * - Delete media files
1336
+ * - Download media files from URLs
1337
+ */
1338
+ var MediaApi = class extends BaseAPI {
1339
+ endpoint = "media";
1340
+ constructor(config, client) {
1341
+ super(config, client);
1342
+ }
1343
+ /**
1344
+ * Retrieve media information by media ID.
1345
+ *
1346
+ * @param mediaId The media ID to retrieve information for
1347
+ * @param phone_number_id Optional phone number ID (defaults to configured one)
1348
+ * @returns Media information including URL, mime type, file size, etc.
1349
+ *
1350
+ * @example
1351
+ * const mediaInfo = await whatsappClient.media.getMediaById('media_id_123');
1352
+ */
1353
+ async getMediaById(mediaId, phone_number_id) {
1354
+ return this.sendJson(HttpMethodsEnum.Get, `${mediaId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1355
+ }
1356
+ /**
1357
+ * Upload a media file to WhatsApp.
1358
+ *
1359
+ * @param file The file to upload
1360
+ * @param messagingProduct The messaging product (default: 'whatsapp')
1361
+ * @returns Upload response containing the media ID
1362
+ *
1363
+ * @example
1364
+ * const file = new File([buffer], 'image.jpg', { type: 'image/jpeg' });
1365
+ * const result = await whatsappClient.media.uploadMedia(file);
1366
+ */
1367
+ async uploadMedia(file, messagingProduct = "whatsapp") {
1368
+ const formData = new FormData();
1369
+ formData.append("file", file);
1370
+ formData.append("messaging_product", messagingProduct);
1371
+ formData.append("type", file.type);
1372
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], formData);
1373
+ }
1374
+ /**
1375
+ * Delete a media file.
1376
+ *
1377
+ * @param mediaId The media ID to delete
1378
+ * @param phone_number_id Optional phone number ID (defaults to configured one)
1379
+ * @returns Response indicating success or failure
1380
+ *
1381
+ * @example
1382
+ * await whatsappClient.media.deleteMedia('media_id_123');
1383
+ */
1384
+ async deleteMedia(mediaId, phone_number_id) {
1385
+ return this.sendJson(HttpMethodsEnum.Delete, `${mediaId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1386
+ }
1387
+ /**
1388
+ * Download media from a URL.
1389
+ *
1390
+ * @param mediaUrl The URL to download media from
1391
+ * @returns Blob containing the media data
1392
+ *
1393
+ * @example
1394
+ * const blob = await whatsappClient.media.downloadMedia('https://...');
1395
+ */
1396
+ async downloadMedia(mediaUrl) {
1397
+ return this.sendJson(HttpMethodsEnum.Get, mediaUrl, this.config[WabaConfigEnum.RequestTimeout], null);
1398
+ }
1399
+ };
1400
+
1401
+ //#endregion
1402
+ //#region src/api/media/index.ts
1403
+ var media_default = MediaApi;
1404
+
1405
+ //#endregion
1406
+ //#region src/api/messages/MessageApi.ts
1407
+ var MessagesApi = class extends BaseAPI {
1408
+ commonMethod = HttpMethodsEnum.Post;
1409
+ commonEndpoint = "messages";
1410
+ constructor(config, client) {
1411
+ super(config, client);
1412
+ }
1413
+ /**
1414
+ * Builds the request body for WhatsApp API messages
1415
+ * @param type The type of message to send
1416
+ * @param payload The message payload object
1417
+ * @param to The recipient's phone number
1418
+ * @param replyMessageId Optional message ID to reply to
1419
+ * @returns The formatted request body
1420
+ */
1421
+ bodyBuilder(type, payload, to, replyMessageId) {
1422
+ const body = {
1423
+ messaging_product: "whatsapp",
1424
+ recipient_type: "individual",
1425
+ to,
1426
+ type,
1427
+ [type]: payload
1428
+ };
1429
+ if (replyMessageId) body["context"] = { message_id: replyMessageId };
1430
+ return body;
1431
+ }
1432
+ /**
1433
+ * Sends a request to the WhatsApp API
1434
+ * @param body The request body to send
1435
+ * @returns Promise with the API response
1436
+ */
1437
+ send(body) {
1438
+ return this.sendJson(this.commonMethod, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`, this.config[WabaConfigEnum.RequestTimeout], body);
1439
+ }
1440
+ /**
1441
+ * Sends an audio message via WhatsApp
1442
+ * @param params The audio message parameter object
1443
+ * @returns Promise with the message response
1444
+ */
1445
+ async audio(params) {
1446
+ const { body, to, replyMessageId } = params;
1447
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, to, replyMessageId)));
1448
+ }
1449
+ /**
1450
+ * Sends a contact card via WhatsApp
1451
+ * @param params The contact message parameter object
1452
+ * @returns Promise with the message response
1453
+ */
1454
+ async contacts(params) {
1455
+ const { body, to, replyMessageId } = params;
1456
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, to, replyMessageId)));
1457
+ }
1458
+ /**
1459
+ * Sends a document via WhatsApp
1460
+ * @param params The document message parameter object
1461
+ * @returns Promise with the message response
1462
+ */
1463
+ async document(params) {
1464
+ const { body, to, replyMessageId } = params;
1465
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, to, replyMessageId)));
1466
+ }
1467
+ /**
1468
+ * Sends an image via WhatsApp
1469
+ * @param params The image message parameter object
1470
+ * @returns Promise with the message response
1471
+ */
1472
+ async image(params) {
1473
+ const { body, to, replyMessageId } = params;
1474
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, to, replyMessageId)));
1475
+ }
1476
+ /**
1477
+ * Sends an interactive message via WhatsApp
1478
+ * @param params The interactive message parameter object
1479
+ * @returns Promise with the message response
1480
+ */
1481
+ async interactive(params) {
1482
+ const { body, to, replyMessageId } = params;
1483
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));
1484
+ }
1485
+ /**
1486
+ * Sends a location via WhatsApp
1487
+ * @param params The location message parameter object
1488
+ * @returns Promise with the message response
1489
+ */
1490
+ async location(params) {
1491
+ const { body, to, replyMessageId } = params;
1492
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, to, replyMessageId)));
1493
+ }
1494
+ /**
1495
+ * Sends a sticker via WhatsApp
1496
+ * @param params The sticker message parameter object
1497
+ * @returns Promise with the message response
1498
+ */
1499
+ async sticker(params) {
1500
+ const { body, to, replyMessageId } = params;
1501
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, to, replyMessageId)));
1502
+ }
1503
+ /**
1504
+ * Sends a template message via WhatsApp
1505
+ * @param params The template message parameter object
1506
+ * @returns Promise with the message response
1507
+ */
1508
+ async template(params) {
1509
+ const { body, to, replyMessageId } = params;
1510
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, to, replyMessageId)));
1511
+ }
1512
+ /**
1513
+ * Sends a text message via WhatsApp
1514
+ * @param params The text message parameter object
1515
+ * @returns Promise with the message response
1516
+ */
1517
+ async text(params) {
1518
+ const { body, to, replyMessageId, previewUrl } = params;
1519
+ const textPayload = typeof body === "string" ? {
1520
+ body,
1521
+ preview_url: previewUrl ?? true
1522
+ } : {
1523
+ ...body,
1524
+ preview_url: previewUrl ?? body.preview_url ?? true
1525
+ };
1526
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, textPayload, to, replyMessageId)));
1527
+ }
1528
+ /**
1529
+ * Sends a video message via WhatsApp
1530
+ * @param params The video message parameter object
1531
+ * @returns Promise with the message response
1532
+ */
1533
+ async video(params) {
1534
+ const { body, to, replyMessageId } = params;
1535
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, to, replyMessageId)));
1536
+ }
1537
+ /**
1538
+ * Updates message status (mark as read, etc.)
1539
+ * @param params The status update parameters
1540
+ * @returns Promise with the API response
1541
+ */
1542
+ async status(params) {
1543
+ const body = {
1544
+ messaging_product: "whatsapp",
1545
+ status: params.status,
1546
+ message_id: params.messageId,
1547
+ ...params.typingIndicator && { typing_indicator: params.typingIndicator }
1548
+ };
1549
+ return this.send(JSON.stringify(body));
1550
+ }
1551
+ /**
1552
+ * Marks a message as read
1553
+ * @param params Object containing messageId
1554
+ * @returns Promise with the API response
1555
+ */
1556
+ async markAsRead(params) {
1557
+ return this.status({
1558
+ status: "read",
1559
+ messageId: params.messageId
1560
+ });
1561
+ }
1562
+ /**
1563
+ * Shows typing indicator
1564
+ * @param params Object containing messageId
1565
+ * @returns Promise with the API response
1566
+ */
1567
+ async showTypingIndicator(params) {
1568
+ return this.status({
1569
+ status: "read",
1570
+ messageId: params.messageId,
1571
+ typingIndicator: { type: "text" }
1572
+ });
1573
+ }
1574
+ /**
1575
+ * Sends a list interactive message
1576
+ * @param params The list interactive message parameters
1577
+ * @returns Promise with the message response
1578
+ */
1579
+ async interactiveList(params) {
1580
+ return this.interactive(params);
1581
+ }
1582
+ /**
1583
+ * Sends a CTA URL interactive message
1584
+ * @param params The CTA URL interactive message parameters
1585
+ * @returns Promise with the message response
1586
+ */
1587
+ async interactiveCtaUrl(params) {
1588
+ return this.interactive(params);
1589
+ }
1590
+ /**
1591
+ * Sends a location request interactive message
1592
+ * @param params The location request interactive message parameters
1593
+ * @returns Promise with the message response
1594
+ */
1595
+ async interactiveLocationRequest(params) {
1596
+ return this.interactive(params);
1597
+ }
1598
+ /**
1599
+ * Sends an address message interactive message
1600
+ * @param params The address message interactive message parameters
1601
+ * @returns Promise with the message response
1602
+ */
1603
+ async interactiveAddressMessage(params) {
1604
+ return this.interactive(params);
1605
+ }
1606
+ /**
1607
+ * Sends a reply buttons interactive message
1608
+ * @param params The reply buttons interactive message parameters
1609
+ * @returns Promise with the message response
1610
+ */
1611
+ async interactiveReplyButtons(params) {
1612
+ return this.interactive(params);
1613
+ }
1614
+ /**
1615
+ * Sends a flow interactive message
1616
+ * @param params The flow interactive message parameters
1617
+ * @returns Promise with the message response
1618
+ */
1619
+ async interactiveFlow(params) {
1620
+ return this.interactive(params);
1621
+ }
1622
+ /**
1623
+ * Sends a reaction to a message
1624
+ * @param params The reaction parameters
1625
+ * @returns Promise with the message response
1626
+ */
1627
+ async reaction(params) {
1628
+ const reactionPayload = {
1629
+ message_id: params.messageId,
1630
+ emoji: params.emoji
1631
+ };
1632
+ return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Reaction, reactionPayload, params.to)));
1633
+ }
1634
+ };
1635
+
1636
+ //#endregion
1637
+ //#region src/api/messages/index.ts
1638
+ var messages_default = MessagesApi;
1639
+
1640
+ //#endregion
1641
+ //#region src/utils/objectToQueryString.ts
1642
+ const objectToQueryString = (params) => {
1643
+ if (!params || Object.keys(params).length === 0) {
1644
+ return "";
1645
+ }
1646
+ const queryParts = [];
1647
+ for (const [key, value] of Object.entries(params)) {
1648
+ if (value !== undefined) {
1649
+ const encodedKey = encodeURIComponent(key);
1650
+ const encodedValue = encodeURIComponent(String(value));
1651
+ queryParts.push(`${encodedKey}=${encodedValue}`);
1652
+ }
1653
+ }
1654
+ return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
1655
+ };
1656
+
1657
+ //#endregion
1658
+ //#region src/api/phone/PhoneNumberApi.ts
1659
+ /**
1660
+ * API for managing WhatsApp Phone Numb ers.
1661
+ *
1662
+ * This API allows you to:
1663
+ * - Get phone number information by ID
1664
+ * - Get all phone numbers for a business account
1665
+ * - Request verification codes for phone numbers
1666
+ * - Verify phone numbers with codes
1667
+ */
1668
+ var PhoneNumberApi = class extends BaseAPI {
1669
+ endpoint = "phone_numbers";
1670
+ constructor(config, client) {
1671
+ super(config, client);
1672
+ }
1673
+ /**
1674
+ * Get phone number information by ID.
1675
+ *
1676
+ * @param fields Optional comma-separated list of fields to include in the response
1677
+ * @returns Phone number information including verification status, quality rating, etc.
1678
+ *
1679
+ * @example
1680
+ * const phoneNumber = await whatsappClient.phoneNumber.getPhoneNumberById();
1681
+ * const phoneNumberWithFields = await whatsappClient.phoneNumber.getPhoneNumberById('display_phone_number,verified_name');
1682
+ */
1683
+ async getPhoneNumberById(fields) {
1684
+ const queryParams = fields ? objectToQueryString({ fields }) : "";
1685
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.PhoneNumberId]}${queryParams}`, this.config[WabaConfigEnum.RequestTimeout], null);
1686
+ }
1687
+ /**
1688
+ * Get all phone numbers for the business account.
1689
+ *
1690
+ * @returns List of phone numbers associated with the business account
1691
+ *
1692
+ * @example
1693
+ * const phoneNumbers = await whatsappClient.phoneNumber.getPhoneNumbers();
1694
+ */
1695
+ async getPhoneNumbers() {
1696
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.BusinessAcctId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], null);
1697
+ }
1698
+ /**
1699
+ * Request a verification code for the phone number.
1700
+ *
1701
+ * @param request Verification code request containing method and language
1702
+ * @returns Response indicating success or failure
1703
+ *
1704
+ * @example
1705
+ * await whatsappClient.phoneNumber.requestVerificationCode({
1706
+ * code_method: 'SMS',
1707
+ * language: 'en_US'
1708
+ * });
1709
+ */
1710
+ async requestVerificationCode(request) {
1711
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/request_code`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(request));
1712
+ }
1713
+ /**
1714
+ * Verify the phone number with the received code.
1715
+ *
1716
+ * @param request Verification request containing the code
1717
+ * @returns Response indicating success or failure
1718
+ *
1719
+ * @example
1720
+ * await whatsappClient.phoneNumber.verifyCode({
1721
+ * code: '123456'
1722
+ * });
1723
+ */
1724
+ async verifyCode(request) {
1725
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/verify_code`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(request));
1726
+ }
1727
+ };
1728
+
1729
+ //#endregion
1730
+ //#region src/api/phone/index.ts
1731
+ var phone_default = PhoneNumberApi;
1732
+
1733
+ //#endregion
1734
+ //#region src/utils/buildFieldsQueryString.ts
1735
+ function buildFieldsQueryString(fields) {
1736
+ if (!fields) return "";
1737
+ let fieldParams = "";
1738
+ if (Array.isArray(fields)) {
1739
+ fieldParams = fields.join(",");
1740
+ } else if (typeof fields === "string") {
1741
+ fieldParams = fields;
1742
+ } else {
1743
+ fieldParams = Object.entries(fields).filter(([_, value]) => value).map(([key]) => key).join(",");
1744
+ }
1745
+ return fieldParams ? `?fields=${fieldParams}` : "";
1746
+ }
1747
+
1748
+ //#endregion
1749
+ //#region src/api/profile/BusinessProfileApi.ts
1750
+ /**
1751
+ * API for managing WhatsApp Business Profiles and profile pictures.
1752
+ *
1753
+ * This API allows you to:
1754
+ * - Get business profile information
1755
+ * - Update business profile details
1756
+ * - Upload profile pictures using a three-step process:
1757
+ * 1. Create an upload session
1758
+ * 2. Upload the image binary data
1759
+ * 3. Get the upload handle to use when updating the profile
1760
+ */
1761
+ var BusinessProfileApi = class extends BaseAPI {
1762
+ endpoint = "whatsapp_business_profile";
1763
+ constructor(config, client) {
1764
+ super(config, client);
1765
+ }
1766
+ /**
1767
+ * Get your business profile information.
1768
+ *
1769
+ * Use this method to retrieve details about your WhatsApp business profile, including
1770
+ * about text, address, description, email, profile picture URL, websites, and vertical.
1771
+ *
1772
+ * @param fields Fields to be returned in the response. If not specified, all fields will be returned.
1773
+ * Possible values: about, address, description, email, profile_picture_url, websites, vertical
1774
+ * @returns The business profile information.
1775
+ *
1776
+ * @example
1777
+ * // Get all business profile fields
1778
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile();
1779
+ *
1780
+ * // Get specific business profile fields
1781
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');
1782
+ *
1783
+ * // Using the BusinessProfileFieldsParam type
1784
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile(['about', 'address', 'email']);
1785
+ */
1786
+ async getBusinessProfile(fields) {
1787
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}${buildFieldsQueryString(fields)}`, this.config[WabaConfigEnum.RequestTimeout], null);
1788
+ }
1789
+ /**
1790
+ * Update your business profile.
1791
+ *
1792
+ * Use this method to update one or more fields of your WhatsApp business profile.
1793
+ *
1794
+ * @param updateRequest The request object containing the fields to update.
1795
+ * - messaging_product: Required. Always set to "whatsapp".
1796
+ * - about: Optional. Business's About text (1-139 characters).
1797
+ * - address: Optional. Business address (max 256 characters).
1798
+ * - description: Optional. Business description (max 512 characters).
1799
+ * - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).
1800
+ * - email: Optional. Contact email (valid format, max 128 characters).
1801
+ * - websites: Optional. Up to 2 URLs (max 256 characters each).
1802
+ * - profile_picture_handle: Optional. Handle from upload process.
1803
+ * @returns Response indicating success or failure.
1804
+ *
1805
+ * @example
1806
+ * // Update business profile with multiple fields including vertical using enum
1807
+ * await whatsappClient.businessProfile.updateBusinessProfile({
1808
+ * messaging_product: 'whatsapp',
1809
+ * about: 'We provide excellent service',
1810
+ * email: 'contact@example.com',
1811
+ * websites: ['https://example.com'],
1812
+ * vertical: BusinessVerticalEnum.RETAIL
1813
+ * });
1814
+ */
1815
+ async updateBusinessProfile(updateRequest) {
1816
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(updateRequest));
1817
+ }
1818
+ /**
1819
+ * Create an upload session for a profile picture.
1820
+ *
1821
+ * This is the first step in the profile picture upload process.
1822
+ *
1823
+ * @param fileLength Length of the file to be uploaded in bytes.
1824
+ * @param fileType MIME type of the file (e.g., 'image/jpeg').
1825
+ * @param fileName Name of the file with extension.
1826
+ * @returns Response containing the upload session ID needed for the next step.
1827
+ *
1828
+ * @example
1829
+ * // Create upload session for profile picture
1830
+ * const session = await whatsappClient.businessProfile.createUploadSession(
1831
+ * fileBuffer.length,
1832
+ * 'image/jpeg',
1833
+ * 'profile.jpg'
1834
+ * );
1835
+ * const uploadSessionId = session.upload_session_id;
1836
+ */
1837
+ async createUploadSession(fileLength, fileType, fileName) {
1838
+ const queryParams = objectToQueryString({
1839
+ file_length: fileLength,
1840
+ file_type: fileType,
1841
+ file_name: fileName
1842
+ });
1843
+ return this.sendJson(HttpMethodsEnum.Post, `app/uploads/${queryParams}`, this.config[WabaConfigEnum.RequestTimeout], null);
1844
+ }
1845
+ /**
1846
+ * Upload media file to the upload session.
1847
+ *
1848
+ * This is the second step in the profile picture upload process.
1849
+ * Upload the binary content of the file to the previously created upload session.
1850
+ *
1851
+ * @param uploadId The upload session ID from createUploadSession response.
1852
+ * @param file The binary data of the file (Buffer).
1853
+ * @returns Response indicating success or failure.
1854
+ *
1855
+ * @example
1856
+ * // Upload the actual file content
1857
+ * await whatsappClient.businessProfile.uploadMedia(
1858
+ * uploadSessionId,
1859
+ * fileBuffer
1860
+ * );
1861
+ */
1862
+ async uploadMedia(uploadId, file) {
1863
+ return this.sendJson(HttpMethodsEnum.Post, `${uploadId}`, this.config[WabaConfigEnum.RequestTimeout], file);
1864
+ }
1865
+ /**
1866
+ * Get the upload handle information.
1867
+ *
1868
+ * This is the third step in the profile picture upload process.
1869
+ * After uploading the file, get the handle to use when updating the profile.
1870
+ *
1871
+ * @param uploadId The upload session ID from createUploadSession response.
1872
+ * @returns Response containing the upload handle information.
1873
+ *
1874
+ * @example
1875
+ * // Complete profile picture update process
1876
+ * // 1. Create upload session
1877
+ * const session = await whatsappClient.businessProfile.createUploadSession(
1878
+ * fileBuffer.length, 'image/jpeg', 'profile.jpg'
1879
+ * );
1880
+ *
1881
+ * // 2. Upload the image data
1882
+ * await whatsappClient.businessProfile.uploadMedia(
1883
+ * session.upload_session_id, fileBuffer
1884
+ * );
1885
+ *
1886
+ * // 3. Get the handle for the uploaded file
1887
+ * const handleInfo = await whatsappClient.businessProfile.getUploadHandle(
1888
+ * session.upload_session_id
1889
+ * );
1890
+ *
1891
+ * // 4. Update profile with new picture and business information
1892
+ * await whatsappClient.businessProfile.updateBusinessProfile({
1893
+ * messaging_product: 'whatsapp',
1894
+ * profile_picture_handle: handleInfo.handle,
1895
+ * vertical: BusinessVerticalEnum.RESTAURANT,
1896
+ * about: 'Delicious food served daily'
1897
+ * });
1898
+ */
1899
+ async getUploadHandle(uploadId) {
1900
+ return this.sendJson(HttpMethodsEnum.Get, `${uploadId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1901
+ }
1902
+ };
1903
+
1904
+ //#endregion
1905
+ //#region src/api/profile/index.ts
1906
+ var profile_default = BusinessProfileApi;
1907
+
1908
+ //#endregion
1909
+ //#region src/api/qrCode/QrCodeApi.ts
1910
+ /**
1911
+ * API for managing WhatsApp QR Codes.
1912
+ *
1913
+ * This API allows you to:
1914
+ * - Create QR codes with prefilled messages
1915
+ * - Get all QR codes
1916
+ * - Get specific QR code details
1917
+ * - Update QR code messages
1918
+ * - Delete QR codes
1919
+ */
1920
+ var QrCodeApi = class extends BaseAPI {
1921
+ endpoint = "message_qrdls";
1922
+ constructor(config, client) {
1923
+ super(config, client);
1924
+ }
1925
+ /**
1926
+ * Create a new QR code with a prefilled message.
1927
+ *
1928
+ * @param request The QR code creation request
1929
+ * @returns QR code information including code, deep link URL, and optional image URL
1930
+ *
1931
+ * @example
1932
+ * const qrCode = await whatsappClient.qrCode.createQrCode({
1933
+ * prefilled_message: 'Hello from WhatsApp!',
1934
+ * generate_qr_image: 'PNG'
1935
+ * });
1936
+ */
1937
+ async createQrCode(request) {
1938
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(request));
1939
+ }
1940
+ /**
1941
+ * Get all QR codes for the current phone number.
1942
+ *
1943
+ * @returns List of all QR codes
1944
+ *
1945
+ * @example
1946
+ * const qrCodes = await whatsappClient.qrCode.getQrCodes();
1947
+ */
1948
+ async getQrCodes() {
1949
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], null);
1950
+ }
1951
+ /**
1952
+ * Get a specific QR code by ID.
1953
+ *
1954
+ * @param qrCodeId The QR code ID to retrieve
1955
+ * @returns QR code information
1956
+ *
1957
+ * @example
1958
+ * const qrCode = await whatsappClient.qrCode.getQrCode('qr_code_123');
1959
+ */
1960
+ async getQrCode(qrCodeId) {
1961
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}/${qrCodeId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1962
+ }
1963
+ /**
1964
+ * Update an existing QR code's prefilled message.
1965
+ *
1966
+ * @param request The QR code update request containing code and new message
1967
+ * @returns Updated QR code information
1968
+ *
1969
+ * @example
1970
+ * const updatedQrCode = await whatsappClient.qrCode.updateQrCode({
1971
+ * code: 'existing_qr_code',
1972
+ * prefilled_message: 'Updated message!'
1973
+ * });
1974
+ */
1975
+ async updateQrCode(request) {
1976
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(request));
1977
+ }
1978
+ /**
1979
+ * Delete a QR code.
1980
+ *
1981
+ * @param qrCodeId The QR code ID to delete
1982
+ * @returns Response indicating success or failure
1983
+ *
1984
+ * @example
1985
+ * await whatsappClient.qrCode.deleteQrCode('qr_code_123');
1986
+ */
1987
+ async deleteQrCode(qrCodeId) {
1988
+ return this.sendJson(HttpMethodsEnum.Delete, `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}/${qrCodeId}`, this.config[WabaConfigEnum.RequestTimeout], null);
1989
+ }
1990
+ };
1991
+
1992
+ //#endregion
1993
+ //#region src/api/qrCode/index.ts
1994
+ var qrCode_default = QrCodeApi;
1995
+
1996
+ //#endregion
1997
+ //#region src/api/registration/RegistrationApi.ts
1998
+ /**
1999
+ * API for managing WhatsApp Business Account registration.
2000
+ *
2001
+ * This API allows you to:
2002
+ * - Register a WhatsApp Business Account with a PIN
2003
+ * - Deregister a WhatsApp Business Account
2004
+ */
2005
+ var RegistrationApi = class extends BaseAPI {
2006
+ constructor(config, client) {
2007
+ super(config, client);
2008
+ }
2009
+ /**
2010
+ * Register a WhatsApp Business Account using a PIN.
2011
+ *
2012
+ * @param pin The registration PIN received via SMS or voice call
2013
+ * @param dataLocalizationRegion Optional data localization region
2014
+ * @returns Response indicating success or failure
2015
+ *
2016
+ * @example
2017
+ * await whatsappClient.registration.register('123456', DataLocalizationRegionEnum.Asia);
2018
+ */
2019
+ async register(pin, dataLocalizationRegion) {
2020
+ const body = {
2021
+ messaging_product: "whatsapp",
2022
+ pin,
2023
+ ...dataLocalizationRegion && { data_localization_region: dataLocalizationRegion }
2024
+ };
2025
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/register`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(body));
2026
+ }
2027
+ /**
2028
+ * Deregister a WhatsApp Business Account.
2029
+ *
2030
+ * @returns Response indicating success or failure
2031
+ *
2032
+ * @example
2033
+ * await whatsappClient.registration.deregister();
2034
+ */
2035
+ async deregister() {
2036
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}/deregister`, this.config[WabaConfigEnum.RequestTimeout], null);
2037
+ }
2038
+ };
2039
+
2040
+ //#endregion
2041
+ //#region src/api/registration/index.ts
2042
+ var registration_default = RegistrationApi;
2043
+
2044
+ //#endregion
2045
+ //#region src/api/template/TemplateApi.ts
2046
+ var TemplateApi = class extends BaseAPI {
2047
+ endpoint = "message_templates";
2048
+ constructor(config, client) {
2049
+ super(config, client);
2050
+ }
2051
+ async getTemplate(templateId) {
2052
+ return this.sendJson(HttpMethodsEnum.Get, `${templateId}`, this.config[WabaConfigEnum.RequestTimeout], null);
2053
+ }
2054
+ async updateTemplate(templateId, template) {
2055
+ return this.sendJson(HttpMethodsEnum.Post, `${templateId}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(template));
2056
+ }
2057
+ async getTemplates(params) {
2058
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.BusinessAcctId]}/${this.endpoint}${objectToQueryString(params ?? {})}`, this.config[WabaConfigEnum.RequestTimeout], null);
2059
+ }
2060
+ async createTemplate(template) {
2061
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.BusinessAcctId]}/${this.endpoint}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(template));
2062
+ }
2063
+ async deleteTemplate(params) {
2064
+ return this.sendJson(HttpMethodsEnum.Delete, `${this.config[WabaConfigEnum.BusinessAcctId]}/${this.endpoint}${objectToQueryString(params)}`, this.config[WabaConfigEnum.RequestTimeout], null);
2065
+ }
2066
+ };
2067
+
2068
+ //#endregion
2069
+ //#region src/api/template/factories/index.ts
2070
+ function createHeader(options) {
2071
+ const header = {
2072
+ type: "HEADER",
2073
+ format: options.format
2074
+ };
2075
+ if (options.text) {
2076
+ header.text = options.text;
2077
+ }
2078
+ if (options.example) {
2079
+ header.example = options.example;
2080
+ }
2081
+ return header;
2082
+ }
2083
+ function createBody(options) {
2084
+ const body = {
2085
+ type: "BODY",
2086
+ text: options.text
2087
+ };
2088
+ if (options.example) {
2089
+ body.example = options.example;
2090
+ }
2091
+ return body;
2092
+ }
2093
+ function createFooter(options) {
2094
+ return {
2095
+ type: "FOOTER",
2096
+ text: options.text
2097
+ };
2098
+ }
2099
+ function createButtons(options) {
2100
+ const buttons = [];
2101
+ if (options.phone_number) {
2102
+ buttons.push({
2103
+ type: "PHONE_NUMBER",
2104
+ text: options.phone_number.text,
2105
+ phone_number: options.phone_number.phone_number
2106
+ });
2107
+ }
2108
+ if (options.url) {
2109
+ const urlButton = {
2110
+ type: "URL",
2111
+ text: options.url.text,
2112
+ url: options.url.url
2113
+ };
2114
+ if (options.url.example) {
2115
+ urlButton.example = [options.url.example];
2116
+ }
2117
+ buttons.push(urlButton);
2118
+ }
2119
+ if (options.quick_reply) {
2120
+ options.quick_reply.forEach((qr) => {
2121
+ buttons.push({
2122
+ type: "QUICK_REPLY",
2123
+ text: qr.text
2124
+ });
2125
+ });
2126
+ }
2127
+ if (options.copy_code) {
2128
+ buttons.push({
2129
+ type: "COPY_CODE",
2130
+ example: options.copy_code.example
2131
+ });
2132
+ }
2133
+ if (options.flow) {
2134
+ const flowButton = {
2135
+ type: "FLOW",
2136
+ text: options.flow.text
2137
+ };
2138
+ if (options.flow.flow_id) flowButton.flow_id = options.flow.flow_id;
2139
+ if (options.flow.flow_name) flowButton.flow_name = options.flow.flow_name;
2140
+ if (options.flow.flow_json) flowButton.flow_json = options.flow.flow_json;
2141
+ if (options.flow.flow_action) flowButton.flow_action = options.flow.flow_action;
2142
+ if (options.flow.navigate_screen) flowButton.navigate_screen = options.flow.navigate_screen;
2143
+ buttons.push(flowButton);
2144
+ }
2145
+ if (options.mpm) {
2146
+ buttons.push({ type: "MPM" });
2147
+ }
2148
+ if (options.otp) {
2149
+ buttons.push({ type: "OTP" });
2150
+ }
2151
+ if (options.spm) {
2152
+ buttons.push({ type: "SPM" });
2153
+ }
2154
+ return buttons.length > 0 ? [{
2155
+ type: "BUTTONS",
2156
+ buttons
2157
+ }] : [];
2158
+ }
2159
+ function formatParameterExamples(parameters) {
2160
+ return parameters.map((param) => {
2161
+ switch (param.type) {
2162
+ case "text": return param.value;
2163
+ case "currency": return param.fallback_value;
2164
+ case "date_time": return param.fallback_value;
2165
+ case "image":
2166
+ case "video":
2167
+ case "document": return param.handle || param.link || "";
2168
+ case "location": return param.name || "";
2169
+ case "product": return param.product_retailer_id;
2170
+ default: return "";
2171
+ }
2172
+ });
2173
+ }
2174
+ function createTemplate(options) {
2175
+ const components = [];
2176
+ if (options.header) {
2177
+ components.push(createHeader(options.header));
2178
+ }
2179
+ if (options.body) {
2180
+ components.push(createBody(options.body));
2181
+ }
2182
+ if (options.footer) {
2183
+ components.push(createFooter(options.footer));
2184
+ }
2185
+ if (options.buttons) {
2186
+ components.push(...createButtons(options.buttons));
2187
+ }
2188
+ if (options.carousel) {
2189
+ const carouselComponents = [];
2190
+ options.carousel.cards.forEach((card, index) => {
2191
+ if (card.image || card.video || card.product) {
2192
+ const format = card.image ? "IMAGE" : card.video ? "VIDEO" : "DOCUMENT";
2193
+ const handle = card.image || card.video || card.product || "";
2194
+ carouselComponents.push({
2195
+ type: "HEADER",
2196
+ format,
2197
+ example: { header_handle: [handle] }
2198
+ });
2199
+ }
2200
+ if (card.body) {
2201
+ carouselComponents.push({
2202
+ type: "BODY",
2203
+ text: card.body,
2204
+ example: card.bodyParameters ? { body_text: [formatParameterExamples(card.bodyParameters)] } : undefined
2205
+ });
2206
+ }
2207
+ if (card.buttons) {
2208
+ carouselComponents.push(...createButtons(card.buttons));
2209
+ }
2210
+ });
2211
+ components.push(...carouselComponents);
2212
+ }
2213
+ if (options.limitedTimeOffer) {
2214
+ components.push({
2215
+ type: "LIMITED_TIME_OFFER",
2216
+ limited_time_offer: { expiration_time_ms: options.limitedTimeOffer.expiration_time_ms }
2217
+ });
2218
+ }
2219
+ return {
2220
+ name: options.name,
2221
+ language: options.language,
2222
+ category: options.category,
2223
+ components: components.length > 0 ? components : undefined
2224
+ };
2225
+ }
2226
+ function createOTPTemplate(options) {
2227
+ const components = [];
2228
+ let bodyText = "*{{1}}* is your verification code.";
2229
+ if (options.add_security_recommendation) {
2230
+ bodyText += " For your security, do not share this code.";
2231
+ }
2232
+ if (options.code_expiration_minutes) {
2233
+ bodyText += ` This code expires in ${options.code_expiration_minutes} minutes.`;
2234
+ }
2235
+ components.push({
2236
+ type: "BODY",
2237
+ text: bodyText,
2238
+ example: { body_text: [["123456"]] }
2239
+ });
2240
+ components.push({
2241
+ type: "BUTTONS",
2242
+ buttons: [{ type: "OTP" }]
2243
+ });
2244
+ return {
2245
+ name: options.name,
2246
+ language: options.language,
2247
+ category: CategoryEnum.Authentication,
2248
+ components
2249
+ };
2250
+ }
2251
+ function createAuthenticationTemplate(options) {
2252
+ const components = [];
2253
+ let bodyText = "Your security code is *{{1}}*.";
2254
+ if (options.add_security_recommendation) {
2255
+ bodyText += " Do not share this code with anyone.";
2256
+ }
2257
+ if (options.code_expiration_minutes) {
2258
+ bodyText += ` This code expires in ${options.code_expiration_minutes} minutes.`;
2259
+ }
2260
+ components.push({
2261
+ type: "BODY",
2262
+ text: bodyText,
2263
+ example: { body_text: [["ABCD1234"]] }
2264
+ });
2265
+ if (options.copy_code_button) {
2266
+ components.push({
2267
+ type: "BUTTONS",
2268
+ buttons: [{
2269
+ type: "COPY_CODE",
2270
+ example: "ABCD1234"
2271
+ }]
2272
+ });
2273
+ }
2274
+ return {
2275
+ name: options.name,
2276
+ language: options.language,
2277
+ category: CategoryEnum.Authentication,
2278
+ components
2279
+ };
2280
+ }
2281
+ function createCatalogTemplate(options) {
2282
+ const components = [];
2283
+ if (options.header) {
2284
+ components.push(createHeader({
2285
+ ...options.header,
2286
+ format: "TEXT"
2287
+ }));
2288
+ }
2289
+ components.push(createBody(options.body));
2290
+ if (options.footer) {
2291
+ components.push(createFooter(options.footer));
2292
+ }
2293
+ components.push({
2294
+ type: "BUTTONS",
2295
+ buttons: [{
2296
+ type: "CATALOG",
2297
+ action: { thumbnail_product_retailer_id: options.thumbnail_product_retailer_id }
2298
+ }]
2299
+ });
2300
+ return {
2301
+ name: options.name,
2302
+ language: options.language,
2303
+ category: CategoryEnum.Marketing,
2304
+ components
2305
+ };
2306
+ }
2307
+ function createCouponTemplate(options) {
2308
+ const components = [];
2309
+ if (options.header) {
2310
+ components.push(createHeader({
2311
+ ...options.header,
2312
+ format: "TEXT"
2313
+ }));
2314
+ }
2315
+ components.push(createBody(options.body));
2316
+ if (options.footer) {
2317
+ components.push(createFooter(options.footer));
2318
+ }
2319
+ components.push({
2320
+ type: "BUTTONS",
2321
+ buttons: [{
2322
+ type: "COPY_CODE",
2323
+ example: options.coupon_code
2324
+ }]
2325
+ });
2326
+ return {
2327
+ name: options.name,
2328
+ language: options.language,
2329
+ category: CategoryEnum.Marketing,
2330
+ components
2331
+ };
2332
+ }
2333
+ function createLimitedTimeOfferTemplate(options) {
2334
+ const components = [];
2335
+ components.push({
2336
+ type: "LIMITED_TIME_OFFER",
2337
+ limited_time_offer: { expiration_time_ms: options.expiration_time_ms }
2338
+ });
2339
+ if (options.header) {
2340
+ components.push(createHeader({
2341
+ ...options.header,
2342
+ format: "TEXT"
2343
+ }));
2344
+ }
2345
+ components.push(createBody(options.body));
2346
+ if (options.footer) {
2347
+ components.push(createFooter(options.footer));
2348
+ }
2349
+ return {
2350
+ name: options.name,
2351
+ language: options.language,
2352
+ category: CategoryEnum.Marketing,
2353
+ components
2354
+ };
2355
+ }
2356
+ function createMediaCardCarouselTemplate(options) {
2357
+ const components = [];
2358
+ const carouselCards = [];
2359
+ options.cards.forEach((card, index) => {
2360
+ const cardComponents = [];
2361
+ cardComponents.push({
2362
+ type: "HEADER",
2363
+ format: card.header.format,
2364
+ example: card.header.example
2365
+ });
2366
+ cardComponents.push(createBody(card.body));
2367
+ if (card.buttons) {
2368
+ cardComponents.push(...createButtons(card.buttons));
2369
+ }
2370
+ carouselCards.push({
2371
+ card_index: index,
2372
+ components: cardComponents
2373
+ });
2374
+ });
2375
+ components.push({
2376
+ type: "CAROUSEL",
2377
+ cards: carouselCards
2378
+ });
2379
+ return {
2380
+ name: options.name,
2381
+ language: options.language,
2382
+ category: CategoryEnum.Marketing,
2383
+ components
2384
+ };
2385
+ }
2386
+ function createMPMTemplate(options) {
2387
+ const components = [];
2388
+ if (options.header) {
2389
+ components.push(createHeader({
2390
+ ...options.header,
2391
+ format: "TEXT"
2392
+ }));
2393
+ }
2394
+ components.push(createBody(options.body));
2395
+ if (options.footer) {
2396
+ components.push(createFooter(options.footer));
2397
+ }
2398
+ components.push({
2399
+ type: "BUTTONS",
2400
+ buttons: [{
2401
+ type: "MPM",
2402
+ action: {
2403
+ thumbnail_product_retailer_id: options.thumbnail_product_retailer_id,
2404
+ sections: options.sections
2405
+ }
2406
+ }]
2407
+ });
2408
+ return {
2409
+ name: options.name,
2410
+ language: options.language,
2411
+ category: CategoryEnum.Marketing,
2412
+ components
2413
+ };
2414
+ }
2415
+ function createProductCardCarouselTemplate(options) {
2416
+ const components = [];
2417
+ if (options.header) {
2418
+ components.push(createHeader({
2419
+ ...options.header,
2420
+ format: "TEXT"
2421
+ }));
2422
+ }
2423
+ components.push(createBody(options.body));
2424
+ if (options.footer) {
2425
+ components.push(createFooter(options.footer));
2426
+ }
2427
+ const carouselCards = options.cards.map((card, index) => ({
2428
+ card_index: index,
2429
+ components: [{
2430
+ type: "HEADER",
2431
+ format: "PRODUCT",
2432
+ example: { header_handle: [card.product_retailer_id] }
2433
+ }]
2434
+ }));
2435
+ components.push({
2436
+ type: "CAROUSEL",
2437
+ cards: carouselCards
2438
+ });
2439
+ return {
2440
+ name: options.name,
2441
+ language: options.language,
2442
+ category: CategoryEnum.Marketing,
2443
+ components
2444
+ };
2445
+ }
2446
+ function createSPMTemplate(options) {
2447
+ const components = [];
2448
+ if (options.header) {
2449
+ components.push(createHeader({
2450
+ ...options.header,
2451
+ format: "TEXT"
2452
+ }));
2453
+ }
2454
+ components.push(createBody(options.body));
2455
+ if (options.footer) {
2456
+ components.push(createFooter(options.footer));
2457
+ }
2458
+ components.push({
2459
+ type: "BUTTONS",
2460
+ buttons: [{
2461
+ type: "SPM",
2462
+ action: { product_retailer_id: options.product_retailer_id }
2463
+ }]
2464
+ });
2465
+ return {
2466
+ name: options.name,
2467
+ language: options.language,
2468
+ category: CategoryEnum.Marketing,
2469
+ components
2470
+ };
2471
+ }
2472
+
2473
+ //#endregion
2474
+ //#region src/api/twoStepVerification/TwoStepVerificationApi.ts
2475
+ /**
2476
+ * API for managing WhatsApp Two-Step Verification.
2477
+ *
2478
+ * This API allows you to:
2479
+ * - Set a two-step verification PIN code
2480
+ * - Manage two-step verification settings
2481
+ */
2482
+ var TwoStepVerificationApi = class extends BaseAPI {
2483
+ constructor(config, client) {
2484
+ super(config, client);
2485
+ }
2486
+ /**
2487
+ * Set a two-step verification PIN code.
2488
+ *
2489
+ * @param pin The PIN code to set for two-step verification (6-digit numeric string)
2490
+ * @returns Response indicating success or failure
2491
+ *
2492
+ * @example
2493
+ * await whatsappClient.twoStepVerification.setTwoStepVerificationCode('123456');
2494
+ */
2495
+ async setTwoStepVerificationCode(pin) {
2496
+ const body = { pin };
2497
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.PhoneNumberId]}`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(body));
2498
+ }
2499
+ };
2500
+
2501
+ //#endregion
2502
+ //#region src/api/twoStepVerification/index.ts
2503
+ var twoStepVerification_default = TwoStepVerificationApi;
2504
+
2505
+ //#endregion
2506
+ //#region src/api/waba/WabaApi.ts
2507
+ /**
2508
+ * API for managing WhatsApp Business Account (WABA).
2509
+ *
2510
+ * This API allows you to:
2511
+ * - Get WABA account information
2512
+ * - Manage WABA subscriptions
2513
+ * - Subscribe/unsubscribe from WABA webhooks
2514
+ * - Update subscription settings
2515
+ */
2516
+ var WabaApi = class extends BaseAPI {
2517
+ constructor(config, client) {
2518
+ super(config, client);
2519
+ }
2520
+ /**
2521
+ * Retrieve WhatsApp Business Account information.
2522
+ *
2523
+ * @param fields Optional array of specific fields to retrieve
2524
+ * @returns WABA account information including status, health, verification status, etc.
2525
+ *
2526
+ * @example
2527
+ * const account = await whatsappClient.waba.getWabaAccount(['id', 'name', 'status']);
2528
+ */
2529
+ async getWabaAccount(fields) {
2530
+ const queryString = buildFieldsQueryString(fields)?.replace(/,/g, "%2C");
2531
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.BusinessAcctId]}${queryString}`, this.config[WabaConfigEnum.RequestTimeout], null);
2532
+ }
2533
+ /**
2534
+ * Get all WABA subscriptions for the business account.
2535
+ *
2536
+ * @returns List of all subscribed apps and their configurations
2537
+ *
2538
+ * @example
2539
+ * const subscriptions = await whatsappClient.waba.getAllWabaSubscriptions();
2540
+ */
2541
+ async getAllWabaSubscriptions() {
2542
+ return this.sendJson(HttpMethodsEnum.Get, `${this.config[WabaConfigEnum.BusinessAcctId]}/subscribed_apps`, this.config[WabaConfigEnum.RequestTimeout], null);
2543
+ }
2544
+ /**
2545
+ * Update WABA subscription configuration.
2546
+ *
2547
+ * @param params Configuration parameters including callback URI and verify token
2548
+ * @returns Response indicating success or failure
2549
+ *
2550
+ * @example
2551
+ * await whatsappClient.waba.updateWabaSubscription({
2552
+ * override_callback_uri: 'https://example.com/webhook',
2553
+ * verify_token: 'your_verify_token'
2554
+ * });
2555
+ */
2556
+ async updateWabaSubscription({ override_callback_uri, verify_token }) {
2557
+ const body = {
2558
+ override_callback_uri,
2559
+ verify_token
2560
+ };
2561
+ return this.sendJson(HttpMethodsEnum.Post, `${this.config[WabaConfigEnum.BusinessAcctId]}/subscribed_apps`, this.config[WabaConfigEnum.RequestTimeout], JSON.stringify(body));
2562
+ }
2563
+ /**
2564
+ * Unsubscribe from WABA webhooks.
2565
+ *
2566
+ * @returns Response indicating success or failure
2567
+ *
2568
+ * @example
2569
+ * await whatsappClient.waba.unsubscribeFromWaba();
2570
+ */
2571
+ async unsubscribeFromWaba() {
2572
+ return this.sendJson(HttpMethodsEnum.Delete, `${this.config[WabaConfigEnum.BusinessAcctId]}/subscribed_apps`, this.config[WabaConfigEnum.RequestTimeout], null);
2573
+ }
2574
+ };
2575
+
2576
+ //#endregion
2577
+ //#region src/api/waba/index.ts
2578
+ var waba_default = WabaApi;
2579
+
2580
+ //#endregion
2581
+ //#region src/utils/logoConsole.ts
2582
+ function printLogo() {
2583
+ if (process.env.NODE_ENV === "test" || process.env.VITEST === "true" || typeof global !== "undefined" && global.__VITEST__) {
2584
+ return;
2585
+ }
2586
+ console.log("\x1B[36m%s\x1B[0m", `
2587
+ ██████╗ ██╗ ██████╗ ██╗ ██╗ ██████╗ █████╗ ██████╗ ██╗
2588
+ ██╔════╝ ██║ ██╔═══██╗ ██║ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║
2589
+ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ███████║ ██████╔╝ ██║
2590
+ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██╔══██║ ██╔═══╝ ██║
2591
+ ╚██████╗ ███████╗ ╚██████╔╝ ╚██████╔╝ ██████╔╝ ██║ ██║ ██║ ██║
2592
+ ╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
2593
+ `);
2594
+ }
2595
+
2596
+ //#endregion
2597
+ //#region src/core/whatsapp/WhatsApp.ts
2598
+ const LIB_NAME$1 = "WHATSAPP";
2599
+ const LOGGER$2 = new Logger(LIB_NAME$1, process.env.DEBUG === "true");
2600
+ /**
2601
+ * WhatsApp SDK Main Class following official patterns
2602
+ * Provides unified access to WhatsApp Cloud API and Flows API
2603
+ */
2604
+ var WhatsApp = class {
2605
+ config;
2606
+ requester;
2607
+ messages;
2608
+ media;
2609
+ phoneNumbers;
2610
+ twoStepVerification;
2611
+ flows;
2612
+ businessProfile;
2613
+ templates;
2614
+ encryption;
2615
+ qrCode;
2616
+ registration;
2617
+ waba;
2618
+ constructor(config) {
2619
+ printLogo();
2620
+ this.config = importConfig(config);
2621
+ this.requester = new Requester(this.config[WabaConfigEnum.APIVersion], this.config[WabaConfigEnum.PhoneNumberId], this.config[WabaConfigEnum.AccessToken], this.config[WabaConfigEnum.BusinessAcctId], this.getUserAgent());
2622
+ this.messages = new messages_default(this.config, this.requester);
2623
+ this.media = new media_default(this.config, this.requester);
2624
+ this.phoneNumbers = new phone_default(this.config, this.requester);
2625
+ this.twoStepVerification = new twoStepVerification_default(this.config, this.requester);
2626
+ this.flows = new flow_default(this.config, this.requester);
2627
+ this.businessProfile = new profile_default(this.config, this.requester);
2628
+ this.templates = new TemplateApi(this.config, this.requester);
2629
+ this.encryption = new encryption_default(this.config, this.requester);
2630
+ this.qrCode = new qrCode_default(this.config, this.requester);
2631
+ this.registration = new registration_default(this.config, this.requester);
2632
+ this.waba = new waba_default(this.config, this.requester);
2633
+ LOGGER$2.log("\n" + formatConfigTable(this.config));
2634
+ }
2635
+ /**
2636
+ * Runtime configuration updates following official patterns
2637
+ */
2638
+ updateTimeout(timeout) {
2639
+ this.config[WabaConfigEnum.RequestTimeout] = timeout;
2640
+ if ("updateTimeout" in this.requester) {
2641
+ this.requester.updateTimeout(timeout);
2642
+ }
2643
+ LOGGER$2.log(`Timeout updated to ${timeout}ms`);
2644
+ }
2645
+ updateSenderNumberId(phoneNumberId) {
2646
+ this.config[WabaConfigEnum.PhoneNumberId] = phoneNumberId;
2647
+ LOGGER$2.log(`Sender number ID updated to ${phoneNumberId}`);
2648
+ }
2649
+ updateAccessToken(accessToken) {
2650
+ this.config[WabaConfigEnum.AccessToken] = accessToken;
2651
+ if ("updateAccessToken" in this.requester) {
2652
+ this.requester.updateAccessToken(accessToken);
2653
+ }
2654
+ LOGGER$2.log("Access token updated");
2655
+ }
2656
+ /**
2657
+ * Get SDK version
2658
+ */
2659
+ version() {
2660
+ return getVersion();
2661
+ }
2662
+ /**
2663
+ * Static enums access
2664
+ */
2665
+ static get Enums() {
2666
+ return enums_exports;
2667
+ }
2668
+ /**
2669
+ * Get User-Agent string
2670
+ */
2671
+ getUserAgent() {
2672
+ return getUserAgent();
2673
+ }
2674
+ };
2675
+
2676
+ //#endregion
2677
+ //#region src/api/waba/types/common.ts
2678
+ /**
2679
+ * WABA account review status enumeration
2680
+ */
2681
+ let WabaAccountReviewStatus = /* @__PURE__ */ function(WabaAccountReviewStatus$1) {
2682
+ WabaAccountReviewStatus$1["Approved"] = "APPROVED";
2683
+ WabaAccountReviewStatus$1["Active"] = "ACTIVE";
2684
+ WabaAccountReviewStatus$1["Inactive"] = "INACTIVE";
2685
+ WabaAccountReviewStatus$1["Disabled"] = "DISABLED";
2686
+ return WabaAccountReviewStatus$1;
2687
+ }({});
2688
+ /**
2689
+ * WABA health status for message sending capability
2690
+ */
2691
+ let WabaHealthStatusCanSendMessage = /* @__PURE__ */ function(WabaHealthStatusCanSendMessage$1) {
2692
+ WabaHealthStatusCanSendMessage$1["Blocked"] = "BLOCKED";
2693
+ WabaHealthStatusCanSendMessage$1["Limited"] = "LIMITED";
2694
+ WabaHealthStatusCanSendMessage$1["Available"] = "AVAILABLE";
2695
+ return WabaHealthStatusCanSendMessage$1;
2696
+ }({});
2697
+ /**
2698
+ * WABA account status enumeration
2699
+ */
2700
+ let WabaAccountStatus = /* @__PURE__ */ function(WabaAccountStatus$1) {
2701
+ WabaAccountStatus$1["Approved"] = "APPROVED";
2702
+ WabaAccountStatus$1["Active"] = "ACTIVE";
2703
+ WabaAccountStatus$1["Inactive"] = "INACTIVE";
2704
+ WabaAccountStatus$1["Disabled"] = "DISABLED";
2705
+ return WabaAccountStatus$1;
2706
+ }({});
2707
+ /**
2708
+ * Business verification status enumeration
2709
+ */
2710
+ let WabaBusinessVerificationStatus = /* @__PURE__ */ function(WabaBusinessVerificationStatus$1) {
2711
+ WabaBusinessVerificationStatus$1["Verified"] = "verified";
2712
+ WabaBusinessVerificationStatus$1["PendingSubmission"] = "pending_submission";
2713
+ WabaBusinessVerificationStatus$1["Unverified"] = "unverified";
2714
+ WabaBusinessVerificationStatus$1["Rejected"] = "rejected";
2715
+ return WabaBusinessVerificationStatus$1;
2716
+ }({});
2717
+
2718
+ //#endregion
2719
+ //#region src/utils/flowTypeGuards.ts
2720
+ /**
2721
+ * Helper function to check if a value is an object
2722
+ * @param value The value to check
2723
+ * @returns True if the value is a non-null object
2724
+ */
2725
+ function isObject(value) {
2726
+ return typeof value === "object" && value !== null;
2727
+ }
2728
+ /**
2729
+ * Helper function to check if a value is a string
2730
+ * @param value The value to check
2731
+ * @returns True if the value is a string
2732
+ */
2733
+ function isString(value) {
2734
+ return typeof value === "string";
2735
+ }
2736
+ const DATA_EXCHANGE_ACTIONS = [
2737
+ FlowActionEnum.DATA_EXCHANGE,
2738
+ FlowActionEnum.INIT,
2739
+ FlowActionEnum.BACK
2740
+ ];
2741
+ const ERROR_ACTIONS = [FlowActionEnum.DATA_EXCHANGE, FlowActionEnum.INIT];
2742
+ /**
2743
+ * Type guard to check if a request is a Data Exchange request
2744
+ * Validates the request structure according to the Flow API specifications
2745
+ *
2746
+ * @param request The Flow endpoint request to check
2747
+ * @returns True if the request is a valid Data Exchange request, false otherwise
2748
+ */
2749
+ function isFlowDataExchangeRequest(request) {
2750
+ if (!("flow_token" in request && isString(request.flow_token) && "action" in request)) {
2751
+ return false;
2752
+ }
2753
+ const { action, version, screen, data } = request;
2754
+ const hasValidVersion = version === "3.0";
2755
+ const hasValidAction = DATA_EXCHANGE_ACTIONS.includes(action);
2756
+ const hasValidScreen = typeof screen === "undefined" || isString(screen) && screen !== "SUCCESS";
2757
+ const hasValidData = action === FlowActionEnum.DATA_EXCHANGE || isObject(data);
2758
+ return hasValidVersion && hasValidAction && hasValidScreen && hasValidData;
2759
+ }
2760
+ /**
2761
+ * Type guard to check if a request is an Error Notification request
2762
+ * Validates the request structure according to the Flow API error specifications
2763
+ *
2764
+ * @param request The Flow endpoint request to check
2765
+ * @returns True if the request is a valid Error Notification request, false otherwise
2766
+ */
2767
+ function isFlowErrorRequest(request) {
2768
+ if (!("flow_token" in request && isString(request.flow_token) && "action" in request)) {
2769
+ return false;
2770
+ }
2771
+ const { action, screen, data } = request;
2772
+ const hasValidAction = ERROR_ACTIONS.includes(action);
2773
+ const hasValidScreen = isString(screen);
2774
+ const hasValidData = isObject(data) && "error_key" in data && isString(data.error) && "error_message" in data && isString(data.error_message);
2775
+ return hasValidAction && hasValidScreen && hasValidData;
2776
+ }
2777
+ /**
2778
+ * Type guard to check if a request is a Ping (health check) request
2779
+ * Simple validation for health check endpoints in the Flow API
2780
+ *
2781
+ * @param request The Flow endpoint request to check
2782
+ * @returns True if the request is a Ping request, false otherwise
2783
+ */
2784
+ function isFlowPingRequest(request) {
2785
+ return "action" in request && request.action === "ping";
2786
+ }
2787
+
2788
+ //#endregion
2789
+ //#region src/core/webhook/utils/webhookUtils.ts
2790
+ const LIB_NAME = "WEBHOOK_UTILS";
2791
+ const LOGGER$1 = new Logger(LIB_NAME, process.env.DEBUG === "true");
2792
+ /**
2793
+ * Process webhook messages
2794
+ */
2795
+ async function processWebhookMessages(request, whatsapp, handlers) {
2796
+ try {
2797
+ LOGGER$1.info("Processing webhook messages request");
2798
+ const body = await request.json();
2799
+ LOGGER$1.info("Webhook request body:", body);
2800
+ if (body.object !== "whatsapp_business_account") {
2801
+ const errorMsg = "Received webhook for non-WhatsApp event";
2802
+ LOGGER$1.warn(errorMsg, { body });
2803
+ return new Response(JSON.stringify({ error: errorMsg }), { status: 404 });
2804
+ }
2805
+ const errors = [];
2806
+ for (const entry of body.entry) {
2807
+ try {
2808
+ LOGGER$1.info("Processing webhook entry:", { entryId: entry.id });
2809
+ const changes = entry.changes;
2810
+ for (const change of changes) {
2811
+ if (change.field === "messages") {
2812
+ LOGGER$1.info("Processing messages change:", { change });
2813
+ await processMessages(entry.id, change.value, whatsapp, handlers);
2814
+ }
2815
+ }
2816
+ } catch (error) {
2817
+ const errorMsg = `Error processing webhook: ${error}`;
2818
+ LOGGER$1.error(errorMsg, {
2819
+ entry,
2820
+ error
2821
+ });
2822
+ errors.push(errorMsg);
2823
+ }
2824
+ }
2825
+ LOGGER$1.info("Webhook processing complete", { errorCount: errors.length });
2826
+ return new Response(errors.length > 0 ? JSON.stringify({ errors }) : null, { status: 200 });
2827
+ } catch (error) {
2828
+ LOGGER$1.error("Error processing webhook:", error);
2829
+ return new Response(JSON.stringify({ error: "Internal Server Error" }), { status: 500 });
2830
+ }
2831
+ }
2832
+ /**
2833
+ * Handle flow requests
2834
+ */
2835
+ async function processFlowRequest(request, config, whatsapp, flowHandlers) {
2836
+ try {
2837
+ LOGGER$1.info("Processing flow request");
2838
+ const body = await request.text();
2839
+ const signature = request.headers.get("x-hub-signature-256");
2840
+ LOGGER$1.info("Flow request signature:", { signature });
2841
+ if (!verifySignature(body, signature, config.WEBHOOK_VERIFICATION_TOKEN || "")) {
2842
+ LOGGER$1.warn("Invalid request signature", { signature });
2843
+ return new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 });
2844
+ }
2845
+ const data = JSON.parse(body);
2846
+ LOGGER$1.info("Flow request data:", data);
2847
+ const { decryptedBody } = decryptFlowRequest(data, config);
2848
+ LOGGER$1.info("Decrypted flow request:", decryptedBody);
2849
+ const handler = flowHandlers.get(FlowTypeEnum.All);
2850
+ if (!handler) {
2851
+ LOGGER$1.warn("No handler registered for flow action:", { action: decryptedBody.action });
2852
+ return new Response(JSON.stringify({ error: "Handler not found" }), { status: 404 });
2853
+ }
2854
+ if (isFlowPingRequest(decryptedBody)) {
2855
+ LOGGER$1.info("Handling flow ping request");
2856
+ return new Response(JSON.stringify({
2857
+ version: "3.0",
2858
+ data: { status: "active" }
2859
+ }), { status: 200 });
2860
+ }
2861
+ if (isFlowErrorRequest(decryptedBody)) {
2862
+ LOGGER$1.warn("Flow error request received:", decryptedBody);
2863
+ return new Response(null, { status: 200 });
2864
+ }
2865
+ if (isFlowDataExchangeRequest(decryptedBody)) {
2866
+ LOGGER$1.info("Processing flow data exchange request");
2867
+ const result = await handler(whatsapp, decryptedBody);
2868
+ LOGGER$1.info("Flow handler result:", result);
2869
+ const encryptedResponse = encryptFlowResponse(result, Buffer.from(data.aes_key, "base64"), Buffer.from(data.initial_vector, "base64"));
2870
+ LOGGER$1.info("Encrypted flow response generated");
2871
+ return new Response(JSON.stringify(encryptedResponse), { status: 200 });
2872
+ }
2873
+ LOGGER$1.warn("Unknown flow request type:", decryptedBody);
2874
+ return new Response(JSON.stringify({ error: "Unknown request type" }), { status: 400 });
2875
+ } catch (error) {
2876
+ LOGGER$1.error("Error handling flow request:", error);
2877
+ return new Response(JSON.stringify({ error: "Internal server error" }), { status: 500 });
2878
+ }
2879
+ }
2880
+ /**
2881
+ * Verify webhook signature
2882
+ */
2883
+ function verifySignature(body, signature, verificationToken) {
2884
+ if (!signature) {
2885
+ LOGGER$1.warn("Missing signature in request");
2886
+ return false;
2887
+ }
2888
+ LOGGER$1.info("Signature verification details:", {
2889
+ bodyLength: body.length,
2890
+ verificationTokenLength: verificationToken.length,
2891
+ rawSignature: signature,
2892
+ cleanedSignature: signature.replace("sha256=", "")
2893
+ });
2894
+ const expectedSignature = crypto.createHmac("sha256", verificationToken).update(body).digest("hex");
2895
+ LOGGER$1.info("Signature verification:", {
2896
+ received: signature.replace("sha256=", ""),
2897
+ expected: expectedSignature
2898
+ });
2899
+ return crypto.timingSafeEqual(Buffer.from(signature.replace("sha256=", "")), Buffer.from(expectedSignature));
2900
+ }
2901
+ /**
2902
+ * Constructs a full URL from framework-specific request headers and URL
2903
+ * @param headers - Request headers containing host and protocol information
2904
+ * @param url - Relative URL path
2905
+ * @returns Full URL string
2906
+ */
2907
+ function constructFullUrl(headers, url) {
2908
+ const protocol = headers["x-forwarded-proto"] || "http";
2909
+ const host = headers.host || "localhost";
2910
+ const path = url || "/";
2911
+ return `${protocol}://${host}${path}`;
2912
+ }
2913
+ /**
2914
+ * Private helper functions
2915
+ */
2916
+ async function processMessages(waba_id, value, whatsapp, handlers) {
2917
+ LOGGER$1.info("Processing messages:", {
2918
+ waba_id,
2919
+ value
2920
+ });
2921
+ const metadata = value.metadata;
2922
+ const contacts = value.contacts;
2923
+ const wabaId = waba_id;
2924
+ const displayPhoneNumber = metadata?.display_phone_number || "";
2925
+ const phoneNumberId = metadata?.phone_number_id || "";
2926
+ const profileName = contacts?.[0]?.profile?.name || "";
2927
+ if (value.statuses && value.statuses.length > 0) {
2928
+ LOGGER$1.info("Processing statuses:", { statusCount: value.statuses.length });
2929
+ const statuses = value.statuses;
2930
+ for (const status of statuses) {
2931
+ const processedStatus = {
2932
+ wabaId,
2933
+ id: status.id,
2934
+ from: status.recipient_id,
2935
+ timestamp: status.timestamp,
2936
+ type: MessageTypesEnum.Statuses,
2937
+ phoneNumberId,
2938
+ displayPhoneNumber,
2939
+ profileName,
2940
+ statuses: value.statuses[0],
2941
+ originalData: status
2942
+ };
2943
+ LOGGER$1.info("Processing status:", processedStatus);
2944
+ await executeHandler(handlers.messageHandlers.get(MessageTypesEnum.Statuses), whatsapp, processedStatus, MessageTypesEnum.Statuses);
2945
+ }
2946
+ return;
2947
+ }
2948
+ if (value.messages && value.messages.length > 0) {
2949
+ LOGGER$1.info("Processing messages:", { messageCount: value.messages.length });
2950
+ const messages = value.messages;
2951
+ for (const message of messages) {
2952
+ const messageType = message.type;
2953
+ LOGGER$1.info("Processing message:", {
2954
+ messageType,
2955
+ messageId: message.id
2956
+ });
2957
+ const processedMessage = {
2958
+ wabaId,
2959
+ id: message.id,
2960
+ from: message.from,
2961
+ timestamp: message.timestamp,
2962
+ type: message.type,
2963
+ phoneNumberId,
2964
+ displayPhoneNumber,
2965
+ profileName,
2966
+ originalData: message
2967
+ };
2968
+ switch (messageType) {
2969
+ case MessageTypesEnum.Text:
2970
+ processedMessage.text = message.text;
2971
+ break;
2972
+ case MessageTypesEnum.Image:
2973
+ processedMessage.image = message.image;
2974
+ break;
2975
+ case MessageTypesEnum.Video:
2976
+ processedMessage.video = message.video;
2977
+ break;
2978
+ case MessageTypesEnum.Audio:
2979
+ processedMessage.audio = message.audio;
2980
+ break;
2981
+ case MessageTypesEnum.Document:
2982
+ processedMessage.document = message.document;
2983
+ break;
2984
+ case MessageTypesEnum.Sticker:
2985
+ processedMessage.sticker = message.sticker;
2986
+ break;
2987
+ case MessageTypesEnum.Location:
2988
+ processedMessage.location = message.location;
2989
+ break;
2990
+ case MessageTypesEnum.Contacts:
2991
+ processedMessage.contacts = message.contacts;
2992
+ break;
2993
+ case MessageTypesEnum.Interactive:
2994
+ processedMessage.interactive = message.interactive;
2995
+ break;
2996
+ case MessageTypesEnum.Button:
2997
+ processedMessage.button = message.button;
2998
+ break;
2999
+ case MessageTypesEnum.Order:
3000
+ processedMessage.order = message.order;
3001
+ break;
3002
+ case MessageTypesEnum.System:
3003
+ processedMessage.system = message.system;
3004
+ break;
3005
+ case MessageTypesEnum.Reaction:
3006
+ processedMessage.reaction = message.reaction;
3007
+ break;
3008
+ default:
3009
+ LOGGER$1.warn("Unknown message type:", { messageType });
3010
+ break;
3011
+ }
3012
+ LOGGER$1.info("Executing message handlers");
3013
+ await executeHandler(handlers.preProcessHandler, whatsapp, processedMessage, "pre-process");
3014
+ await executeHandler(handlers.messageHandlers.get(messageType), whatsapp, processedMessage, messageType);
3015
+ await executeHandler(handlers.postProcessHandler, whatsapp, processedMessage, "post-process");
3016
+ }
3017
+ }
3018
+ }
3019
+ async function executeHandler(handler, whatsapp, message, handlerType) {
3020
+ if (handler) {
3021
+ try {
3022
+ LOGGER$1.info("Executing handler:", {
3023
+ handlerType,
3024
+ messageId: message.id
3025
+ });
3026
+ await handler(whatsapp, message);
3027
+ LOGGER$1.info("Handler execution complete:", {
3028
+ handlerType,
3029
+ messageId: message.id
3030
+ });
3031
+ } catch (error) {
3032
+ LOGGER$1.error(`Error in ${handlerType} handler:`, {
3033
+ error,
3034
+ messageId: message.id
3035
+ });
3036
+ }
3037
+ } else {
3038
+ LOGGER$1.info("No handler registered:", { handlerType });
3039
+ }
3040
+ }
3041
+ function decryptFlowRequest(body, config) {
3042
+ LOGGER$1.info("Decrypting flow request");
3043
+ const { encrypted_aes_key, encrypted_flow_data, initial_vector } = body;
3044
+ if (!encrypted_aes_key || !encrypted_flow_data || !initial_vector) {
3045
+ LOGGER$1.error("Missing required encryption properties");
3046
+ throw new Error("Missing required encryption properties");
3047
+ }
3048
+ const privatePem = config.FLOW_API_PRIVATE_PEM.replace(/\\n/g, "\n");
3049
+ const passphrase = config.FLOW_API_PASSPHRASE;
3050
+ const privateKey = crypto.createPrivateKey({
3051
+ key: privatePem,
3052
+ passphrase
3053
+ });
3054
+ let decryptedAesKey;
3055
+ try {
3056
+ LOGGER$1.info("Decrypting AES key");
3057
+ decryptedAesKey = crypto.privateDecrypt({
3058
+ key: privateKey,
3059
+ padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
3060
+ oaepHash: "sha256"
3061
+ }, Buffer.from(encrypted_aes_key, "base64"));
3062
+ } catch (error) {
3063
+ LOGGER$1.error("Failed to decrypt AES key:", error);
3064
+ throw new Error("Failed to decrypt the request. Please verify your private key.");
3065
+ }
3066
+ const flowDataBuffer = Buffer.from(encrypted_flow_data, "base64");
3067
+ const initialVectorBuffer = Buffer.from(initial_vector, "base64");
3068
+ const TAG_LENGTH = 16;
3069
+ const encrypted_flow_data_body = flowDataBuffer.subarray(0, -TAG_LENGTH);
3070
+ const encrypted_flow_data_tag = flowDataBuffer.subarray(-TAG_LENGTH);
3071
+ LOGGER$1.info("Decrypting flow data");
3072
+ const decipher = crypto.createDecipheriv("aes-128-gcm", decryptedAesKey, initialVectorBuffer);
3073
+ decipher.setAuthTag(encrypted_flow_data_tag);
3074
+ const decryptedJSONString = Buffer.concat([decipher.update(encrypted_flow_data_body), decipher.final()]).toString("utf-8");
3075
+ LOGGER$1.info("Flow request decryption complete");
3076
+ return {
3077
+ decryptedBody: JSON.parse(decryptedJSONString),
3078
+ aesKeyBuffer: decryptedAesKey,
3079
+ initialVectorBuffer
3080
+ };
3081
+ }
3082
+ function encryptFlowResponse(response, aesKeyBuffer, initialVectorBuffer) {
3083
+ LOGGER$1.info("Encrypting flow response");
3084
+ const flipped_iv = [];
3085
+ for (const pair of Array.from(initialVectorBuffer.entries())) {
3086
+ flipped_iv.push(~pair[1]);
3087
+ }
3088
+ try {
3089
+ const cipher = crypto.createCipheriv("aes-128-gcm", aesKeyBuffer, Buffer.from(flipped_iv));
3090
+ const encryptedResponse = Buffer.concat([
3091
+ cipher.update(JSON.stringify(response || {}), "utf-8"),
3092
+ cipher.final(),
3093
+ cipher.getAuthTag()
3094
+ ]).toString("base64");
3095
+ LOGGER$1.info("Flow response encryption complete");
3096
+ return encryptedResponse;
3097
+ } catch (error) {
3098
+ LOGGER$1.error("Response encryption error:", error);
3099
+ throw new Error("Failed to encrypt response. Internal server error.");
3100
+ }
3101
+ }
3102
+
3103
+ //#endregion
3104
+ //#region src/core/webhook/WebhookProcessor.ts
3105
+ const LOGGER = new Logger("WEBHOOK_PROCESSOR", process.env.DEBUG === "true");
3106
+ var WebhookProcessor = class {
3107
+ config;
3108
+ client;
3109
+ messageHandlers = new Map();
3110
+ preProcessHandler = undefined;
3111
+ postProcessHandler = undefined;
3112
+ flowHandlers = new Map();
3113
+ constructor(config) {
3114
+ this.config = importConfig(config);
3115
+ this.client = new WhatsApp(config);
3116
+ LOGGER.log("WebhookProcessor instantiated");
3117
+ }
3118
+ async processVerification(mode, token, challenge) {
3119
+ if (mode === "subscribe" && token === this.config.WEBHOOK_VERIFICATION_TOKEN) {
3120
+ return {
3121
+ status: 200,
3122
+ body: challenge || "",
3123
+ headers: { "Content-Type": "text/plain" }
3124
+ };
3125
+ }
3126
+ return {
3127
+ status: 403,
3128
+ body: JSON.stringify({ error: "Forbidden" }),
3129
+ headers: { "Content-Type": "application/json" }
3130
+ };
3131
+ }
3132
+ async processWebhook(request) {
3133
+ try {
3134
+ const webResponse = await processWebhookMessages(request, this.client, {
3135
+ messageHandlers: this.messageHandlers,
3136
+ preProcessHandler: this.preProcessHandler,
3137
+ postProcessHandler: this.postProcessHandler
3138
+ });
3139
+ const body = await webResponse.text();
3140
+ const contentType = webResponse.headers.get("content-type") || "application/json";
3141
+ return {
3142
+ status: webResponse.status,
3143
+ body,
3144
+ headers: { "Content-Type": contentType }
3145
+ };
3146
+ } catch (error) {
3147
+ LOGGER.log(`Error processing webhook: ${error}`);
3148
+ return {
3149
+ status: 500,
3150
+ body: JSON.stringify({ error: "Internal Server Error" }),
3151
+ headers: { "Content-Type": "application/json" }
3152
+ };
3153
+ }
3154
+ }
3155
+ async processFlow(request) {
3156
+ try {
3157
+ const webResponse = await processFlowRequest(request, this.config, this.client, this.flowHandlers);
3158
+ const body = await webResponse.text();
3159
+ const contentType = webResponse.headers.get("content-type") || "application/json";
3160
+ return {
3161
+ status: webResponse.status,
3162
+ body,
3163
+ headers: { "Content-Type": contentType }
3164
+ };
3165
+ } catch (error) {
3166
+ LOGGER.log(`Error processing flow: ${error}`);
3167
+ return {
3168
+ status: 500,
3169
+ body: JSON.stringify({ error: "Internal Server Error" }),
3170
+ headers: { "Content-Type": "application/json" }
3171
+ };
3172
+ }
3173
+ }
3174
+ onMessage(type, handler) {
3175
+ this.messageHandlers.set(type, handler);
3176
+ LOGGER.log(`Registered message handler for ${type}`);
3177
+ }
3178
+ onMessagePreProcess(handler) {
3179
+ this.preProcessHandler = handler;
3180
+ LOGGER.log("Registered pre-process handler");
3181
+ }
3182
+ onMessagePostProcess(handler) {
3183
+ this.postProcessHandler = handler;
3184
+ LOGGER.log("Registered post-process handler");
3185
+ }
3186
+ onFlow(type, handler) {
3187
+ this.flowHandlers.set(type, handler);
3188
+ LOGGER.log(`Registered flow handler for ${type}`);
3189
+ }
3190
+ getClient() {
3191
+ return this.client;
3192
+ }
3193
+ getConfig() {
3194
+ return this.config;
3195
+ }
3196
+ };
3197
+
3198
+ //#endregion
3199
+ //#region src/core/webhook/frameworks/handler.ts
3200
+ /**
3201
+ * Abstract base class for framework-agnostic webhook handlers
3202
+ * Provides common architecture and functionality across all frameworks
3203
+ */
3204
+ var BaseWebhookHandler = class {
3205
+ processor;
3206
+ constructor(config) {
3207
+ this.processor = new WebhookProcessor(config);
3208
+ }
3209
+ /**
3210
+ * Common webhook verification logic
3211
+ */
3212
+ async processVerification(mode, token, challenge) {
3213
+ return await this.processor.processVerification(mode, token, challenge);
3214
+ }
3215
+ /**
3216
+ * Common webhook processing logic
3217
+ */
3218
+ async processWebhook(request) {
3219
+ return await this.processor.processWebhook(request);
3220
+ }
3221
+ /**
3222
+ * Common flow processing logic
3223
+ */
3224
+ async processFlow(request) {
3225
+ return await this.processor.processFlow(request);
3226
+ }
3227
+ /**
3228
+ * Helper to construct full URL from headers and path
3229
+ */
3230
+ constructFullUrl(headers, url = "") {
3231
+ return constructFullUrl(headers, url);
3232
+ }
3233
+ /**
3234
+ * Helper to apply result headers to response
3235
+ */
3236
+ applyHeaders(result, res) {
3237
+ if (res.setHeader) {
3238
+ Object.entries(result.headers).forEach(([key, value]) => {
3239
+ res.setHeader(key, value);
3240
+ });
3241
+ }
3242
+ }
3243
+ /**
3244
+ * Auto-routing method handler that dispatches based on request method
3245
+ */
3246
+ async autoRoute(req, res, ...args) {
3247
+ const method = req.method?.toUpperCase();
3248
+ switch (method) {
3249
+ case "GET": return await this.handleGet(req, res, ...args);
3250
+ case "POST": return await this.handlePost(req, res, ...args);
3251
+ default:
3252
+ if (res.status && res.json) {
3253
+ return res.status(405).json({ error: "Method Not Allowed" });
3254
+ }
3255
+ throw new Error("Method Not Allowed");
3256
+ }
3257
+ }
3258
+ /**
3259
+ * Get the processor instance for handler registration
3260
+ */
3261
+ get webhookProcessor() {
3262
+ return this.processor;
3263
+ }
3264
+ };
3265
+
3266
+ //#endregion
3267
+ //#region src/core/webhook/frameworks/express.ts
3268
+ /**
3269
+ * Express-specific webhook handler extending the base handler
3270
+ */
3271
+ var ExpressWebhookHandler = class extends BaseWebhookHandler {
3272
+ constructor(config) {
3273
+ super(config);
3274
+ }
3275
+ async handleGet(req, res, next) {
3276
+ try {
3277
+ const { "hub.mode": mode, "hub.verify_token": token, "hub.challenge": challenge } = req.query;
3278
+ const result = await this.processVerification(mode || null, token || null, challenge || null);
3279
+ this.applyHeaders(result, res);
3280
+ return res.status(result.status).send(result.body);
3281
+ } catch (error) {
3282
+ next(error);
3283
+ return res;
3284
+ }
3285
+ }
3286
+ async handlePost(req, res, next) {
3287
+ try {
3288
+ const fullUrl = this.constructFullUrl(req.headers, req.url);
3289
+ const webRequest = new globalThis.Request(fullUrl, {
3290
+ method: req.method,
3291
+ headers: req.headers,
3292
+ body: JSON.stringify(req.body)
3293
+ });
3294
+ const result = await this.processWebhook(webRequest);
3295
+ this.applyHeaders(result, res);
3296
+ return res.status(result.status).send(result.body);
3297
+ } catch (error) {
3298
+ next(error);
3299
+ return res;
3300
+ }
3301
+ }
3302
+ async handleFlow(req, res, next) {
3303
+ try {
3304
+ const fullUrl = this.constructFullUrl(req.headers, req.url);
3305
+ const webRequest = new globalThis.Request(fullUrl, {
3306
+ method: req.method,
3307
+ headers: req.headers,
3308
+ body: req.method === "POST" ? JSON.stringify(req.body) : undefined
3309
+ });
3310
+ const result = await this.processFlow(webRequest);
3311
+ this.applyHeaders(result, res);
3312
+ return res.status(result.status).send(result.body);
3313
+ } catch (error) {
3314
+ next(error);
3315
+ return res;
3316
+ }
3317
+ }
3318
+ getHandlers() {
3319
+ return {
3320
+ GET: (req, res, next) => this.handleGet(req, res, next),
3321
+ POST: (req, res, next) => this.handlePost(req, res, next),
3322
+ webhook: (req, res, next) => this.autoRoute(req, res, next),
3323
+ flow: (req, res, next) => this.handleFlow(req, res, next),
3324
+ processor: this.webhookProcessor
3325
+ };
3326
+ }
3327
+ };
3328
+ function webhookHandler(config) {
3329
+ const handler = new ExpressWebhookHandler(config);
3330
+ return handler.getHandlers();
3331
+ }
3332
+
3333
+ //#endregion
3334
+ //#region src/core/webhook/frameworks/nextjs.ts
3335
+ /**
3336
+ * Next.js Page Router webhook handler extending the base handler
3337
+ */
3338
+ var NextJsWebhookHandler = class extends BaseWebhookHandler {
3339
+ constructor(config) {
3340
+ super(config);
3341
+ }
3342
+ async parseRequestBody(req) {
3343
+ if (req.method === "POST" && !req.body) {
3344
+ const chunks = [];
3345
+ if (typeof req[Symbol.asyncIterator] === "function") {
3346
+ for await (const chunk of req) {
3347
+ chunks.push(chunk);
3348
+ }
3349
+ const body = Buffer.concat(chunks).toString();
3350
+ if (body.trim()) {
3351
+ try {
3352
+ req.body = JSON.parse(body);
3353
+ } catch (error) {
3354
+ throw new Error("Invalid JSON in request body");
3355
+ }
3356
+ } else {
3357
+ req.body = {};
3358
+ }
3359
+ }
3360
+ }
3361
+ }
3362
+ async handleGet(req, res) {
3363
+ try {
3364
+ const { "hub.mode": mode, "hub.verify_token": token, "hub.challenge": challenge } = req.query;
3365
+ const result = await this.processVerification(mode || null, token || null, challenge || null);
3366
+ this.applyHeaders(result, res);
3367
+ return res.status(result.status).send(result.body);
3368
+ } catch (error) {
3369
+ console.error("Webhook verification error:", error);
3370
+ return res.status(500).json({ error: "Internal Server Error" });
3371
+ }
3372
+ }
3373
+ async handlePost(req, res) {
3374
+ try {
3375
+ await this.parseRequestBody(req);
3376
+ } catch (error) {
3377
+ console.error("Webhook processing error:", error);
3378
+ if (error instanceof Error && error.message === "Invalid JSON in request body") {
3379
+ return res.status(400).json({ error: "Invalid JSON" });
3380
+ }
3381
+ return res.status(500).json({ error: "Internal Server Error" });
3382
+ }
3383
+ try {
3384
+ const fullUrl = this.constructFullUrl(req.headers, req.url);
3385
+ const webRequest = new Request(fullUrl, {
3386
+ method: "POST",
3387
+ headers: req.headers,
3388
+ body: JSON.stringify(req.body)
3389
+ });
3390
+ const result = await this.processWebhook(webRequest);
3391
+ this.applyHeaders(result, res);
3392
+ return res.status(result.status).send(result.body);
3393
+ } catch (error) {
3394
+ console.error("Webhook processing error:", error);
3395
+ return res.status(500).json({ error: "Internal Server Error" });
3396
+ }
3397
+ }
3398
+ async handleFlow(req, res) {
3399
+ try {
3400
+ const fullUrl = this.constructFullUrl(req.headers, req.url);
3401
+ const webRequest = new Request(fullUrl, {
3402
+ method: req.method,
3403
+ headers: req.headers,
3404
+ body: req.method === "POST" ? JSON.stringify(req.body) : undefined
3405
+ });
3406
+ const result = await this.processFlow(webRequest);
3407
+ this.applyHeaders(result, res);
3408
+ return res.status(result.status).send(result.body);
3409
+ } catch (error) {
3410
+ console.error("Flow error:", error);
3411
+ return res.status(500).json({ error: "Internal Server Error" });
3412
+ }
3413
+ }
3414
+ getHandlers() {
3415
+ return {
3416
+ GET: (req, res) => this.handleGet(req, res),
3417
+ POST: (req, res) => this.handlePost(req, res),
3418
+ webhook: (req, res) => this.autoRoute(req, res),
3419
+ flow: (req, res) => this.handleFlow(req, res),
3420
+ processor: this.webhookProcessor
3421
+ };
3422
+ }
3423
+ };
3424
+ function webhookHandler$1(config) {
3425
+ const handler = new NextJsWebhookHandler(config);
3426
+ return handler.getHandlers();
3427
+ }
3428
+
3429
+ //#endregion
3430
+ //#region src/core/webhook/utils/generateXHub256Sig.ts
3431
+ const generateXHub256Sig = (body, appSecret) => {
3432
+ return crypto$1.createHmac("sha256", appSecret).update(body, "utf-8").digest("hex");
3433
+ };
3434
+
3435
+ //#endregion
3436
+ export { AudioMediaTypesEnum, profile_default as BusinessProfileApi, BusinessVerticalEnum, ButtonPositionEnum, CategoryEnum, ComponentTypesEnum, ConversationTypesEnum, CurrencyCodesEnum, DataLocalizationRegionEnum, DocumentMediaTypesEnum, encryption_default as EncryptionApi, webhookHandler as ExpressWebhook, FlowActionEnum, flow_default as FlowApi, FlowCategoryEnum, FlowStatusEnum, FlowTypeEnum, HttpMethodsEnum, ImageMediaTypesEnum, InteractiveTypesEnum, LanguagesEnum, media_default as MediaApi, MessageTypesEnum, messages_default as MessagesApi, webhookHandler$1 as NextJsWebhook, ParametersTypesEnum, phone_default as PhoneNumberApi, qrCode_default as QrCodeApi, registration_default as RegistrationApi, RequestCodeMethodsEnum, StatusEnum, StickerMediaTypesEnum, SubTypeEnum, SystemChangeTypesEnum, TemplateApi, TemplateStatusEnum, twoStepVerification_default as TwoStepVerificationApi, VideoMediaTypesEnum, WabaAccountReviewStatus, WabaAccountStatus, waba_default as WabaApi, WabaBusinessVerificationStatus, WabaConfigEnum, WabaHealthStatusCanSendMessage, WebhookTypesEnum, WhatsApp, WhatsApp as WhatsAppLegacy, isFlowDataExchangeRequest, isFlowErrorRequest, isFlowPingRequest, isMetaError };
2
3437
  //# sourceMappingURL=index.js.map