meta-cloud-api 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,28 +1,28 @@
1
1
  export { IRequest, IResponse, default as WebhookHandler } from './webhook.mjs';
2
2
  import WhatsApp from './whatsapp.mjs';
3
+ export { BaseClass } from './types/base.mjs';
4
+ export { BusinessProfileClass, BusinessProfileData, BusinessProfileField, BusinessProfileFieldsParam, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadBusinessProfileResponse, UploadHandle, UploadSession, UploadSessionResponse } from './types/businessProfile.mjs';
3
5
  export { WabaConfigType } from './types/config.mjs';
6
+ export { EncryptionClass, EncryptionPublicKeyResponse } from './types/encryption.mjs';
4
7
  export { A as AudioMediaTypesEnum, k as BusinessVerticalEnum, a as ButtonPositionEnum, B as ButtonTypesEnum, C as CategoryEnum, b as ComponentTypesEnum, c as ConversationTypesEnum, i as CurrencyCodesEnum, j as DataLocalizationRegionEnum, D as DocumentMediaTypesEnum, H as HttpMethodsEnum, e as ImageMediaTypesEnum, I as InteractiveTypesEnum, L as LanguagesEnum, M as MessageTypesEnum, P as ParametersTypesEnum, R as ReferralSourceTypesEnum, h as RequestCodeMethodsEnum, S as StatusEnum, d as StickerMediaTypesEnum, g as SystemChangeTypesEnum, T as TemplateStatusEnum, V as VideoMediaTypesEnum, W as WabaConfigEnum, f as WebhookTypesEnum } from './enums-DEhBfoMC.mjs';
5
- export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.mjs';
6
- export { BaseClass } from './types/base.mjs';
8
+ export { CreateFlowResponse, Flow, FlowAsset, FlowAssetsResponse, FlowCategoryEnum, FlowClass, FlowMigrationFailure, FlowMigrationResponse, FlowMigrationResult, FlowPreview, FlowPreviewResponse, FlowStatusEnum, FlowValidationError, FlowValidationErrorPointer, FlowsListResponse, Pagination, PaginationCursors, UpdateFlowResponse, ValidateFlowJsonResponse } from './types/flow.mjs';
7
9
  export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.mjs';
8
10
  export { LoggerInterface } from './types/logger.mjs';
11
+ export { MediaClass, MediaResponse, MediasResponse, UploadMediaResponse } from './types/media.mjs';
9
12
  export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageRequestParams, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, ReactionParams, StatusObject, StatusParams, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageParams, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.mjs';
10
- export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.mjs';
11
- export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.mjs';
12
13
  export { AccountMode, CodeVerificationStatus, Cursors, HealthStatus, HealthStatusEntity, MessagingLimitTier, PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, PlatformType, QualityRating, QualityScore, RequestVerificationCodeRequest, Throughput, ThroughputLevel, TwoStepVerificationParams, VerifyCodeRequest } from './types/phoneNumber.mjs';
14
+ export { CreateQrCodeRequest, QrCodeClass, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from './types/qrCode.mjs';
13
15
  export { RegistrationClass, RegistrationRequest } from './types/registration.mjs';
16
+ export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.mjs';
17
+ export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.mjs';
14
18
  export { TwoStepVerificationClass, TwoStepVerificationRequest } from './types/twoStepVerification.mjs';
15
- export { CreateQrCodeRequest, QrCodeClass, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from './types/qrCode.mjs';
16
- export { EncryptionClass, EncryptionPublicKeyResponse } from './types/encryption.mjs';
17
19
  export { UpdateWabaSubscription, WABAClass, WabaAccount, WabaAccountFields, WabaAccountFieldsParam, WabaAccountReviewStatus, WabaAccountStatus, WabaBusinessVerificationStatus, WabaHealthStatus, WabaHealthStatusCanSendMessage, WabaHealthStatusEntity, WabaHealthStatusError, WabaSubscription, WabaSubscriptions } from './types/waba.mjs';
18
- export { MediaClass, MediaResponse, MediasResponse, UploadMediaResponse } from './types/media.mjs';
19
- export { CreateFlowResponse, Flow, FlowAsset, FlowAssetsResponse, FlowCategoryEnum, FlowClass, FlowMigrationFailure, FlowMigrationResponse, FlowMigrationResult, FlowPreview, FlowPreviewResponse, FlowStatusEnum, FlowValidationError, FlowValidationErrorPointer, FlowsListResponse, Pagination, PaginationCursors, UpdateFlowResponse, ValidateFlowJsonResponse } from './types/flow.mjs';
20
- export { BusinessProfileClass, BusinessProfileData, BusinessProfileField, BusinessProfileFieldsParam, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadBusinessProfileResponse, UploadHandle, UploadSession, UploadSessionResponse } from './types/businessProfile.mjs';
20
+ export { EventField, EventHandler, MessageHandler, MessageStatus, WebhookEvent, WebhookMessage } from './types/webhook.mjs';
21
+ export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.mjs';
21
22
  export { generateXHub256Sig } from './utils/generateXHub256Sig.mjs';
22
23
  export { importConfig } from './utils/importConfig.mjs';
23
24
  export { MetaError, isMetaError } from './utils/isMetaError.mjs';
24
25
  export { objectToQueryString } from './utils/objectToQueryString.mjs';
25
- import './types/webhook.mjs';
26
26
  import './api/businessProfile.mjs';
27
27
  import './api/base.mjs';
28
28
  import './api/encryption.mjs';
package/dist/index.d.ts CHANGED
@@ -1,28 +1,28 @@
1
1
  export { IRequest, IResponse, default as WebhookHandler } from './webhook.js';
2
2
  import WhatsApp from './whatsapp.js';
3
+ export { BaseClass } from './types/base.js';
4
+ export { BusinessProfileClass, BusinessProfileData, BusinessProfileField, BusinessProfileFieldsParam, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadBusinessProfileResponse, UploadHandle, UploadSession, UploadSessionResponse } from './types/businessProfile.js';
3
5
  export { WabaConfigType } from './types/config.js';
6
+ export { EncryptionClass, EncryptionPublicKeyResponse } from './types/encryption.js';
4
7
  export { A as AudioMediaTypesEnum, k as BusinessVerticalEnum, a as ButtonPositionEnum, B as ButtonTypesEnum, C as CategoryEnum, b as ComponentTypesEnum, c as ConversationTypesEnum, i as CurrencyCodesEnum, j as DataLocalizationRegionEnum, D as DocumentMediaTypesEnum, H as HttpMethodsEnum, e as ImageMediaTypesEnum, I as InteractiveTypesEnum, L as LanguagesEnum, M as MessageTypesEnum, P as ParametersTypesEnum, R as ReferralSourceTypesEnum, h as RequestCodeMethodsEnum, S as StatusEnum, d as StickerMediaTypesEnum, g as SystemChangeTypesEnum, T as TemplateStatusEnum, V as VideoMediaTypesEnum, W as WabaConfigEnum, f as WebhookTypesEnum } from './enums-DEhBfoMC.js';
5
- export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.js';
6
- export { BaseClass } from './types/base.js';
8
+ export { CreateFlowResponse, Flow, FlowAsset, FlowAssetsResponse, FlowCategoryEnum, FlowClass, FlowMigrationFailure, FlowMigrationResponse, FlowMigrationResult, FlowPreview, FlowPreviewResponse, FlowStatusEnum, FlowValidationError, FlowValidationErrorPointer, FlowsListResponse, Pagination, PaginationCursors, UpdateFlowResponse, ValidateFlowJsonResponse } from './types/flow.js';
7
9
  export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.js';
8
10
  export { LoggerInterface } from './types/logger.js';
11
+ export { MediaClass, MediaResponse, MediasResponse, UploadMediaResponse } from './types/media.js';
9
12
  export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageRequestParams, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, ReactionParams, StatusObject, StatusParams, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageParams, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.js';
10
- export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.js';
11
- export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.js';
12
13
  export { AccountMode, CodeVerificationStatus, Cursors, HealthStatus, HealthStatusEntity, MessagingLimitTier, PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, PlatformType, QualityRating, QualityScore, RequestVerificationCodeRequest, Throughput, ThroughputLevel, TwoStepVerificationParams, VerifyCodeRequest } from './types/phoneNumber.js';
14
+ export { CreateQrCodeRequest, QrCodeClass, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from './types/qrCode.js';
13
15
  export { RegistrationClass, RegistrationRequest } from './types/registration.js';
16
+ export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.js';
17
+ export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.js';
14
18
  export { TwoStepVerificationClass, TwoStepVerificationRequest } from './types/twoStepVerification.js';
15
- export { CreateQrCodeRequest, QrCodeClass, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from './types/qrCode.js';
16
- export { EncryptionClass, EncryptionPublicKeyResponse } from './types/encryption.js';
17
19
  export { UpdateWabaSubscription, WABAClass, WabaAccount, WabaAccountFields, WabaAccountFieldsParam, WabaAccountReviewStatus, WabaAccountStatus, WabaBusinessVerificationStatus, WabaHealthStatus, WabaHealthStatusCanSendMessage, WabaHealthStatusEntity, WabaHealthStatusError, WabaSubscription, WabaSubscriptions } from './types/waba.js';
18
- export { MediaClass, MediaResponse, MediasResponse, UploadMediaResponse } from './types/media.js';
19
- export { CreateFlowResponse, Flow, FlowAsset, FlowAssetsResponse, FlowCategoryEnum, FlowClass, FlowMigrationFailure, FlowMigrationResponse, FlowMigrationResult, FlowPreview, FlowPreviewResponse, FlowStatusEnum, FlowValidationError, FlowValidationErrorPointer, FlowsListResponse, Pagination, PaginationCursors, UpdateFlowResponse, ValidateFlowJsonResponse } from './types/flow.js';
20
- export { BusinessProfileClass, BusinessProfileData, BusinessProfileField, BusinessProfileFieldsParam, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadBusinessProfileResponse, UploadHandle, UploadSession, UploadSessionResponse } from './types/businessProfile.js';
20
+ export { EventField, EventHandler, MessageHandler, MessageStatus, WebhookEvent, WebhookMessage } from './types/webhook.js';
21
+ export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.js';
21
22
  export { generateXHub256Sig } from './utils/generateXHub256Sig.js';
22
23
  export { importConfig } from './utils/importConfig.js';
23
24
  export { MetaError, isMetaError } from './utils/isMetaError.js';
24
25
  export { objectToQueryString } from './utils/objectToQueryString.js';
25
- import './types/webhook.js';
26
26
  import './api/businessProfile.js';
27
27
  import './api/base.js';
28
28
  import './api/encryption.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var Me=Object.create;var K=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var me=(r,t)=>{for(var s in t)K(r,s,{get:t[s],enumerable:!0})},Re=(r,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of De(t))!Ue.call(r,o)&&o!==s&&K(r,o,{get:()=>t[o],enumerable:!(i=Oe(t,o))||i.enumerable});return r};var xe=(r,t,s)=>(s=r!=null?Me(Be(r)):{},Re(t||!r||!r.__esModule?K(s,"default",{value:r,enumerable:!0}):s,r)),ve=r=>Re(K({},"__esModule",{value:!0}),r);var ot={};me(ot,{AudioMediaTypesEnum:()=>ie,BusinessVerticalEnum:()=>ge,ButtonPositionEnum:()=>Z,ButtonTypesEnum:()=>Y,CategoryEnum:()=>u,ComponentTypesEnum:()=>Q,ConversationTypesEnum:()=>z,CurrencyCodesEnum:()=>le,DataLocalizationRegionEnum:()=>ce,DocumentMediaTypesEnum:()=>se,FlowCategoryEnum:()=>Te,FlowStatusEnum:()=>_e,HttpMethodsEnum:()=>P,ImageMediaTypesEnum:()=>te,InteractiveTypesEnum:()=>X,LanguagesEnum:()=>pe,MessageTypesEnum:()=>q,ParametersTypesEnum:()=>V,ReferralSourceTypesEnum:()=>ae,RequestCodeMethodsEnum:()=>ne,StatusEnum:()=>E,StickerMediaTypesEnum:()=>ee,SystemChangeTypesEnum:()=>re,TemplateStatusEnum:()=>j,VideoMediaTypesEnum:()=>C,WabaAccountReviewStatus:()=>he,WabaAccountStatus:()=>be,WabaBusinessVerificationStatus:()=>Ae,WabaConfigEnum:()=>h,WabaHealthStatusCanSendMessage:()=>Pe,WebhookHandler:()=>G,WebhookTypesEnum:()=>oe,default:()=>it,generateXHub256Sig:()=>Fe,importConfig:()=>y,isMetaError:()=>k,objectToQueryString:()=>T});module.exports=ve(ot);var fe={};me(fe,{AudioMediaTypesEnum:()=>ie,BusinessVerticalEnum:()=>ge,ButtonPositionEnum:()=>Z,ButtonTypesEnum:()=>Y,CategoryEnum:()=>u,ComponentTypesEnum:()=>Q,ConversationTypesEnum:()=>z,CurrencyCodesEnum:()=>le,DataLocalizationRegionEnum:()=>ce,DocumentMediaTypesEnum:()=>se,HttpMethodsEnum:()=>P,ImageMediaTypesEnum:()=>te,InteractiveTypesEnum:()=>X,LanguagesEnum:()=>pe,MessageTypesEnum:()=>q,ParametersTypesEnum:()=>V,ReferralSourceTypesEnum:()=>ae,RequestCodeMethodsEnum:()=>ne,StatusEnum:()=>E,StickerMediaTypesEnum:()=>ee,SystemChangeTypesEnum:()=>re,TemplateStatusEnum:()=>j,VideoMediaTypesEnum:()=>C,WabaConfigEnum:()=>h,WebhookTypesEnum:()=>oe});var u=(i=>(i.Authentication="AUTHENTICATION",i.Marketing="MARKETING",i.Utility="UTILITY",i))(u||{}),j=(i=>(i.Approved="APPROVED",i.Pending="PENDING",i.Rejected="REJECTED",i))(j||{}),P=(o=>(o.Get="GET",o.Post="POST",o.Put="PUT",o.Delete="DELETE",o))(P||{}),q=(R=>(R.Audio="audio",R.Contacts="contacts",R.Document="document",R.Image="image",R.Interactive="interactive",R.Location="location",R.Reaction="sticker",R.Sticker="sticker",R.Template="template",R.Text="text",R.Video="video",R.Button="button",R.Order="order",R.System="system",R.Unknown="unknown",R["*"]="*",R))(q||{}),V=(l=>(l.Currency="currency",l.DateTime="date_time",l.Document="document",l.Image="image",l.Text="text",l.Video="video",l.Payload="payload",l))(V||{}),X=(p=>(p.Button="button",p.List="list",p.Product="product",p.ProductList="product_list",p.CtaUrl="cta_url",p.LocationRequest="location_request_message",p.AddressMessage="address_message",p.Flow="flow",p))(X||{}),Y=(s=>(s.QuickReply="quick_reply",s.URL="url",s))(Y||{}),Z=(i=>(i[i.First=0]="First",i[i.Second=1]="Second",i[i.Third=2]="Third",i))(Z||{}),Q=(o=>(o.Header="HEADER",o.Body="BODY",o.Button="BUTTON",o.Footer="FOOTER",o))(Q||{}),h=(c=>(c.BaseURL="WA_BASE_URL",c.AppId="M4D_APP_ID",c.Port="WA_PORT",c.AppSecret="M4D_APP_SECRET",c.PhoneNumberId="WA_PHONE_NUMBER_ID",c.BusinessAcctId="WA_BUSINESS_ACCOUNT_ID",c.APIVersion="CLOUD_API_VERSION",c.AccessToken="CLOUD_API_ACCESS_TOKEN",c.WebhookEndpoint="WEBHOOK_ENDPOINT",c.WebhookVerificationToken="WEBHOOK_VERIFICATION_TOKEN",c.ListenerPort="LISTENER_PORT",c.MaxRetriesAfterWait="MAX_RETRIES_AFTER_WAIT",c.RequestTimeout="REQUEST_TIMEOUT",c.Debug="DEBUG",c))(h||{}),z=(i=>(i.BusinessInitiated="business_initiated",i.CustomerInitiated="customer_initiated",i.ReferralConversion="referral_conversion",i))(z||{}),E=(i=>(i.Delivered="delivered",i.Read="read",i.Sent="sent",i))(E||{}),C=(s=>(s.Mp4="video/mp4",s.Threegp="video/3gp",s))(C||{}),ee=(t=>(t.Webp="image/webp",t))(ee||{}),te=(s=>(s.Jpeg="image/jpeg",s.Png="image/png",s))(te||{}),se=(p=>(p.Text="text/plain",p.Pdf="application/pdf",p.Ppt="application/vnd.ms-powerpoint",p.Word="application/msword",p.Excel="application/vnd.ms-excel",p.OpenDoc="application/vnd.openxmlformats-officedocument.wordprocessingml.document",p.OpenPres="application/vnd.openxmlformats-officedocument.presentationml.presentation",p.OpenSheet="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",p))(se||{}),ie=(n=>(n.Aac="audio/aac",n.Mp4="audio/mp4",n.Mpeg="audio/mpeg",n.Amr="audio/amr",n.Ogg="audio/ogg",n))(ie||{}),oe=(A=>(A.Audio="audio",A.Button="button",A.Document="document",A.Text="text",A.Image="image",A.Interactive="interactive",A.Order="order",A.Sticker="sticker",A.System="system",A.Unknown="unknown",A.Video="video",A))(oe||{}),re=(s=>(s.CustomerChangedNumber="customer_changed_number",s.CustomerIdentityChanged="customer_identity_changed",s))(re||{}),ae=(s=>(s.Ad="ad",s.Post="post",s))(ae||{}),ne=(s=>(s.Sms="SMS",s.Voice="VOICE",s))(ne||{}),pe=(a=>(a.Afrikaans="af",a.Albanian="sq",a.Arabic="ar",a.Azerbaijani="az",a.Bengali="bn",a.Bulgarian="bg",a.Catalan="ca",a.Chinese_CHN="zh_CN",a.Chinese_HKG="zh_HK",a.Chinese_TAI="zh_TW",a.Croatian="hr",a.Czech="cs",a.Danish="da",a.Dutch="nl",a.English="en",a.English_UK="en_GB",a.English_US="en_US",a.Estonian="et",a.Filipino="fil",a.Finnish="fi",a.French="fr",a.Georgian="ka",a.German="de",a.Greek="el",a.Gujarati="gu",a.Hausa="ha",a.Hebrew="he",a.Hindi="hi",a.Hungarian="hu",a.Indonesian="id",a.Irish="ga",a.Italian="it",a.Japanese="ja",a.Kannada="kn",a.Kazakh="kk",a.Kinyarwanda="rw_RW",a.Korean="ko",a.Kyrgyz_Kyrgyzstan="ky_KG",a.Lao="lo",a.Latvian="lv",a.Lithuanian="lt",a.Macedonian="mk",a.Malay="ms",a.Malayalam="ml",a.Marathi="mr",a.Norwegian="nb",a.Persian="fa",a.Polish="pl",a.Portuguese_BR="pt_BR",a.Portuguese_POR="pt_PT",a.Punjabi="pa",a.Romanian="ro",a.Russian="ru",a.Serbian="sr",a.Slovak="sk",a.Slovenian="sl",a.Spanish="es",a.Spanish_ARG="es_AR",a.Spanish_SPA="es_ES",a.Spanish_MEX="es_MX",a.Swahili="sw",a.Swedish="sv",a.Tamil="ta",a.Telugu="te",a.Thai="th",a.Turkish="tr",a.Ukrainian="uk",a.Urdu="ur",a.Uzbek="uz",a.Vietnamese="vi",a.Zulu="zu",a))(pe||{}),le=(e=>(e.AFN="AFN",e.EUR="EUR",e.ALL="ALL",e.DZD="DZD",e.USD="USD",e.AOA="AOA",e.XCD="XCD",e.ARS="ARS",e.AMD="AMD",e.AWG="AWG",e.AUD="AUD",e.AZN="AZN",e.BSD="BSD",e.BHD="BHD",e.BDT="BDT",e.BBD="BBD",e.BYN="BYN",e.BZD="BZD",e.XOF="XOF",e.BMD="BMD",e.INR="INR",e.BTN="BTN",e.BOB="BOB",e.BOV="BOV",e.BAM="BAM",e.BWP="BWP",e.NOK="NOK",e.BRL="BRL",e.BND="BND",e.BGN="BGN",e.BIF="BIF",e.CVE="CVE",e.KHR="KHR",e.XAF="XAF",e.CAD="CAD",e.KYD="KYD",e.CLP="CLP",e.CLF="CLF",e.CNY="CNY",e.COP="COP",e.COU="COU",e.KMF="KMF",e.CDF="CDF",e.NZD="NZD",e.CRC="CRC",e.HRK="HRK",e.CUP="CUP",e.CUC="CUC",e.ANG="ANG",e.CZK="CZK",e.DKK="DKK",e.DJF="DJF",e.DOP="DOP",e.EGP="EGP",e.SVC="SVC",e.ERN="ERN",e.SZL="SZL",e.ETB="ETB",e.FKP="FKP",e.FJD="FJD",e.XPF="XPF",e.GMD="GMD",e.GEL="GEL",e.GHS="GHS",e.GIP="GIP",e.GTQ="GTQ",e.GBP="GBP",e.GNF="GNF",e.GYD="GYD",e.HTG="HTG",e.HNL="HNL",e.HKD="HKD",e.HUF="HUF",e.ISK="ISK",e.IDR="IDR",e.XDR="XDR",e.IRR="IRR",e.IQD="IQD",e.ILS="ILS",e.JMD="JMD",e.JPY="JPY",e.JOD="JOD",e.KZT="KZT",e.KES="KES",e.KPW="KPW",e.KRW="KRW",e.KWD="KWD",e.KGS="KGS",e.LAK="LAK",e.LBP="LBP",e.LSL="LSL",e.ZAR="ZAR",e.LRD="LRD",e.LYD="LYD",e.CHF="CHF",e.MOP="MOP",e.MKD="MKD",e.MGA="MGA",e.MWK="MWK",e.MYR="MYR",e.MVR="MVR",e.MRU="MRU",e.MUR="MUR",e.XUA="XUA",e.MXN="MXN",e.MXV="MXV",e.MDL="MDL",e.MNT="MNT",e.MAD="MAD",e.MZN="MZN",e.MMK="MMK",e.NAD="NAD",e.NPR="NPR",e.NIO="NIO",e.NGN="NGN",e.OMR="OMR",e.PKR="PKR",e.PAB="PAB",e.PGK="PGK",e.PYG="PYG",e.PEN="PEN",e.PHP="PHP",e.PLN="PLN",e.QAR="QAR",e.RON="RON",e.RUB="RUB",e.RWF="RWF",e.SHP="SHP",e.WST="WST",e.STN="STN",e.SAR="SAR",e.RSD="RSD",e.SCR="SCR",e.SLL="SLL",e.SGD="SGD",e.XSU="XSU",e.SBD="SBD",e.SOS="SOS",e.SSP="SSP",e.LKR="LKR",e.SDG="SDG",e.SRD="SRD",e.SEK="SEK",e.CHE="CHE",e.CHW="CHW",e.SYP="SYP",e.TWD="TWD",e.TJS="TJS",e.TZS="TZS",e.THB="THB",e.TOP="TOP",e.TTD="TTD",e.TND="TND",e.TRY="TRY",e.TMT="TMT",e.UGX="UGX",e.UAH="UAH",e.AED="AED",e.USN="USN",e.UYU="UYU",e.UYI="UYI",e.UYW="UYW",e.UZS="UZS",e.VUV="VUV",e.VES="VES",e.VND="VND",e.YER="YER",e.ZMW="ZMW",e.ZWL="ZWL",e.XBA="XBA",e.XBB="XBB",e.XBC="XBC",e.XBD="XBD",e.XTS="XTS",e.XXX="XXX",e.XAU="XAU",e.XPD="XPD",e.XPT="XPT",e.XAG="XAG",e.AFA="AFA",e.FIM="FIM",e.ALK="ALK",e.ADP="ADP",e.ESP="ESP",e.FRF="FRF",e.AOK="AOK",e.AON="AON",e.AOR="AOR",e.ARA="ARA",e.ARP="ARP",e.ARY="ARY",e.RUR="RUR",e.ATS="ATS",e.AYM="AYM",e.AZM="AZM",e.BYB="BYB",e.BYR="BYR",e.BEC="BEC",e.BEF="BEF",e.BEL="BEL",e.BOP="BOP",e.BAD="BAD",e.BRB="BRB",e.BRC="BRC",e.BRE="BRE",e.BRN="BRN",e.BRR="BRR",e.BGJ="BGJ",e.BGK="BGK",e.BGL="BGL",e.BUK="BUK",e.HRD="HRD",e.CYP="CYP",e.CSJ="CSJ",e.CSK="CSK",e.ECS="ECS",e.ECV="ECV",e.GQE="GQE",e.EEK="EEK",e.XEU="XEU",e.GEK="GEK",e.DDM="DDM",e.DEM="DEM",e.GHC="GHC",e.GHP="GHP",e.GRD="GRD",e.GNE="GNE",e.GNS="GNS",e.GWE="GWE",e.GWP="GWP",e.ITL="ITL",e.ISJ="ISJ",e.IEP="IEP",e.ILP="ILP",e.ILR="ILR",e.LAJ="LAJ",e.LVL="LVL",e.LVR="LVR",e.LSM="LSM",e.ZAL="ZAL",e.LTL="LTL",e.LTT="LTT",e.LUC="LUC",e.LUF="LUF",e.LUL="LUL",e.MGF="MGF",e.MVQ="MVQ",e.MLF="MLF",e.MTL="MTL",e.MTP="MTP",e.MRO="MRO",e.MXP="MXP",e.MZE="MZE",e.MZM="MZM",e.NLG="NLG",e.NIC="NIC",e.PEH="PEH",e.PEI="PEI",e.PES="PES",e.PLZ="PLZ",e.PTE="PTE",e.ROK="ROK",e.ROL="ROL",e.STD="STD",e.CSD="CSD",e.SKK="SKK",e.SIT="SIT",e.RHD="RHD",e.ESA="ESA",e.ESB="ESB",e.SDD="SDD",e.SDP="SDP",e.SRG="SRG",e.CHC="CHC",e.TJR="TJR",e.TPE="TPE",e.TRL="TRL",e.TMM="TMM",e.UGS="UGS",e.UGW="UGW",e.UAK="UAK",e.SUR="SUR",e.USS="USS",e.UYN="UYN",e.UYP="UYP",e.VEB="VEB",e.VEF="VEF",e.VNC="VNC",e.YDD="YDD",e.YUD="YUD",e.YUM="YUM",e.YUN="YUN",e.ZRN="ZRN",e.ZRZ="ZRZ",e.ZMK="ZMK",e.ZWC="ZWC",e.ZWD="ZWD",e.ZWN="ZWN",e.ZWR="ZWR",e.XFO="XFO",e.XRE="XRE",e.XFU="XFU",e))(le||{}),ce=(c=>(c.AU="AU",c.ID="ID",c.IN="IN",c.JP="JP",c.SG="SG",c.KR="KR",c.DE="DE",c.CH="CH",c.GB="GB",c.BR="BR",c.BH="BH",c.ZA="ZA",c.AE="AE",c.CA="CA",c))(ce||{}),ge=(d=>(d.ALCOHOL="ALCOHOL",d.APPAREL="APPAREL",d.AUTO="AUTO",d.BEAUTY="BEAUTY",d.EDU="EDU",d.ENTERTAIN="ENTERTAIN",d.EVENT_PLAN="EVENT_PLAN",d.FINANCE="FINANCE",d.GOVT="GOVT",d.GROCERY="GROCERY",d.HEALTH="HEALTH",d.HOTEL="HOTEL",d.NONPROFIT="NONPROFIT",d.ONLINE_GAMBLING="ONLINE_GAMBLING",d.OTC_DRUGS="OTC_DRUGS",d.OTHER="OTHER",d.PHYSICAL_GAMBLING="PHYSICAL_GAMBLING",d.PROF_SERVICES="PROF_SERVICES",d.RESTAURANT="RESTAURANT",d.RETAIL="RETAIL",d.TRAVEL="TRAVEL",d))(ge||{});var he=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(he||{}),Pe=(i=>(i.Blocked="BLOCKED",i.Limited="LIMITED",i.Available="AVAILABLE",i))(Pe||{}),be=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(be||{}),Ae=(o=>(o.Verified="verified",o.PendingSubmission="pending_submission",o.Unverified="unverified",o.Rejected="rejected",o))(Ae||{});var _e=(n=>(n.Draft="DRAFT",n.Published="PUBLISHED",n.Throttled="THROTTLED",n.Blocked="BLOCKED",n.Deprecated="DEPRECATED",n))(_e||{}),Te=(p=>(p.SignUp="SIGN_UP",p.SignIn="SIGN_IN",p.AppointmentBooking="APPOINTMENT_BOOKING",p.LeadGeneration="LEAD_GENERATION",p.ContactUs="CONTACT_US",p.CustomerSupport="CUSTOMER_SUPPORT",p.Survey="SURVEY",p.Other="OTHER",p))(Te||{});var Se=xe(require("crypto")),Fe=(r,t)=>Se.createHmac("sha256",t).update(r,"utf-8").digest("hex");var m=class{name;debug;constructor(t,s=!1){this.name=t,this.debug=s}log(...t){if(this.debug){let s=`[ ${Date.now()} ]`;this.name&&(s+=` - ${this.name}`),console.log.apply(console,[s,": ",...t])}}error(...t){let s=`[ ${Date.now()} ] - ERROR`;this.name&&(s+=` - ${this.name}`),console.error.apply(console,[s,": ",...t])}warn(...t){let s=`[ ${Date.now()} ] - WARN`;this.name&&(s+=` - ${this.name}`),console.warn.apply(console,[s,": ",...t])}info(...t){let s=`[ ${Date.now()} ] - INFO`;this.name&&(s+=` - ${this.name}`),console.info.apply(console,[s,": ",...t])}};var qe="UTILS",ye=!1,Ie=new m(qe,process.env.DEBUG==="true"||ye),Ge="graph.facebook.com",We=3e3,He=30,Le=2e4,Je=r=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!r?.accessToken)throw Ie.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},y=r=>{Je(r);let t={WA_BASE_URL:process.env.WA_BASE_URL||Ge,M4D_APP_ID:process.env.M4D_APP_ID||"",M4D_APP_SECRET:process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:r?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:r?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:r?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:parseInt(process.env.LISTENER_PORT||"")||We,MAX_RETRIES_AFTER_WAIT:parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||He,REQUEST_TIMEOUT:parseInt(process.env.REQUEST_TIMEOUT||"")||Le,DEBUG:process.env.DEBUG==="true"};return Ie.log(`Configuration loaded for App Id ${t.M4D_APP_ID}`),t};function k(r){return r!=null&&typeof r=="object"&&"error"in r&&typeof r.error=="object"&&r.error!=null&&"message"in r.error&&typeof r.error.message=="string"&&"type"in r.error&&typeof r.error.type=="string"&&"code"in r.error&&typeof r.error.code=="number"&&"fbtrace_id"in r.error&&typeof r.error.fbtrace_id=="string"&&(!("error_data"in r.error)||typeof r.error.error_data=="object"&&r.error.error_data!=null&&"messaging_product"in r.error.error_data&&r.error.error_data.messaging_product==="whatsapp"&&"details"in r.error.error_data&&typeof r.error.error_data.details=="string")&&(!("error_subcode"in r.error)||typeof r.error.error_subcode=="number")}var T=r=>{if(!r||Object.keys(r).length===0)return"";let t=new URLSearchParams;for(let[i,o]of Object.entries(r))o!==void 0&&t.append(i,String(o));let s=t.toString();return s?`?${s}`:""};var Ke="WEBHOOK",ke=!1,S=new m(Ke,process.env.DEBUG==="true"||ke),G=class{config;messageHandlers=new Map;eventHandlers=new Map;constructor(t){let s=y(t);this.config=s,S.log("WebhookHandler instantiated!")}handleVerificationRequest(t,s){let i=t.query["hub.mode"],o=t.query["hub.verify_token"],n=t.query["hub.challenge"];i==="subscribe"&&o===this.config.WEBHOOK_VERIFICATION_TOKEN?(S.log("Webhook verified successfully"),s.status(200).send(n)):(S.log("Webhook verification failed"),s.status(403).end())}async handleWebhookRequest(t,s){let i=t.body;if(i.object!=="whatsapp_business_account"){S.log("Received webhook for non-WhatsApp event"),s.status(404).end();return}for(let o of i.entry)try{let n=o.changes;for(let f of n)f.field==="messages"?await this.processMessages(f.value):await this.processEvent(f.field,f.value)}catch(n){S.log(`Error processing webhook: ${n}`)}s.status(200).end()}handleRequest(t,s){if(t.method==="GET")return this.handleVerificationRequest(t,s);if(t.method==="POST")return this.handleWebhookRequest(t,s);s.status(405).end()}async processMessages(t){let i=t.metadata.phone_number_id,o=t.messages;if(o&&o.length>0)for(let n of o){let f=n.type,l={id:n.id,from:n.from,timestamp:n.timestamp,type:n.type,phoneNumberId:i,originalData:n};switch(n.type){case"text":l.text=n.text;break;case"image":l.image=n.image;break;case"video":l.video=n.video;break;case"audio":l.audio=n.audio;break;case"document":l.document=n.document;break;case"sticker":l.sticker=n.sticker;break;case"location":l.location=n.location;break;case"contacts":l.contacts=n.contacts;break;case"interactive":l.interactive=n.interactive;break;case"button":l.button=n.button;break;case"order":l.order=n.order;break;case"system":l.system=n.system;break;default:break}if(n.context&&(l.context=n.context),n.errors&&(l.errors=n.errors),this.messageHandlers.has(f)){let p=this.messageHandlers.get(f);p&&await Promise.resolve(p(l))}if(this.messageHandlers.has("*")){let p=this.messageHandlers.get("*");p&&await Promise.resolve(p(l))}}t.statuses&&t.statuses.length>0&&await this.processEvent("statuses",t)}async processEvent(t,s){let i={field:t,value:s};if(this.eventHandlers.has(t)){let o=this.eventHandlers.get(t);o&&await Promise.resolve(o(i))}if(this.eventHandlers.has("*")){let o=this.eventHandlers.get("*");o&&await Promise.resolve(o(i))}}onMessage(t,s){this.messageHandlers.set(t,s),S.log(`Registered handler for message type: ${t}`)}onEvent(t,s){this.eventHandlers.set(t,s),S.log(`Registered handler for event field: ${t}`)}};var $e="BaseAPI",ue=!1,je=new m($e,process.env.DEBUG==="true"||ue),g=class{config;client;constructor(t,s){this.config=t,this.client=s,je.log("Initialized with HTTPSClient")}sendJson(t,s,i,o){return this.client.getJson(t,s,i,o)}sendFormData(t,s,i,o){return this.client.sendFormData(t,s,i,o)}sendUrlEncodedForm(t,s,i,o){return this.client.sendUrlEncodedForm(t,s,i,o)}};function $(r){if(!r)return"";let t="";return Array.isArray(r)?t=r.join(","):t=Object.entries(r).filter(([s,i])=>i).map(([s])=>s).join(","),t?`?fields=${t}`:""}var I=class extends g{endpoint="whatsapp_business_profile";constructor(t,s){super(t,s)}async getBusinessProfile(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${$(t)}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,s,i){let o=T({file_length:t,file_type:s,file_name:i});return this.sendJson("POST",`app/uploads/${o}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,s){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,s)}async getUploadHandle(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};var w=class extends g{endpoint="whatsapp_business_encryption";constructor(t,s){super(t,s)}async getEncryptionPublicKey(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(t){let s=new FormData;return s.append("business_public_key",t),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,s)}};var Ve="FlowAPI",Xe=!1,we=new m(Ve,process.env.DEBUG==="true"||Xe),N=class extends g{constructor(t,s){super(t,s),we.log("FlowAPI initialized")}async listFlows(t){return this.sendJson("GET",`/${t}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(t,s){let i={name:s.name,categories:s.categories,...s.endpoint_uri&&{endpoint_uri:s.endpoint_uri},...s.clone_flow_id&&{clone_flow_id:s.clone_flow_id},...s.flow_json&&{flow_json:s.flow_json},...s.publish!==void 0&&{publish:s.publish}};return this.sendJson("POST",`/${t}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async getFlow(t,s,i){let o=new URLSearchParams;s&&o.append("fields",s),i&&o.append("date_format",i);let n=o.toString()?`?${o.toString()}`:"";return this.sendJson("GET",`/${t}${n}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(t,s=!1){let i=`preview.invalidate(${s})`;return this.getFlow(t,i)}async updateFlowMetadata(t,s){let i={...s.name&&{name:s.name},...s.categories&&{categories:s.categories},...s.endpoint_uri&&{endpoint_uri:s.endpoint_uri},...s.application_id&&{application_id:s.application_id}};return this.sendJson("POST",`/${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async deleteFlow(t){return this.sendJson("DELETE",`/${t}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(t){return this.sendJson("GET",`/${t}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(t,s){let i=new FormData,o;if(s.file instanceof Buffer)o=new globalThis.Blob([s.file]),i.append("file",o);else if(typeof s.file=="object"&&!(s.file instanceof Blob))try{o=new globalThis.Blob([JSON.stringify(s.file,null,2)],{type:"application/json"}),i.append("file",o)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(s.file instanceof Blob)o=s.file,i.append("file",o);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return i.append("asset_type","FLOW_JSON"),i.append("name",s.name||"flow.json"),this.sendFormData("POST",`/${t}/assets`,this.config.REQUEST_TIMEOUT,i)}async validateFlowJson(t,s){try{let i=await this.updateFlowJson(t,{file:s}),o=!i.validation_errors||i.validation_errors.length===0;return{...i,valid:o}}catch(i){throw we.error("Error during Flow JSON validation attempt:",i),i}}async publishFlow(t){return this.sendJson("POST",`/${t}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(t){return this.sendJson("POST",`/${t}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(t,s){let i={source_waba_id:s.source_waba_id,...s.source_flow_names&&{source_flow_names:s.source_flow_names}};return this.sendJson("POST",`/${t}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}};var M=class extends g{endpoint="media";constructor(t,s){super(t,s)}async getMediaById(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,s="whatsapp"){let i=new FormData;return i.append("file",t),i.append("messaging_product",s),i.append("type",t.type),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,i)}async deleteMedia(t){return this.sendJson("DELETE",`${t}`,this.config.REQUEST_TIMEOUT,null)}async downloadMedia(t){return this.sendJson("GET",t,this.config.REQUEST_TIMEOUT,null)}};var O=class extends g{commonMethod="POST";commonEndpoint="messages";constructor(t,s){super(t,s)}bodyBuilder(t,s,i,o){let n={messaging_product:"whatsapp",recipient_type:"individual",to:i,type:t,[t]:s};return o&&(n.context={message_id:o}),n}send(t){return this.sendJson(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("audio",s,i,o)))}async contacts(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("contacts",s,i,o)))}async document(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("document",s,i,o)))}async image(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("image",s,i,o)))}async interactive(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async location(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("location",s,i,o)))}async sticker(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("sticker",s,i,o)))}async template(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("template",s,i,o)))}async text(t){let{body:s,previewUrl:i,to:o,replyMessageId:n}=t,f;return typeof s=="string"?f={body:s,preview_url:i}:f=s,this.send(JSON.stringify(this.bodyBuilder("text",f,o,n)))}async video(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("video",s,i,o)))}async status(t){let{status:s,messageId:i,typingIndicator:o}=t,n={messaging_product:"whatsapp",status:s,message_id:i,...o&&{typing_indicator:o}};return this.send(JSON.stringify(n))}async markAsRead(t){return this.status({status:"read",messageId:t.messageId})}async showTypingIndicator(t){return this.status({status:"read",messageId:t.messageId,typingIndicator:{type:"text"}})}async interactiveList(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveCtaUrl(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveLocationRequest(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveAddressMessage(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveReplyButtons(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveFlow(t){let{body:s,to:i,replyMessageId:o}=t;return s.action.parameters.flow_message_version===void 0&&(s.action.parameters.flow_message_version="3"),s.action.parameters.mode===void 0&&(s.action.parameters.mode="published"),s.action.parameters.flow_action===void 0&&(s.action.parameters.flow_action="navigate"),s.action.parameters.flow_action==="navigate"?s.action.parameters.flow_action_payload?.screen===void 0&&(s.action.parameters.flow_action_payload={...s.action.parameters.flow_action_payload,screen:"INIT"}):s.action.parameters.flow_action==="data_exchange"&&delete s.action.parameters.flow_action_payload,this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async reaction(t){let{messageId:s,emoji:i,to:o}=t,n={messaging_product:"whatsapp",recipient_type:"individual",to:o,type:"reaction",reaction:{message_id:s,emoji:i}};return this.send(JSON.stringify(n))}};var D=class extends g{endpoint="phone_numbers";constructor(t,s){super(t,s)}async getPhoneNumberById(t){let s=t?T({fields:t}):"";return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}${s}`,this.config.REQUEST_TIMEOUT,null)}async getPhoneNumbers(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async requestVerificationCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/request_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async verifyCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/verify_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};var B=class extends g{endpoint="message_qrdls";constructor(t,s){super(t,s)}async createQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async getQrCodes(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async getQrCode(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}async updateQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteQrCode(t){return this.sendJson("DELETE",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}};var U=class extends g{constructor(t,s){super(t,s)}async register(t,s){let i={messaging_product:"whatsapp",pin:t,...s&&{data_localization_region:s}};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/register`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async deregister(){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/deregister`,this.config.REQUEST_TIMEOUT,null)}};var x=class extends g{endpoint="message_templates";constructor(t,s){super(t,s)}async getTemplate(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async updateTemplate(t,s){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async getTemplates(t){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${T(t)}`,this.config.REQUEST_TIMEOUT,null)}async createTemplate(t){return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteTemplate(t){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${T(t)}`,this.config.REQUEST_TIMEOUT,null)}};var v=class extends g{constructor(t,s){super(t,s)}async setTwoStepVerificationCode(t){let s={pin:t};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}};var F=class extends g{constructor(t,s){super(t,s)}async getWabaAccount(t){let s=$(t)?.replace(/,/g,"%2C");return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}${s}`,this.config.REQUEST_TIMEOUT,null)}async getAllWabaSubscriptions(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}async updateWabaSubscription({override_callback_uri:t,verify_token:s}){let i={override_callback_uri:t,verify_token:s};return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async unsubscribeFromWaba(){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}};var Ne=require("https");var Ye="HttpsClient",Ze=!1,Qe=new m(Ye,process.env.DEBUG==="true"||Ze),W=class{agent;constructor(){this.agent=new Ne.Agent({keepAlive:!0})}clearSockets(){return this.agent.destroy(),!0}async sendRequest(t,s,i,o,n,f){let l=`https://${t}/${s}`,p=new AbortController,b=setTimeout(()=>p.abort(),n);try{let _=await fetch(l,{method:i,headers:o,body:f,signal:p.signal});return Qe.log(`${i} : ${l} - ${JSON.stringify(_)}`),clearTimeout(b),new de(_)}catch(_){throw _}}},de=class{res;respStatusCode;respHeaders;constructor(t){this.res=t,this.respStatusCode=t.status,this.respHeaders=Object.fromEntries(t.headers.entries())}statusCode(){return this.respStatusCode}headers(){return this.respHeaders}rawResponse(){return this.res}async json(){try{return await this.res.json()}catch(t){throw new Error("Failed to parse response body to JSON: "+t.message)}}};var ze="REQUESTER",Ee=!1,Ce=new m(ze,process.env.DEBUG==="true"||Ee),H=class{client;accessToken;phoneNumberId;businessAcctId;apiVersion;userAgent;host;protocol="https:";constructor(t,s,i,o,n,f){this.client=new W,this.host=t||"graph.facebook.com",this.apiVersion=s||"22",this.phoneNumberId=i,this.accessToken=o,this.businessAcctId=n,this.userAgent=f}buildHeader(t,s){let i={Authorization:`Bearer ${this.accessToken}`,"User-Agent":this.userAgent};return t!=="multipart/form-data"&&(i["Content-Type"]=t),s&&Object.assign(i,s),i}buildCAPIPath(t){return`v${this.apiVersion}.0/${t}`}async sendRequest(t,s,i,o,n="application/json",f){let l=n;o instanceof FormData?l="multipart/form-data":typeof o=="string"&&o.startsWith("<?xml")&&(l="application/xml");let p=`${this.protocol.toLowerCase()}//${this.host}/${this.buildCAPIPath(s)}`;Ce.log(`${t} : ${p} (${l})`);try{let b=await this.client.sendRequest(this.host,this.buildCAPIPath(s),t,this.buildHeader(l,f),i,t==="POST"||t==="PUT"?o:void 0);if(!b.rawResponse().ok){let _=await b.json();throw k(_)?_:{name:"MetaError",message:"Unknown error occurred",error:{message:_.message||"Unknown error occurred",type:"UnknownError",code:b.statusCode(),fbtrace_id:""}}}return b}catch(b){throw k(b)?b:{name:"MetaError",message:b instanceof Error?b.message:"Network error occurred",error:{message:b instanceof Error?b.message:"Network error occurred",type:"NetworkError",code:500,fbtrace_id:""}}}}async getJson(t,s,i,o,n){return await(await this.sendRequest(t,s,i,o,"application/json",n)).json()}async sendFormData(t,s,i,o,n){return await(await this.sendRequest(t,s,i,o,"multipart/form-data",n)).json()}async sendUrlEncodedForm(t,s,i,o,n){let f=new URLSearchParams(o).toString();return await(await this.sendRequest(t,s,i,f,"application/x-www-form-urlencoded",n)).json()}};var et="WHATSAPP",tt=!1,L=new m(et,process.env.DEBUG==="true"||tt),st="WA_SDK",J=class{config;requester;messages;templates;phoneNumber;qrCode;encryption;twoStepVerification;registration;media;waba;flow;businessProfile;static Enums=fe;constructor(t){this.config=y(t),this.requester=new H(this.config.WA_BASE_URL,this.config.CLOUD_API_VERSION,this.config.WA_PHONE_NUMBER_ID,this.config.CLOUD_API_ACCESS_TOKEN,this.config.WA_BUSINESS_ACCOUNT_ID,this.userAgent()),this.messages=new O(this.config,this.requester),this.templates=new x(this.config,this.requester),this.phoneNumber=new D(this.config,this.requester),this.qrCode=new B(this.config,this.requester),this.encryption=new w(this.config,this.requester),this.twoStepVerification=new v(this.config,this.requester),this.registration=new U(this.config,this.requester),this.media=new M(this.config,this.requester),this.waba=new F(this.config,this.requester),this.flow=new N(this.config,this.requester),this.businessProfile=new I(this.config,this.requester),L.log("WhatsApp Node.js SDK instantiated!")}userAgent(){return`${st}/0.0.1 (Node.js ${process.version})`}updateTimeout(t){return this.config.REQUEST_TIMEOUT=t,L.log(`Updated request timeout to ${t}ms`),!0}updatePhoneNumberId(t){return this.config.WA_PHONE_NUMBER_ID=t,L.log(`Updated sender phone number id to ${t}`),!0}updateAccessToken(t){return this.config.CLOUD_API_ACCESS_TOKEN=t,L.log("Updated access token"),!0}updateWabaId(t){return this.config.WA_BUSINESS_ACCOUNT_ID=t,L.log(`Updated business account id to ${t}`),!0}};var it=J;0&&(module.exports={AudioMediaTypesEnum,BusinessVerticalEnum,ButtonPositionEnum,ButtonTypesEnum,CategoryEnum,ComponentTypesEnum,ConversationTypesEnum,CurrencyCodesEnum,DataLocalizationRegionEnum,DocumentMediaTypesEnum,FlowCategoryEnum,FlowStatusEnum,HttpMethodsEnum,ImageMediaTypesEnum,InteractiveTypesEnum,LanguagesEnum,MessageTypesEnum,ParametersTypesEnum,ReferralSourceTypesEnum,RequestCodeMethodsEnum,StatusEnum,StickerMediaTypesEnum,SystemChangeTypesEnum,TemplateStatusEnum,VideoMediaTypesEnum,WabaAccountReviewStatus,WabaAccountStatus,WabaBusinessVerificationStatus,WabaConfigEnum,WabaHealthStatusCanSendMessage,WebhookHandler,WebhookTypesEnum,generateXHub256Sig,importConfig,isMetaError,objectToQueryString});
1
+ "use strict";var De=Object.create;var K=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Ue=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Re=(r,t)=>{for(var s in t)K(r,s,{get:t[s],enumerable:!0})},he=(r,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xe(t))!ve.call(r,o)&&o!==s&&K(r,o,{get:()=>t[o],enumerable:!(i=Be(t,o))||i.enumerable});return r};var Fe=(r,t,s)=>(s=r!=null?De(Ue(r)):{},he(t||!r||!r.__esModule?K(s,"default",{value:r,enumerable:!0}):s,r)),qe=r=>he(K({},"__esModule",{value:!0}),r);var at={};Re(at,{AudioMediaTypesEnum:()=>ie,BusinessVerticalEnum:()=>ge,ButtonPositionEnum:()=>Z,ButtonTypesEnum:()=>Y,CategoryEnum:()=>u,ComponentTypesEnum:()=>Q,ConversationTypesEnum:()=>z,CurrencyCodesEnum:()=>le,DataLocalizationRegionEnum:()=>ce,DocumentMediaTypesEnum:()=>se,EventField:()=>de,FlowCategoryEnum:()=>be,FlowStatusEnum:()=>Pe,HttpMethodsEnum:()=>_,ImageMediaTypesEnum:()=>te,InteractiveTypesEnum:()=>X,LanguagesEnum:()=>pe,MessageStatus:()=>Ie,MessageTypesEnum:()=>q,ParametersTypesEnum:()=>V,ReferralSourceTypesEnum:()=>ae,RequestCodeMethodsEnum:()=>ne,StatusEnum:()=>E,StickerMediaTypesEnum:()=>ee,SystemChangeTypesEnum:()=>re,TemplateStatusEnum:()=>j,VideoMediaTypesEnum:()=>C,WabaAccountReviewStatus:()=>Ae,WabaAccountStatus:()=>Te,WabaBusinessVerificationStatus:()=>Se,WabaConfigEnum:()=>A,WabaHealthStatusCanSendMessage:()=>_e,WebhookHandler:()=>G,WebhookTypesEnum:()=>oe,default:()=>rt,generateXHub256Sig:()=>ye,importConfig:()=>y,isMetaError:()=>k,objectToQueryString:()=>T});module.exports=qe(at);var fe={};Re(fe,{AudioMediaTypesEnum:()=>ie,BusinessVerticalEnum:()=>ge,ButtonPositionEnum:()=>Z,ButtonTypesEnum:()=>Y,CategoryEnum:()=>u,ComponentTypesEnum:()=>Q,ConversationTypesEnum:()=>z,CurrencyCodesEnum:()=>le,DataLocalizationRegionEnum:()=>ce,DocumentMediaTypesEnum:()=>se,HttpMethodsEnum:()=>_,ImageMediaTypesEnum:()=>te,InteractiveTypesEnum:()=>X,LanguagesEnum:()=>pe,MessageTypesEnum:()=>q,ParametersTypesEnum:()=>V,ReferralSourceTypesEnum:()=>ae,RequestCodeMethodsEnum:()=>ne,StatusEnum:()=>E,StickerMediaTypesEnum:()=>ee,SystemChangeTypesEnum:()=>re,TemplateStatusEnum:()=>j,VideoMediaTypesEnum:()=>C,WabaConfigEnum:()=>A,WebhookTypesEnum:()=>oe});var u=(i=>(i.Authentication="AUTHENTICATION",i.Marketing="MARKETING",i.Utility="UTILITY",i))(u||{}),j=(i=>(i.Approved="APPROVED",i.Pending="PENDING",i.Rejected="REJECTED",i))(j||{}),_=(o=>(o.Get="GET",o.Post="POST",o.Put="PUT",o.Delete="DELETE",o))(_||{}),q=(b=>(b.Audio="audio",b.Contacts="contacts",b.Document="document",b.Image="image",b.Interactive="interactive",b.Location="location",b.Reaction="sticker",b.Sticker="sticker",b.Template="template",b.Text="text",b.Video="video",b.Button="button",b.Order="order",b.System="system",b.Unknown="unknown",b["*"]="*",b))(q||{}),V=(m=>(m.Currency="currency",m.DateTime="date_time",m.Document="document",m.Image="image",m.Text="text",m.Video="video",m.Payload="payload",m))(V||{}),X=(n=>(n.Button="button",n.List="list",n.Product="product",n.ProductList="product_list",n.CtaUrl="cta_url",n.LocationRequest="location_request_message",n.AddressMessage="address_message",n.Flow="flow",n))(X||{}),Y=(s=>(s.QuickReply="quick_reply",s.URL="url",s))(Y||{}),Z=(i=>(i[i.First=0]="First",i[i.Second=1]="Second",i[i.Third=2]="Third",i))(Z||{}),Q=(o=>(o.Header="HEADER",o.Body="BODY",o.Button="BUTTON",o.Footer="FOOTER",o))(Q||{}),A=(l=>(l.BaseURL="WA_BASE_URL",l.AppId="M4D_APP_ID",l.Port="WA_PORT",l.AppSecret="M4D_APP_SECRET",l.PhoneNumberId="WA_PHONE_NUMBER_ID",l.BusinessAcctId="WA_BUSINESS_ACCOUNT_ID",l.APIVersion="CLOUD_API_VERSION",l.AccessToken="CLOUD_API_ACCESS_TOKEN",l.WebhookEndpoint="WEBHOOK_ENDPOINT",l.WebhookVerificationToken="WEBHOOK_VERIFICATION_TOKEN",l.ListenerPort="LISTENER_PORT",l.MaxRetriesAfterWait="MAX_RETRIES_AFTER_WAIT",l.RequestTimeout="REQUEST_TIMEOUT",l.Debug="DEBUG",l))(A||{}),z=(i=>(i.BusinessInitiated="business_initiated",i.CustomerInitiated="customer_initiated",i.ReferralConversion="referral_conversion",i))(z||{}),E=(i=>(i.Delivered="delivered",i.Read="read",i.Sent="sent",i))(E||{}),C=(s=>(s.Mp4="video/mp4",s.Threegp="video/3gp",s))(C||{}),ee=(t=>(t.Webp="image/webp",t))(ee||{}),te=(s=>(s.Jpeg="image/jpeg",s.Png="image/png",s))(te||{}),se=(n=>(n.Text="text/plain",n.Pdf="application/pdf",n.Ppt="application/vnd.ms-powerpoint",n.Word="application/msword",n.Excel="application/vnd.ms-excel",n.OpenDoc="application/vnd.openxmlformats-officedocument.wordprocessingml.document",n.OpenPres="application/vnd.openxmlformats-officedocument.presentationml.presentation",n.OpenSheet="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",n))(se||{}),ie=(p=>(p.Aac="audio/aac",p.Mp4="audio/mp4",p.Mpeg="audio/mpeg",p.Amr="audio/amr",p.Ogg="audio/ogg",p))(ie||{}),oe=(R=>(R.Audio="audio",R.Button="button",R.Document="document",R.Text="text",R.Image="image",R.Interactive="interactive",R.Order="order",R.Sticker="sticker",R.System="system",R.Unknown="unknown",R.Video="video",R))(oe||{}),re=(s=>(s.CustomerChangedNumber="customer_changed_number",s.CustomerIdentityChanged="customer_identity_changed",s))(re||{}),ae=(s=>(s.Ad="ad",s.Post="post",s))(ae||{}),ne=(s=>(s.Sms="SMS",s.Voice="VOICE",s))(ne||{}),pe=(a=>(a.Afrikaans="af",a.Albanian="sq",a.Arabic="ar",a.Azerbaijani="az",a.Bengali="bn",a.Bulgarian="bg",a.Catalan="ca",a.Chinese_CHN="zh_CN",a.Chinese_HKG="zh_HK",a.Chinese_TAI="zh_TW",a.Croatian="hr",a.Czech="cs",a.Danish="da",a.Dutch="nl",a.English="en",a.English_UK="en_GB",a.English_US="en_US",a.Estonian="et",a.Filipino="fil",a.Finnish="fi",a.French="fr",a.Georgian="ka",a.German="de",a.Greek="el",a.Gujarati="gu",a.Hausa="ha",a.Hebrew="he",a.Hindi="hi",a.Hungarian="hu",a.Indonesian="id",a.Irish="ga",a.Italian="it",a.Japanese="ja",a.Kannada="kn",a.Kazakh="kk",a.Kinyarwanda="rw_RW",a.Korean="ko",a.Kyrgyz_Kyrgyzstan="ky_KG",a.Lao="lo",a.Latvian="lv",a.Lithuanian="lt",a.Macedonian="mk",a.Malay="ms",a.Malayalam="ml",a.Marathi="mr",a.Norwegian="nb",a.Persian="fa",a.Polish="pl",a.Portuguese_BR="pt_BR",a.Portuguese_POR="pt_PT",a.Punjabi="pa",a.Romanian="ro",a.Russian="ru",a.Serbian="sr",a.Slovak="sk",a.Slovenian="sl",a.Spanish="es",a.Spanish_ARG="es_AR",a.Spanish_SPA="es_ES",a.Spanish_MEX="es_MX",a.Swahili="sw",a.Swedish="sv",a.Tamil="ta",a.Telugu="te",a.Thai="th",a.Turkish="tr",a.Ukrainian="uk",a.Urdu="ur",a.Uzbek="uz",a.Vietnamese="vi",a.Zulu="zu",a))(pe||{}),le=(e=>(e.AFN="AFN",e.EUR="EUR",e.ALL="ALL",e.DZD="DZD",e.USD="USD",e.AOA="AOA",e.XCD="XCD",e.ARS="ARS",e.AMD="AMD",e.AWG="AWG",e.AUD="AUD",e.AZN="AZN",e.BSD="BSD",e.BHD="BHD",e.BDT="BDT",e.BBD="BBD",e.BYN="BYN",e.BZD="BZD",e.XOF="XOF",e.BMD="BMD",e.INR="INR",e.BTN="BTN",e.BOB="BOB",e.BOV="BOV",e.BAM="BAM",e.BWP="BWP",e.NOK="NOK",e.BRL="BRL",e.BND="BND",e.BGN="BGN",e.BIF="BIF",e.CVE="CVE",e.KHR="KHR",e.XAF="XAF",e.CAD="CAD",e.KYD="KYD",e.CLP="CLP",e.CLF="CLF",e.CNY="CNY",e.COP="COP",e.COU="COU",e.KMF="KMF",e.CDF="CDF",e.NZD="NZD",e.CRC="CRC",e.HRK="HRK",e.CUP="CUP",e.CUC="CUC",e.ANG="ANG",e.CZK="CZK",e.DKK="DKK",e.DJF="DJF",e.DOP="DOP",e.EGP="EGP",e.SVC="SVC",e.ERN="ERN",e.SZL="SZL",e.ETB="ETB",e.FKP="FKP",e.FJD="FJD",e.XPF="XPF",e.GMD="GMD",e.GEL="GEL",e.GHS="GHS",e.GIP="GIP",e.GTQ="GTQ",e.GBP="GBP",e.GNF="GNF",e.GYD="GYD",e.HTG="HTG",e.HNL="HNL",e.HKD="HKD",e.HUF="HUF",e.ISK="ISK",e.IDR="IDR",e.XDR="XDR",e.IRR="IRR",e.IQD="IQD",e.ILS="ILS",e.JMD="JMD",e.JPY="JPY",e.JOD="JOD",e.KZT="KZT",e.KES="KES",e.KPW="KPW",e.KRW="KRW",e.KWD="KWD",e.KGS="KGS",e.LAK="LAK",e.LBP="LBP",e.LSL="LSL",e.ZAR="ZAR",e.LRD="LRD",e.LYD="LYD",e.CHF="CHF",e.MOP="MOP",e.MKD="MKD",e.MGA="MGA",e.MWK="MWK",e.MYR="MYR",e.MVR="MVR",e.MRU="MRU",e.MUR="MUR",e.XUA="XUA",e.MXN="MXN",e.MXV="MXV",e.MDL="MDL",e.MNT="MNT",e.MAD="MAD",e.MZN="MZN",e.MMK="MMK",e.NAD="NAD",e.NPR="NPR",e.NIO="NIO",e.NGN="NGN",e.OMR="OMR",e.PKR="PKR",e.PAB="PAB",e.PGK="PGK",e.PYG="PYG",e.PEN="PEN",e.PHP="PHP",e.PLN="PLN",e.QAR="QAR",e.RON="RON",e.RUB="RUB",e.RWF="RWF",e.SHP="SHP",e.WST="WST",e.STN="STN",e.SAR="SAR",e.RSD="RSD",e.SCR="SCR",e.SLL="SLL",e.SGD="SGD",e.XSU="XSU",e.SBD="SBD",e.SOS="SOS",e.SSP="SSP",e.LKR="LKR",e.SDG="SDG",e.SRD="SRD",e.SEK="SEK",e.CHE="CHE",e.CHW="CHW",e.SYP="SYP",e.TWD="TWD",e.TJS="TJS",e.TZS="TZS",e.THB="THB",e.TOP="TOP",e.TTD="TTD",e.TND="TND",e.TRY="TRY",e.TMT="TMT",e.UGX="UGX",e.UAH="UAH",e.AED="AED",e.USN="USN",e.UYU="UYU",e.UYI="UYI",e.UYW="UYW",e.UZS="UZS",e.VUV="VUV",e.VES="VES",e.VND="VND",e.YER="YER",e.ZMW="ZMW",e.ZWL="ZWL",e.XBA="XBA",e.XBB="XBB",e.XBC="XBC",e.XBD="XBD",e.XTS="XTS",e.XXX="XXX",e.XAU="XAU",e.XPD="XPD",e.XPT="XPT",e.XAG="XAG",e.AFA="AFA",e.FIM="FIM",e.ALK="ALK",e.ADP="ADP",e.ESP="ESP",e.FRF="FRF",e.AOK="AOK",e.AON="AON",e.AOR="AOR",e.ARA="ARA",e.ARP="ARP",e.ARY="ARY",e.RUR="RUR",e.ATS="ATS",e.AYM="AYM",e.AZM="AZM",e.BYB="BYB",e.BYR="BYR",e.BEC="BEC",e.BEF="BEF",e.BEL="BEL",e.BOP="BOP",e.BAD="BAD",e.BRB="BRB",e.BRC="BRC",e.BRE="BRE",e.BRN="BRN",e.BRR="BRR",e.BGJ="BGJ",e.BGK="BGK",e.BGL="BGL",e.BUK="BUK",e.HRD="HRD",e.CYP="CYP",e.CSJ="CSJ",e.CSK="CSK",e.ECS="ECS",e.ECV="ECV",e.GQE="GQE",e.EEK="EEK",e.XEU="XEU",e.GEK="GEK",e.DDM="DDM",e.DEM="DEM",e.GHC="GHC",e.GHP="GHP",e.GRD="GRD",e.GNE="GNE",e.GNS="GNS",e.GWE="GWE",e.GWP="GWP",e.ITL="ITL",e.ISJ="ISJ",e.IEP="IEP",e.ILP="ILP",e.ILR="ILR",e.LAJ="LAJ",e.LVL="LVL",e.LVR="LVR",e.LSM="LSM",e.ZAL="ZAL",e.LTL="LTL",e.LTT="LTT",e.LUC="LUC",e.LUF="LUF",e.LUL="LUL",e.MGF="MGF",e.MVQ="MVQ",e.MLF="MLF",e.MTL="MTL",e.MTP="MTP",e.MRO="MRO",e.MXP="MXP",e.MZE="MZE",e.MZM="MZM",e.NLG="NLG",e.NIC="NIC",e.PEH="PEH",e.PEI="PEI",e.PES="PES",e.PLZ="PLZ",e.PTE="PTE",e.ROK="ROK",e.ROL="ROL",e.STD="STD",e.CSD="CSD",e.SKK="SKK",e.SIT="SIT",e.RHD="RHD",e.ESA="ESA",e.ESB="ESB",e.SDD="SDD",e.SDP="SDP",e.SRG="SRG",e.CHC="CHC",e.TJR="TJR",e.TPE="TPE",e.TRL="TRL",e.TMM="TMM",e.UGS="UGS",e.UGW="UGW",e.UAK="UAK",e.SUR="SUR",e.USS="USS",e.UYN="UYN",e.UYP="UYP",e.VEB="VEB",e.VEF="VEF",e.VNC="VNC",e.YDD="YDD",e.YUD="YUD",e.YUM="YUM",e.YUN="YUN",e.ZRN="ZRN",e.ZRZ="ZRZ",e.ZMK="ZMK",e.ZWC="ZWC",e.ZWD="ZWD",e.ZWN="ZWN",e.ZWR="ZWR",e.XFO="XFO",e.XRE="XRE",e.XFU="XFU",e))(le||{}),ce=(l=>(l.AU="AU",l.ID="ID",l.IN="IN",l.JP="JP",l.SG="SG",l.KR="KR",l.DE="DE",l.CH="CH",l.GB="GB",l.BR="BR",l.BH="BH",l.ZA="ZA",l.AE="AE",l.CA="CA",l))(ce||{}),ge=(d=>(d.ALCOHOL="ALCOHOL",d.APPAREL="APPAREL",d.AUTO="AUTO",d.BEAUTY="BEAUTY",d.EDU="EDU",d.ENTERTAIN="ENTERTAIN",d.EVENT_PLAN="EVENT_PLAN",d.FINANCE="FINANCE",d.GOVT="GOVT",d.GROCERY="GROCERY",d.HEALTH="HEALTH",d.HOTEL="HOTEL",d.NONPROFIT="NONPROFIT",d.ONLINE_GAMBLING="ONLINE_GAMBLING",d.OTC_DRUGS="OTC_DRUGS",d.OTHER="OTHER",d.PHYSICAL_GAMBLING="PHYSICAL_GAMBLING",d.PROF_SERVICES="PROF_SERVICES",d.RESTAURANT="RESTAURANT",d.RETAIL="RETAIL",d.TRAVEL="TRAVEL",d))(ge||{});var Pe=(p=>(p.Draft="DRAFT",p.Published="PUBLISHED",p.Throttled="THROTTLED",p.Blocked="BLOCKED",p.Deprecated="DEPRECATED",p))(Pe||{}),be=(n=>(n.SignUp="SIGN_UP",n.SignIn="SIGN_IN",n.AppointmentBooking="APPOINTMENT_BOOKING",n.LeadGeneration="LEAD_GENERATION",n.ContactUs="CONTACT_US",n.CustomerSupport="CUSTOMER_SUPPORT",n.Survey="SURVEY",n.Other="OTHER",n))(be||{});var Ae=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(Ae||{}),_e=(i=>(i.Blocked="BLOCKED",i.Limited="LIMITED",i.Available="AVAILABLE",i))(_e||{}),Te=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(Te||{}),Se=(o=>(o.Verified="verified",o.PendingSubmission="pending_submission",o.Unverified="unverified",o.Rejected="rejected",o))(Se||{});var Ie=(i=>(i.DELIVERED="delivered",i.READ="read",i.SENT="sent",i))(Ie||{}),de=(c=>(c.MESSAGES="messages",c.STATUSES="statuses",c.MESSAGE_TEMPLATE_STATUS_UPDATE="message_template_status_update",c.PHONE_NUMBER_QUALITY_UPDATE="phone_number_quality_update",c.PHONE_NUMBER_NAME_UPDATE="phone_number_name_update",c.UNKNOWN="unknown",c))(de||{});var we=Fe(require("crypto")),ye=(r,t)=>we.createHmac("sha256",t).update(r,"utf-8").digest("hex");var h=class{name;debug;constructor(t,s=!1){this.name=t,this.debug=s}log(...t){if(this.debug){let s=`[ ${Date.now()} ]`;this.name&&(s+=` - ${this.name}`),console.log.apply(console,[s,": ",...t])}}error(...t){let s=`[ ${Date.now()} ] - ERROR`;this.name&&(s+=` - ${this.name}`),console.error.apply(console,[s,": ",...t])}warn(...t){let s=`[ ${Date.now()} ] - WARN`;this.name&&(s+=` - ${this.name}`),console.warn.apply(console,[s,": ",...t])}info(...t){let s=`[ ${Date.now()} ] - INFO`;this.name&&(s+=` - ${this.name}`),console.info.apply(console,[s,": ",...t])}};var Ge="UTILS",We=!1,Ne=new h(Ge,process.env.DEBUG==="true"||We),He="graph.facebook.com",Le=3e3,Je=30,Ke=2e4,ke=r=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!r?.accessToken)throw Ne.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},y=r=>{ke(r);let t={WA_BASE_URL:process.env.WA_BASE_URL||He,M4D_APP_ID:process.env.M4D_APP_ID||"",M4D_APP_SECRET:process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:r?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:r?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:r?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:parseInt(process.env.LISTENER_PORT||"")||Le,MAX_RETRIES_AFTER_WAIT:parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||Je,REQUEST_TIMEOUT:parseInt(process.env.REQUEST_TIMEOUT||"")||Ke,DEBUG:process.env.DEBUG==="true"};return Ne.log(`Configuration loaded for App Id ${t.M4D_APP_ID}`),t};function k(r){return r!=null&&typeof r=="object"&&"error"in r&&typeof r.error=="object"&&r.error!=null&&"message"in r.error&&typeof r.error.message=="string"&&"type"in r.error&&typeof r.error.type=="string"&&"code"in r.error&&typeof r.error.code=="number"&&"fbtrace_id"in r.error&&typeof r.error.fbtrace_id=="string"&&(!("error_data"in r.error)||typeof r.error.error_data=="object"&&r.error.error_data!=null&&"messaging_product"in r.error.error_data&&r.error.error_data.messaging_product==="whatsapp"&&"details"in r.error.error_data&&typeof r.error.error_data.details=="string")&&(!("error_subcode"in r.error)||typeof r.error.error_subcode=="number")}var T=r=>{if(!r||Object.keys(r).length===0)return"";let t=new URLSearchParams;for(let[i,o]of Object.entries(r))o!==void 0&&t.append(i,String(o));let s=t.toString();return s?`?${s}`:""};var $e="WEBHOOK",ue=!1,S=new h($e,process.env.DEBUG==="true"||ue),G=class{config;messageHandlers=new Map;eventHandlers=new Map;constructor(t){let s=y(t);this.config=s,S.log("WebhookHandler instantiated!")}handleVerificationRequest(t,s){let i=t.query["hub.mode"],o=t.query["hub.verify_token"],p=t.query["hub.challenge"];i==="subscribe"&&o===this.config.WEBHOOK_VERIFICATION_TOKEN?(S.log("Webhook verified successfully"),s.status(200).send(p)):(S.log("Webhook verification failed"),s.status(403).end())}async handleWebhookRequest(t,s){let i=t.body;if(i.object!=="whatsapp_business_account"){S.log("Received webhook for non-WhatsApp event"),s.status(404).end();return}for(let o of i.entry)try{let p=o.changes;for(let c of p)c.field==="messages"?await this.processMessages(c.value):await this.processEvent(c.field,c.value)}catch(p){S.log(`Error processing webhook: ${p}`)}s.status(200).end()}handleRequest(t,s){if(t.method==="GET")return this.handleVerificationRequest(t,s);if(t.method==="POST")return this.handleWebhookRequest(t,s);s.status(405).end()}async processMessages(t){let s=t.metadata,i=t.contacts,o=s.display_phone_number,p=s.phone_number_id,c=i.profile.name,m=t.messages;if(m&&m.length>0)for(let n of m){let P=n.type,f={id:n.id,from:n.from,timestamp:n.timestamp,type:n.type,phoneNumberId:p,displayPhoneNumber:o,profileName:c,originalData:n};switch(n.type){case"text":f.text=n.text;break;case"image":f.image=n.image;break;case"video":f.video=n.video;break;case"audio":f.audio=n.audio;break;case"document":f.document=n.document;break;case"sticker":f.sticker=n.sticker;break;case"location":f.location=n.location;break;case"contacts":f.contacts=n.contacts;break;case"interactive":f.interactive=n.interactive;break;case"button":f.button=n.button;break;case"order":f.order=n.order;break;case"system":f.system=n.system;break;default:break}if(n.context&&(f.context=n.context),n.errors&&(f.errors=n.errors),this.messageHandlers.has(P)){let R=this.messageHandlers.get(P);R&&await Promise.resolve(R(f))}if(this.messageHandlers.has("*")){let R=this.messageHandlers.get("*");R&&await Promise.resolve(R(f))}}t.statuses&&t.statuses.length>0&&await this.processEvent("statuses",t)}async processEvent(t,s){let i={field:t,value:s};if(this.eventHandlers.has(t)){let o=this.eventHandlers.get(t);o&&await Promise.resolve(o(i))}if(this.eventHandlers.has("*")){let o=this.eventHandlers.get("*");o&&await Promise.resolve(o(i))}}onMessage(t,s){this.messageHandlers.set(t,s),S.log(`Registered handler for message type: ${t}`)}onEvent(t,s){this.eventHandlers.set(t,s),S.log(`Registered handler for event field: ${t}`)}};var je="BaseAPI",Ve=!1,Xe=new h(je,process.env.DEBUG==="true"||Ve),g=class{config;client;constructor(t,s){this.config=t,this.client=s,Xe.log("Initialized with HTTPSClient")}sendJson(t,s,i,o){return this.client.getJson(t,s,i,o)}sendFormData(t,s,i,o){return this.client.sendFormData(t,s,i,o)}sendUrlEncodedForm(t,s,i,o){return this.client.sendUrlEncodedForm(t,s,i,o)}};function $(r){if(!r)return"";let t="";return Array.isArray(r)?t=r.join(","):t=Object.entries(r).filter(([s,i])=>i).map(([s])=>s).join(","),t?`?fields=${t}`:""}var I=class extends g{endpoint="whatsapp_business_profile";constructor(t,s){super(t,s)}async getBusinessProfile(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${$(t)}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,s,i){let o=T({file_length:t,file_type:s,file_name:i});return this.sendJson("POST",`app/uploads/${o}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,s){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,s)}async getUploadHandle(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};var w=class extends g{endpoint="whatsapp_business_encryption";constructor(t,s){super(t,s)}async getEncryptionPublicKey(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(t){let s=new FormData;return s.append("business_public_key",t),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,s)}};var Ye="FlowAPI",Ze=!1,Me=new h(Ye,process.env.DEBUG==="true"||Ze),N=class extends g{constructor(t,s){super(t,s),Me.log("FlowAPI initialized")}async listFlows(t){return this.sendJson("GET",`/${t}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(t,s){let i={name:s.name,categories:s.categories,...s.endpoint_uri&&{endpoint_uri:s.endpoint_uri},...s.clone_flow_id&&{clone_flow_id:s.clone_flow_id},...s.flow_json&&{flow_json:s.flow_json},...s.publish!==void 0&&{publish:s.publish}};return this.sendJson("POST",`/${t}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async getFlow(t,s,i){let o=new URLSearchParams;s&&o.append("fields",s),i&&o.append("date_format",i);let p=o.toString()?`?${o.toString()}`:"";return this.sendJson("GET",`/${t}${p}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(t,s=!1){let i=`preview.invalidate(${s})`;return this.getFlow(t,i)}async updateFlowMetadata(t,s){let i={...s.name&&{name:s.name},...s.categories&&{categories:s.categories},...s.endpoint_uri&&{endpoint_uri:s.endpoint_uri},...s.application_id&&{application_id:s.application_id}};return this.sendJson("POST",`/${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async deleteFlow(t){return this.sendJson("DELETE",`/${t}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(t){return this.sendJson("GET",`/${t}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(t,s){let i=new FormData,o;if(s.file instanceof Buffer)o=new globalThis.Blob([s.file]),i.append("file",o);else if(typeof s.file=="object"&&!(s.file instanceof Blob))try{o=new globalThis.Blob([JSON.stringify(s.file,null,2)],{type:"application/json"}),i.append("file",o)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(s.file instanceof Blob)o=s.file,i.append("file",o);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return i.append("asset_type","FLOW_JSON"),i.append("name",s.name||"flow.json"),this.sendFormData("POST",`/${t}/assets`,this.config.REQUEST_TIMEOUT,i)}async validateFlowJson(t,s){try{let i=await this.updateFlowJson(t,{file:s}),o=!i.validation_errors||i.validation_errors.length===0;return{...i,valid:o}}catch(i){throw Me.error("Error during Flow JSON validation attempt:",i),i}}async publishFlow(t){return this.sendJson("POST",`/${t}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(t){return this.sendJson("POST",`/${t}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(t,s){let i={source_waba_id:s.source_waba_id,...s.source_flow_names&&{source_flow_names:s.source_flow_names}};return this.sendJson("POST",`/${t}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}};var M=class extends g{endpoint="media";constructor(t,s){super(t,s)}async getMediaById(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,s="whatsapp"){let i=new FormData;return i.append("file",t),i.append("messaging_product",s),i.append("type",t.type),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,i)}async deleteMedia(t){return this.sendJson("DELETE",`${t}`,this.config.REQUEST_TIMEOUT,null)}async downloadMedia(t){return this.sendJson("GET",t,this.config.REQUEST_TIMEOUT,null)}};var O=class extends g{commonMethod="POST";commonEndpoint="messages";constructor(t,s){super(t,s)}bodyBuilder(t,s,i,o){let p={messaging_product:"whatsapp",recipient_type:"individual",to:i,type:t,[t]:s};return o&&(p.context={message_id:o}),p}send(t){return this.sendJson(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("audio",s,i,o)))}async contacts(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("contacts",s,i,o)))}async document(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("document",s,i,o)))}async image(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("image",s,i,o)))}async interactive(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async location(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("location",s,i,o)))}async sticker(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("sticker",s,i,o)))}async template(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("template",s,i,o)))}async text(t){let{body:s,previewUrl:i,to:o,replyMessageId:p}=t,c;return typeof s=="string"?c={body:s,preview_url:i}:c=s,this.send(JSON.stringify(this.bodyBuilder("text",c,o,p)))}async video(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("video",s,i,o)))}async status(t){let{status:s,messageId:i,typingIndicator:o}=t,p={messaging_product:"whatsapp",status:s,message_id:i,...o&&{typing_indicator:o}};return this.send(JSON.stringify(p))}async markAsRead(t){return this.status({status:"read",messageId:t.messageId})}async showTypingIndicator(t){return this.status({status:"read",messageId:t.messageId,typingIndicator:{type:"text"}})}async interactiveList(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveCtaUrl(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveLocationRequest(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveAddressMessage(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveReplyButtons(t){let{body:s,to:i,replyMessageId:o}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async interactiveFlow(t){let{body:s,to:i,replyMessageId:o}=t;return s.action.parameters.flow_message_version===void 0&&(s.action.parameters.flow_message_version="3"),s.action.parameters.mode===void 0&&(s.action.parameters.mode="published"),s.action.parameters.flow_action===void 0&&(s.action.parameters.flow_action="navigate"),s.action.parameters.flow_action==="navigate"?s.action.parameters.flow_action_payload?.screen===void 0&&(s.action.parameters.flow_action_payload={...s.action.parameters.flow_action_payload,screen:"INIT"}):s.action.parameters.flow_action==="data_exchange"&&delete s.action.parameters.flow_action_payload,this.send(JSON.stringify(this.bodyBuilder("interactive",s,i,o)))}async reaction(t){let{messageId:s,emoji:i,to:o}=t,p={messaging_product:"whatsapp",recipient_type:"individual",to:o,type:"reaction",reaction:{message_id:s,emoji:i}};return this.send(JSON.stringify(p))}};var D=class extends g{endpoint="phone_numbers";constructor(t,s){super(t,s)}async getPhoneNumberById(t){let s=t?T({fields:t}):"";return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}${s}`,this.config.REQUEST_TIMEOUT,null)}async getPhoneNumbers(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async requestVerificationCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/request_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async verifyCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/verify_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};var B=class extends g{endpoint="message_qrdls";constructor(t,s){super(t,s)}async createQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async getQrCodes(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async getQrCode(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}async updateQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteQrCode(t){return this.sendJson("DELETE",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}};var x=class extends g{constructor(t,s){super(t,s)}async register(t,s){let i={messaging_product:"whatsapp",pin:t,...s&&{data_localization_region:s}};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/register`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async deregister(){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/deregister`,this.config.REQUEST_TIMEOUT,null)}};var U=class extends g{endpoint="message_templates";constructor(t,s){super(t,s)}async getTemplate(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async updateTemplate(t,s){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async getTemplates(t){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${T(t)}`,this.config.REQUEST_TIMEOUT,null)}async createTemplate(t){return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteTemplate(t){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${T(t)}`,this.config.REQUEST_TIMEOUT,null)}};var v=class extends g{constructor(t,s){super(t,s)}async setTwoStepVerificationCode(t){let s={pin:t};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}};var F=class extends g{constructor(t,s){super(t,s)}async getWabaAccount(t){let s=$(t)?.replace(/,/g,"%2C");return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}${s}`,this.config.REQUEST_TIMEOUT,null)}async getAllWabaSubscriptions(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}async updateWabaSubscription({override_callback_uri:t,verify_token:s}){let i={override_callback_uri:t,verify_token:s};return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,JSON.stringify(i))}async unsubscribeFromWaba(){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}};var Oe=require("https");var Qe="HttpsClient",ze=!1,Ee=new h(Qe,process.env.DEBUG==="true"||ze),W=class{agent;constructor(){this.agent=new Oe.Agent({keepAlive:!0})}clearSockets(){return this.agent.destroy(),!0}async sendRequest(t,s,i,o,p,c){let m=`https://${t}/${s}`,n=new AbortController,P=setTimeout(()=>n.abort(),p);try{let f=await fetch(m,{method:i,headers:o,body:c,signal:n.signal});return Ee.log(`${i} : ${m} - ${JSON.stringify(f)}`),clearTimeout(P),new me(f)}catch(f){throw f}}},me=class{res;respStatusCode;respHeaders;constructor(t){this.res=t,this.respStatusCode=t.status,this.respHeaders=Object.fromEntries(t.headers.entries())}statusCode(){return this.respStatusCode}headers(){return this.respHeaders}rawResponse(){return this.res}async json(){try{return await this.res.json()}catch(t){throw new Error("Failed to parse response body to JSON: "+t.message)}}};var Ce="REQUESTER",et=!1,tt=new h(Ce,process.env.DEBUG==="true"||et),H=class{client;accessToken;phoneNumberId;businessAcctId;apiVersion;userAgent;host;protocol="https:";constructor(t,s,i,o,p,c){this.client=new W,this.host=t||"graph.facebook.com",this.apiVersion=s||"22",this.phoneNumberId=i,this.accessToken=o,this.businessAcctId=p,this.userAgent=c}buildHeader(t,s){let i={Authorization:`Bearer ${this.accessToken}`,"User-Agent":this.userAgent};return t!=="multipart/form-data"&&(i["Content-Type"]=t),s&&Object.assign(i,s),i}buildCAPIPath(t){return`v${this.apiVersion}.0/${t}`}async sendRequest(t,s,i,o,p="application/json",c){let m=p;o instanceof FormData?m="multipart/form-data":typeof o=="string"&&o.startsWith("<?xml")&&(m="application/xml");let n=`${this.protocol.toLowerCase()}//${this.host}/${this.buildCAPIPath(s)}`;tt.log(`${t} : ${n} (${m})`);try{let P=await this.client.sendRequest(this.host,this.buildCAPIPath(s),t,this.buildHeader(m,c),i,t==="POST"||t==="PUT"?o:void 0);if(!P.rawResponse().ok){let f=await P.json();throw k(f)?f:{name:"MetaError",message:"Unknown error occurred",error:{message:f.message||"Unknown error occurred",type:"UnknownError",code:P.statusCode(),fbtrace_id:""}}}return P}catch(P){throw k(P)?P:{name:"MetaError",message:P instanceof Error?P.message:"Network error occurred",error:{message:P instanceof Error?P.message:"Network error occurred",type:"NetworkError",code:500,fbtrace_id:""}}}}async getJson(t,s,i,o,p){return await(await this.sendRequest(t,s,i,o,"application/json",p)).json()}async sendFormData(t,s,i,o,p){return await(await this.sendRequest(t,s,i,o,"multipart/form-data",p)).json()}async sendUrlEncodedForm(t,s,i,o,p){let c=new URLSearchParams(o).toString();return await(await this.sendRequest(t,s,i,c,"application/x-www-form-urlencoded",p)).json()}};var st="WHATSAPP",it=!1,L=new h(st,process.env.DEBUG==="true"||it),ot="WA_SDK",J=class{config;requester;messages;templates;phoneNumber;qrCode;encryption;twoStepVerification;registration;media;waba;flow;businessProfile;static Enums=fe;constructor(t){this.config=y(t),this.requester=new H(this.config.WA_BASE_URL,this.config.CLOUD_API_VERSION,this.config.WA_PHONE_NUMBER_ID,this.config.CLOUD_API_ACCESS_TOKEN,this.config.WA_BUSINESS_ACCOUNT_ID,this.userAgent()),this.messages=new O(this.config,this.requester),this.templates=new U(this.config,this.requester),this.phoneNumber=new D(this.config,this.requester),this.qrCode=new B(this.config,this.requester),this.encryption=new w(this.config,this.requester),this.twoStepVerification=new v(this.config,this.requester),this.registration=new x(this.config,this.requester),this.media=new M(this.config,this.requester),this.waba=new F(this.config,this.requester),this.flow=new N(this.config,this.requester),this.businessProfile=new I(this.config,this.requester),L.log("WhatsApp Node.js SDK instantiated!")}userAgent(){return`${ot}/0.0.1 (Node.js ${process.version})`}updateTimeout(t){return this.config.REQUEST_TIMEOUT=t,L.log(`Updated request timeout to ${t}ms`),!0}updatePhoneNumberId(t){return this.config.WA_PHONE_NUMBER_ID=t,L.log(`Updated sender phone number id to ${t}`),!0}updateAccessToken(t){return this.config.CLOUD_API_ACCESS_TOKEN=t,L.log("Updated access token"),!0}updateWabaId(t){return this.config.WA_BUSINESS_ACCOUNT_ID=t,L.log(`Updated business account id to ${t}`),!0}};var rt=J;0&&(module.exports={AudioMediaTypesEnum,BusinessVerticalEnum,ButtonPositionEnum,ButtonTypesEnum,CategoryEnum,ComponentTypesEnum,ConversationTypesEnum,CurrencyCodesEnum,DataLocalizationRegionEnum,DocumentMediaTypesEnum,EventField,FlowCategoryEnum,FlowStatusEnum,HttpMethodsEnum,ImageMediaTypesEnum,InteractiveTypesEnum,LanguagesEnum,MessageStatus,MessageTypesEnum,ParametersTypesEnum,ReferralSourceTypesEnum,RequestCodeMethodsEnum,StatusEnum,StickerMediaTypesEnum,SystemChangeTypesEnum,TemplateStatusEnum,VideoMediaTypesEnum,WabaAccountReviewStatus,WabaAccountStatus,WabaBusinessVerificationStatus,WabaConfigEnum,WabaHealthStatusCanSendMessage,WebhookHandler,WebhookTypesEnum,generateXHub256Sig,importConfig,isMetaError,objectToQueryString});
2
2
  //# sourceMappingURL=index.js.map