meta-cloud-api 2.3.0 → 2.4.0
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.ts +42 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,5 +17,5 @@ Your key format is not recognized. Please ensure it is in PKCS#8 format.`),Error
|
|
|
17
17
|
██║ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██╔══██║ ██╔═══╝ ██║
|
|
18
18
|
╚██████╗ ███████╗ ╚██████╔╝ ╚██████╔╝ ██████╔╝ ██║ ██║ ██║ ██║
|
|
19
19
|
╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
20
|
-
`)}function Bt(){try{let e=o(__dirname,`../../package.json`);return JSON.parse(a(e,`utf-8`)).version}catch{return`unknown`}}function Vt(){return`WhatsApp-Nodejs-SDK/${Bt()} (Node.js ${process.version})`}const K=new k(`WHATSAPP`,process.env.DEBUG===`true`);var Ht=class{config;requester;blockUsers;calling;commerce;groups;marketingMessages;messages;media;payments;phoneNumbers;twoStepVerification;flows;businessProfile;templates;encryption;qrCode;registration;waba;constructor(e){zt(),this.config=Ge(e),this.requester=new Rt(this.config[v.APIVersion],this.config[v.PhoneNumberId],this.config[v.AccessToken],this.config[v.BusinessAcctId],this.getUserAgent()),this.blockUsers=new me(this.config,this.requester),this.calling=new he(this.config,this.requester),this.commerce=new ge(this.config,this.requester),this.groups=new xe(this.config,this.requester),this.marketingMessages=new Se(this.config,this.requester),this.messages=new C(this.config,this.requester),this.media=new Ce(this.config,this.requester),this.payments=new we(this.config,this.requester),this.phoneNumbers=new Te(this.config,this.requester),this.twoStepVerification=new Ve(this.config,this.requester),this.flows=new ve(this.config,this.requester),this.businessProfile=new Ee(this.config,this.requester),this.templates=new Be(this.config,this.requester),this.encryption=new _e(this.config,this.requester),this.qrCode=new De(this.config,this.requester),this.registration=new Oe(this.config,this.requester),this.waba=new He(this.config,this.requester),K.log(`\n${Ke(this.config)}`)}updateTimeout(e){this.config[v.RequestTimeout]=e,this.requester.updateTimeout(e),K.log(`Timeout updated to ${e}ms`)}updateSenderNumberId(e){this.config[v.PhoneNumberId]=e,K.log(`Sender number ID updated to ${e}`)}updateAccessToken(e){this.config[v.AccessToken]=e,this.requester.updateAccessToken(e),K.log(`Access token updated`)}version(){return Bt()}static get Enums(){return c}getUserAgent(){return Vt()}generateEncryption(e){return Je(e||this.config[v.Passphrase])}};function Ut(e){return typeof e==`object`&&!!e}function q(e){return typeof e==`string`}const Wt=[x.DATA_EXCHANGE,x.INIT,x.BACK],Gt=[x.DATA_EXCHANGE,x.INIT];function Kt(e){if(!(`flow_token`in e&&q(e.flow_token)&&`action`in e))return!1;let{action:t,version:n,screen:r,data:i}=e,a=n===`3.0`,o=Wt.includes(t),s=r===void 0||q(r)&&r!==`SUCCESS`,c=t===x.DATA_EXCHANGE||Ut(i);return a&&o&&s&&c}function qt(e){if(!(`flow_token`in e&&q(e.flow_token)&&`action`in e))return!1;let{action:t,screen:n,data:r}=e,i=Gt.includes(t),a=q(n),o=Ut(r)&&`error_key`in r&&q(r.error)&&`error_message`in r&&q(r.error_message);return i&&a&&o}function Jt(e){return`action`in e&&e.action===`ping`}const J=new k(`WEBHOOK_UTILS`,process.env.DEBUG===`true`);async function Yt(e,t,n){try{let r=await e.json();if(r.object!==`whatsapp_business_account`){let e=`Received webhook for non-WhatsApp event`;return J.warn(e),new Response(JSON.stringify({error:e}),{status:404})}let i=[];for(let e of r.entry)try{let r=e.changes;for(let i of r)i.field===`messages`?await nn(e.id,i.value,t,n):i.field===`account_update`?await X(e.id,i,n.accountUpdateHandler,t):i.field===`account_review_update`?await X(e.id,i,n.accountReviewUpdateHandler,t):i.field===`account_alerts`?await X(e.id,i,n.accountAlertsHandler,t):i.field===`business_capability_update`?await X(e.id,i,n.businessCapabilityUpdateHandler,t):i.field===`phone_number_name_update`?await X(e.id,i,n.phoneNumberNameUpdateHandler,t):i.field===`phone_number_quality_update`?await X(e.id,i,n.phoneNumberQualityUpdateHandler,t):i.field===`message_template_status_update`?await X(e.id,i,n.messageTemplateStatusUpdateHandler,t):i.field===`template_category_update`?await X(e.id,i,n.templateCategoryUpdateHandler,t):i.field===`message_template_quality_update`?await X(e.id,i,n.messageTemplateQualityUpdateHandler,t):i.field===`flows`?await X(e.id,i,n.flowsHandler,t):i.field===`security`?await X(e.id,i,n.securityHandler,t):i.field===`history`?await X(e.id,i,n.historyHandler,t):i.field===`smb_message_echoes`?await X(e.id,i,n.smbMessageEchoesHandler,t):i.field===`smb_app_state_sync`?await X(e.id,i,n.smbAppStateSyncHandler,t):i.field===`account_settings_update`?await X(e.id,i,n.accountSettingsUpdateHandler,t):i.field===`automatic_events`?await X(e.id,i,n.automaticEventsHandler,t):i.field===`business_status_update`?await X(e.id,i,n.businessStatusUpdateHandler,t):i.field===`calls`?await X(e.id,i,n.callsHandler,t):i.field===`group_lifecycle_update`?await X(e.id,i,n.groupLifecycleUpdateHandler,t):i.field===`group_participants_update`?await X(e.id,i,n.groupParticipantsUpdateHandler,t):i.field===`group_settings_update`?await X(e.id,i,n.groupSettingsUpdateHandler,t):i.field===`group_status_update`?await X(e.id,i,n.groupStatusUpdateHandler,t):i.field===`message_echoes`?await X(e.id,i,n.messageEchoesHandler,t):i.field===`message_template_components_update`?await X(e.id,i,n.messageTemplateComponentsUpdateHandler,t):i.field===`messaging_handovers`?await X(e.id,i,n.messagingHandoversHandler,t):i.field===`partner_solutions`?await X(e.id,i,n.partnerSolutionsHandler,t):i.field===`payment_configuration_update`?await X(e.id,i,n.paymentConfigurationUpdateHandler,t):i.field===`standby`?await X(e.id,i,n.standbyHandler,t):i.field===`template_correct_category_detection`?await X(e.id,i,n.templateCorrectCategoryDetectionHandler,t):i.field===`tracking_events`?await X(e.id,i,n.trackingEventsHandler,t):i.field===`user_preferences`?await X(e.id,i,n.userPreferencesHandler,t):J.warn(`Unhandled webhook field: ${i.field}`)}catch(t){let n=`Error processing webhook: ${t}`;J.error(n,{entry:e,error:t}),i.push(n)}return new Response(i.length>0?JSON.stringify({errors:i}):null,{status:200})}catch(e){return J.error(`Error processing webhook:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500})}}function Xt(){return{version:`3.0`,data:{status:`active`}}}function Zt(){return{data:{acknowledged:!0}}}async function Qt(e,t,n,r){try{let i=await e.text();if(!$t(i,e.headers.get(`x-hub-signature-256`),t.WEBHOOK_VERIFICATION_TOKEN||``))return J.warn(`Invalid request signature`),new Response(JSON.stringify({error:`Unauthorized`}),{status:401});let{decryptedBody:a,aesKeyBuffer:o,initialVectorBuffer:s}=Ye(JSON.parse(i),t),c=Jt(a),l=qt(a),u=Kt(a),d;d=c?S.Ping:l?S.Error:u?S.Change:S.All;let f=r.get(d);if(!f){if(d===S.Ping)f=()=>Xt();else if(d===S.Error)f=()=>Zt();else if(f=r.get(S.All),!f)return J.warn(`No handler registered for flow type:`,{flowType:d,action:a.action}),new Response(JSON.stringify({error:`Handler not found`}),{status:404})}let p=await f(n,a);if(l){J.warn(`Flow error notification received`,{error:a.data});let e=p||Zt();return new Response(JSON.stringify(e),{status:200,headers:{"Content-Type":`application/json`}})}if(c||u){let e=Xe(p,o,s);return new Response(e,{status:200,headers:{"Content-Type":`text/plain`}})}return J.warn(`Unknown flow request type:`,a),new Response(JSON.stringify({error:`Unknown request type`}),{status:400})}catch(e){return J.error(`Error handling flow request:`,e),new Response(JSON.stringify({error:`Internal server error`}),{status:500})}}function $t(e,t,n){if(!t)return J.warn(`Missing signature in request`),!1;let i=r.createHmac(`sha256`,n).update(e).digest(`hex`);return r.timingSafeEqual(Buffer.from(t.replace(`sha256=`,``)),Buffer.from(i))}function en(e,t){return`${e[`x-forwarded-proto`]||`http`}://${e.host||`localhost`}${t||`/`}`}function tn(e){return e.id?e.id:(e.type===f.Interactive||e.type===f.Button)&&`context`in e&&e.context?.id?e.context.id:``}async function nn(e,t,n,r){let i=t.metadata,a=e,o=i.display_phone_number,s=i.phone_number_id;if(`statuses`in t&&t.statuses){let e=t;for(let t of e.statuses){let e={wabaId:a,phoneNumberId:s,displayPhoneNumber:o,status:t};await rn(r.statusHandler,n,e)}return}if(`messages`in t&&t.messages){let e=t,i=e.contacts?.[0]?.profile?.name||``;for(let t of e.messages){let e={wabaId:a,phoneNumberId:s,displayPhoneNumber:o,profileName:i,message:t,messageId:tn(t)},c=t.type;await Y(r.preProcessHandler,n,e,`pre-process`),await Y(r.messageHandlers.get(c),n,e,c),await Y(r.postProcessHandler,n,e,`post-process`)}}}async function Y(e,t,n,r){if(e)try{await e(t,n)}catch(e){J.error(`Error in ${r} handler:`,{error:e,messageId:n.messageId})}}async function rn(e,t,n){if(e)try{await e(t,n)}catch(e){J.error(`Error in status handler:`,{error:e,statusId:n.status.id})}}async function X(e,t,n,r){if(n)try{await n(r,{wabaId:e,value:t.value})}catch(n){J.error(`Error in ${t.field} handler:`,{error:n,wabaId:e})}}const Z=new k(`WEBHOOK_PROCESSOR`,process.env.DEBUG===`true`);var Q=class{config;client;messageHandlers=new Map;statusHandler=void 0;preProcessHandler=void 0;postProcessHandler=void 0;flowHandlers=new Map;accountUpdateHandler=void 0;accountReviewUpdateHandler=void 0;accountAlertsHandler=void 0;businessCapabilityUpdateHandler=void 0;phoneNumberNameUpdateHandler=void 0;phoneNumberQualityUpdateHandler=void 0;messageTemplateStatusUpdateHandler=void 0;templateCategoryUpdateHandler=void 0;messageTemplateQualityUpdateHandler=void 0;flowsHandler=void 0;securityHandler=void 0;historyHandler=void 0;smbMessageEchoesHandler=void 0;smbAppStateSyncHandler=void 0;accountSettingsUpdateHandler=void 0;automaticEventsHandler=void 0;businessStatusUpdateHandler=void 0;callsHandler=void 0;groupLifecycleUpdateHandler=void 0;groupParticipantsUpdateHandler=void 0;groupSettingsUpdateHandler=void 0;groupStatusUpdateHandler=void 0;messageEchoesHandler=void 0;messageTemplateComponentsUpdateHandler=void 0;messagingHandoversHandler=void 0;partnerSolutionsHandler=void 0;paymentConfigurationUpdateHandler=void 0;standbyHandler=void 0;templateCorrectCategoryDetectionHandler=void 0;trackingEventsHandler=void 0;userPreferencesHandler=void 0;constructor(e){this.config=Ge(e),this.client=new Ht(e),Z.log(`WebhookProcessor instantiated`)}async processVerification(e,t,n){return e===`subscribe`&&t===this.config.WEBHOOK_VERIFICATION_TOKEN?{status:200,body:n||``,headers:{"Content-Type":`text/plain`}}:{status:403,body:JSON.stringify({error:`Forbidden`}),headers:{"Content-Type":`application/json`}}}async processWebhook(e){try{let t=await Yt(e,this.client,{messageHandlers:this.messageHandlers,statusHandler:this.statusHandler,preProcessHandler:this.preProcessHandler,postProcessHandler:this.postProcessHandler,accountUpdateHandler:this.accountUpdateHandler,accountReviewUpdateHandler:this.accountReviewUpdateHandler,accountAlertsHandler:this.accountAlertsHandler,businessCapabilityUpdateHandler:this.businessCapabilityUpdateHandler,phoneNumberNameUpdateHandler:this.phoneNumberNameUpdateHandler,phoneNumberQualityUpdateHandler:this.phoneNumberQualityUpdateHandler,messageTemplateStatusUpdateHandler:this.messageTemplateStatusUpdateHandler,templateCategoryUpdateHandler:this.templateCategoryUpdateHandler,messageTemplateQualityUpdateHandler:this.messageTemplateQualityUpdateHandler,flowsHandler:this.flowsHandler,securityHandler:this.securityHandler,historyHandler:this.historyHandler,smbMessageEchoesHandler:this.smbMessageEchoesHandler,smbAppStateSyncHandler:this.smbAppStateSyncHandler,accountSettingsUpdateHandler:this.accountSettingsUpdateHandler,automaticEventsHandler:this.automaticEventsHandler,businessStatusUpdateHandler:this.businessStatusUpdateHandler,callsHandler:this.callsHandler,groupLifecycleUpdateHandler:this.groupLifecycleUpdateHandler,groupParticipantsUpdateHandler:this.groupParticipantsUpdateHandler,groupSettingsUpdateHandler:this.groupSettingsUpdateHandler,groupStatusUpdateHandler:this.groupStatusUpdateHandler,messageEchoesHandler:this.messageEchoesHandler,messageTemplateComponentsUpdateHandler:this.messageTemplateComponentsUpdateHandler,messagingHandoversHandler:this.messagingHandoversHandler,partnerSolutionsHandler:this.partnerSolutionsHandler,paymentConfigurationUpdateHandler:this.paymentConfigurationUpdateHandler,standbyHandler:this.standbyHandler,templateCorrectCategoryDetectionHandler:this.templateCorrectCategoryDetectionHandler,trackingEventsHandler:this.trackingEventsHandler,userPreferencesHandler:this.userPreferencesHandler}),n=await t.text(),r=t.headers.get(`content-type`)||`application/json`;return{status:t.status,body:n,headers:{"Content-Type":r}}}catch(e){return Z.log(`Error processing webhook: ${e}`),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async processFlow(e){try{let t=await Qt(e,this.config,this.client,this.flowHandlers),n=await t.text(),r=t.headers.get(`content-type`)||`text/plain`;return{status:t.status,body:n,headers:{"Content-Type":r}}}catch(e){return Z.log(`Error processing flow: ${e}`),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}onMessage(e,t){if(e===`statuses`)throw Error(`MessageTypesEnum.Statuses is deprecated. Use onStatus(handler) instead of onMessage(MessageTypesEnum.Statuses, handler)`);this.messageHandlers.set(e,t),Z.log(`Registered message handler for ${e}`)}onStatus(e){this.statusHandler=e,Z.log(`Registered status handler`)}onMessagePreProcess(e){this.preProcessHandler=e,Z.log(`Registered pre-process handler`)}onMessagePostProcess(e){this.postProcessHandler=e,Z.log(`Registered post-process handler`)}onFlow(e,t){this.flowHandlers.set(e,t),Z.log(`Registered flow handler for ${e}`)}onText(e){this.messageHandlers.set(f.Text,e),Z.log(`Registered text message handler`)}onImage(e){this.messageHandlers.set(f.Image,e),Z.log(`Registered image message handler`)}onVideo(e){this.messageHandlers.set(f.Video,e),Z.log(`Registered video message handler`)}onAudio(e){this.messageHandlers.set(f.Audio,e),Z.log(`Registered audio message handler`)}onDocument(e){this.messageHandlers.set(f.Document,e),Z.log(`Registered document message handler`)}onSticker(e){this.messageHandlers.set(f.Sticker,e),Z.log(`Registered sticker message handler`)}onInteractive(e){this.messageHandlers.set(f.Interactive,e),Z.log(`Registered interactive message handler`)}onButton(e){this.messageHandlers.set(f.Button,e),Z.log(`Registered button message handler`)}onLocation(e){this.messageHandlers.set(f.Location,e),Z.log(`Registered location message handler`)}onContacts(e){this.messageHandlers.set(f.Contacts,e),Z.log(`Registered contacts message handler`)}onReaction(e){this.messageHandlers.set(f.Reaction,e),Z.log(`Registered reaction message handler`)}onOrder(e){this.messageHandlers.set(f.Order,e),Z.log(`Registered order message handler`)}onSystem(e){this.messageHandlers.set(f.System,e),Z.log(`Registered system message handler`)}onAccountUpdate(e){this.accountUpdateHandler=e,Z.log(`Registered account_update handler`)}onAccountReviewUpdate(e){this.accountReviewUpdateHandler=e,Z.log(`Registered account_review_update handler`)}onAccountAlerts(e){this.accountAlertsHandler=e,Z.log(`Registered account_alerts handler`)}onBusinessCapabilityUpdate(e){this.businessCapabilityUpdateHandler=e,Z.log(`Registered business_capability_update handler`)}onPhoneNumberNameUpdate(e){this.phoneNumberNameUpdateHandler=e,Z.log(`Registered phone_number_name_update handler`)}onPhoneNumberQualityUpdate(e){this.phoneNumberQualityUpdateHandler=e,Z.log(`Registered phone_number_quality_update handler`)}onMessageTemplateStatusUpdate(e){this.messageTemplateStatusUpdateHandler=e,Z.log(`Registered message_template_status_update handler`)}onTemplateCategoryUpdate(e){this.templateCategoryUpdateHandler=e,Z.log(`Registered template_category_update handler`)}onMessageTemplateQualityUpdate(e){this.messageTemplateQualityUpdateHandler=e,Z.log(`Registered message_template_quality_update handler`)}onFlows(e){this.flowsHandler=e,Z.log(`Registered flows handler`)}onSecurity(e){this.securityHandler=e,Z.log(`Registered security handler`)}onHistory(e){this.historyHandler=e,Z.log(`Registered history handler`)}onSmbMessageEchoes(e){this.smbMessageEchoesHandler=e,Z.log(`Registered smb_message_echoes handler`)}onSmbAppStateSync(e){this.smbAppStateSyncHandler=e,Z.log(`Registered smb_app_state_sync handler`)}onAccountSettingsUpdate(e){this.accountSettingsUpdateHandler=e,Z.log(`Registered account_settings_update handler`)}onAutomaticEvents(e){this.automaticEventsHandler=e,Z.log(`Registered automatic_events handler`)}onBusinessStatusUpdate(e){this.businessStatusUpdateHandler=e,Z.log(`Registered business_status_update handler`)}onCalls(e){this.callsHandler=e,Z.log(`Registered calls handler`)}onGroupLifecycleUpdate(e){this.groupLifecycleUpdateHandler=e,Z.log(`Registered group_lifecycle_update handler`)}onGroupParticipantsUpdate(e){this.groupParticipantsUpdateHandler=e,Z.log(`Registered group_participants_update handler`)}onGroupSettingsUpdate(e){this.groupSettingsUpdateHandler=e,Z.log(`Registered group_settings_update handler`)}onGroupStatusUpdate(e){this.groupStatusUpdateHandler=e,Z.log(`Registered group_status_update handler`)}onMessageEchoes(e){this.messageEchoesHandler=e,Z.log(`Registered message_echoes handler`)}onMessageTemplateComponentsUpdate(e){this.messageTemplateComponentsUpdateHandler=e,Z.log(`Registered message_template_components_update handler`)}onMessagingHandovers(e){this.messagingHandoversHandler=e,Z.log(`Registered messaging_handovers handler`)}onPartnerSolutions(e){this.partnerSolutionsHandler=e,Z.log(`Registered partner_solutions handler`)}onPaymentConfigurationUpdate(e){this.paymentConfigurationUpdateHandler=e,Z.log(`Registered payment_configuration_update handler`)}onStandby(e){this.standbyHandler=e,Z.log(`Registered standby handler`)}onTemplateCorrectCategoryDetection(e){this.templateCorrectCategoryDetectionHandler=e,Z.log(`Registered template_correct_category_detection handler`)}onTrackingEvents(e){this.trackingEventsHandler=e,Z.log(`Registered tracking_events handler`)}onUserPreferences(e){this.userPreferencesHandler=e,Z.log(`Registered user_preferences handler`)}getClient(){return this.client}getConfig(){return this.config}},an=class{processor;constructor(e){this.processor=new Q(e)}async processVerification(e,t,n){return await this.processor.processVerification(e,t,n)}async processWebhook(e){return await this.processor.processWebhook(e)}async processFlow(e){return await this.processor.processFlow(e)}constructFullUrl(e,t=``){return en(e,t)}applyHeaders(e,t){t.setHeader&&Object.entries(e.headers).forEach(([e,n])=>{t.setHeader?.(e,n)})}async autoRoute(e,t,...n){switch(e.method?.toUpperCase()){case`GET`:return await this.handleGet(e,t,...n);case`POST`:return await this.handlePost(e,t,...n);default:if(t.status&&t.json)return t.status(405).json({error:`Method Not Allowed`});throw Error(`Method Not Allowed`)}}get webhookProcessor(){return this.processor}},on=class extends an{async handleGet(e,t,n){try{let{"hub.mode":n,"hub.verify_token":r,"hub.challenge":i}=e.query,a=await this.processVerification(n||null,r||null,i||null);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handlePost(e,t,n){try{let n=this.constructFullUrl(e.headers,e.url),r=new globalThis.Request(n,{method:e.method,headers:e.headers,body:JSON.stringify(e.body)}),i=await this.processWebhook(r);return this.applyHeaders(i,t),t.status(i.status).send(i.body),i}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handleFlow(e,t,n){try{let n=this.constructFullUrl(e.headers,e.url),r=e.rawBody||(e.method===`POST`?JSON.stringify(e.body):void 0),i=new globalThis.Request(n,{method:e.method,headers:e.headers,body:r}),a=await this.processFlow(i);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}getHandlers(){return{GET:(e,t,n)=>this.handleGet(e,t,n),POST:(e,t,n)=>this.handlePost(e,t,n),webhook:(e,t,n)=>this.autoRoute(e,t,n),flow:(e,t,n)=>this.handleFlow(e,t,n),processor:this.webhookProcessor}}};function sn(e){return new on(e).getHandlers()}function cn(e){let t=new Q(e);return{GET:async e=>{try{let{searchParams:n}=new URL(e.url),r=n.get(`hub.mode`),i=n.get(`hub.verify_token`),a=n.get(`hub.challenge`),o=await t.processVerification(r,i,a);return new Response(o.body,{status:o.status,headers:o.headers})}catch(e){return console.error(`Webhook verification error:`,e),new Response(`Internal Server Error`,{status:500})}},POST:async e=>{try{let n=await t.processWebhook(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Webhook processing error:`,e),new Response(`Internal Server Error`,{status:500})}},webhook:{GET:async e=>{try{let{searchParams:n}=new URL(e.url),r=n.get(`hub.mode`),i=n.get(`hub.verify_token`),a=n.get(`hub.challenge`),o=await t.processVerification(r,i,a);return new Response(o.body,{status:o.status,headers:o.headers})}catch(e){return console.error(`Webhook verification error:`,e),new Response(`Internal Server Error`,{status:500})}},POST:async e=>{try{let n=await t.processWebhook(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Webhook processing error:`,e),new Response(`Internal Server Error`,{status:500})}}},flow:{GET:async e=>{try{let n=await t.processFlow(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Flow GET error:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500,headers:{"Content-Type":`application/json`}})}},POST:async e=>{try{let n=await t.processFlow(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Flow POST error:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500,headers:{"Content-Type":`application/json`}})}}},processor:t}}var ln=class extends an{async parseRequestBody(e,t=!1){if(e.method===`POST`&&!e.body){let n=[];if(typeof e[Symbol.asyncIterator]==`function`){for await(let t of e)n.push(t);let r=Buffer.concat(n).toString();if(t&&(e.rawBody=r),r.trim())try{e.body=JSON.parse(r)}catch{throw Error(`Invalid JSON in request body`)}else e.body={}}}}async handleGet(e,t){try{let{"hub.mode":n,"hub.verify_token":r,"hub.challenge":i}=e.query,a=await this.processVerification(n||null,r||null,i||null);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return console.error(`Webhook verification error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handlePost(e,t){try{await this.parseRequestBody(e)}catch(e){return console.error(`Webhook processing error:`,e),e instanceof Error&&e.message===`Invalid JSON in request body`?(t.status(400).json({error:`Invalid JSON`}),{status:400,body:JSON.stringify({error:`Invalid JSON`}),headers:{"Content-Type":`application/json`}}):(t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}})}try{let n=this.constructFullUrl(e.headers,e.url),r=new Request(n,{method:`POST`,headers:e.headers,body:JSON.stringify(e.body)}),i=await this.processWebhook(r);return this.applyHeaders(i,t),t.status(i.status).send(i.body),i}catch(e){return console.error(`Webhook processing error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handleFlow(e,t){try{await this.parseRequestBody(e,!0)}catch(e){return console.error(`Flow body parsing error:`,e),e instanceof Error&&e.message===`Invalid JSON in request body`?(t.status(400).json({error:`Invalid JSON`}),{status:400,body:JSON.stringify({error:`Invalid JSON`}),headers:{"Content-Type":`application/json`}}):(t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}})}try{let n=this.constructFullUrl(e.headers,e.url),r=e.rawBody||(e.method===`POST`?JSON.stringify(e.body):void 0),i=new Request(n,{method:e.method,headers:e.headers,body:r}),a=await this.processFlow(i);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return console.error(`Flow error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}getHandlers(){return{GET:(e,t)=>this.handleGet(e,t),POST:(e,t)=>this.handlePost(e,t),webhook:(e,t)=>this.autoRoute(e,t),flow:(e,t)=>this.handleFlow(e,t),processor:this.webhookProcessor}}};function un(e){return new ln(e).getHandlers()}function dn(e){switch(e.type){case f.Text:return e.text.body;case f.Image:return e.image.caption||`[Image]`;case f.Video:return e.video.caption||`[Video]`;case f.Audio:return e.audio.voice?`[Voice Message]`:`[Audio]`;case f.Document:return e.document.caption||e.document.filename||`[Document]`;case f.Sticker:return e.sticker.animated?`[Animated Sticker]`:`[Sticker]`;case f.Interactive:{let t=e.interactive;return t.type===`button_reply`?t.button_reply.title:t.type===`list_reply`?t.list_reply.title:t.type===`nfm_reply`?t.nfm_reply.body||t.nfm_reply.name||`[Form Reply]`:`[Interactive]`}case f.Button:return e.button.text;case f.Location:return e.location.name||e.location.address||`📍 ${e.location.latitude}, ${e.location.longitude}`;case f.Contacts:{let t=e.contacts.map(e=>e.name.formatted_name);return t.length===1?`👤 ${t[0]}`:`👤 ${t.length} contacts`}case f.Reaction:return e.reaction.emoji||`[Reaction removed]`;case f.Order:{let t=e.order.product_items.length;return`🛒 Order: ${t} item${t>1?`s`:``}`}case f.System:return e.system.body;case f.Unsupported:return`[Unsupported message]`;default:return`[${e.type}]`}}const fn=(e,t)=>n.createHmac(`sha256`,t).update(e,`utf-8`).digest(`hex`);function pn(e){return e.type===f.Text}function mn(e){return e.type===f.Image}function hn(e){return e.type===f.Video}function gn(e){return e.type===f.Audio}function _n(e){return e.type===f.Document}function vn(e){return e.type===f.Sticker}function $(e){return e.type===f.Interactive}function yn(e){return e.type===f.Button}function bn(e){return e.type===f.Location}function xn(e){return e.type===f.Contacts}function Sn(e){return e.type===f.Reaction}function Cn(e){return e.type===f.Order}function wn(e){return e.type===f.System}function Tn(e){return $(e)&&e.interactive.type===`button_reply`}function En(e){return $(e)&&e.interactive.type===`list_reply`}function Dn(e){return $(e)&&e.interactive.type===`nfm_reply`}function On(e){return mn(e)?{id:e.image.id,mimeType:e.image.mime_type,sha256:e.image.sha256,caption:e.image.caption}:hn(e)?{id:e.video.id,mimeType:e.video.mime_type,sha256:e.video.sha256,caption:e.video.caption}:gn(e)?{id:e.audio.id,mimeType:e.audio.mime_type,sha256:e.audio.sha256,voice:e.audio.voice}:_n(e)?{id:e.document.id,mimeType:e.document.mime_type,sha256:e.document.sha256,caption:e.document.caption,filename:e.document.filename}:vn(e)?{id:e.sticker.id,mimeType:e.sticker.mime_type,sha256:e.sticker.sha256,animated:e.sticker.animated}:null}function kn(e){return $(e)?e.interactive.type===`button_reply`?{type:`button_reply`,id:e.interactive.button_reply.id,title:e.interactive.button_reply.title}:e.interactive.type===`list_reply`?{type:`list_reply`,id:e.interactive.list_reply.id,title:e.interactive.list_reply.title,description:e.interactive.list_reply.description}:e.interactive.type===`nfm_reply`?{type:`nfm_reply`,id:e.interactive.nfm_reply.name,title:e.interactive.nfm_reply.body,responseJson:e.interactive.nfm_reply.response_json}:null:null}function An(e){return bn(e)?{latitude:e.location.latitude,longitude:e.location.longitude,name:e.location.name,address:e.location.address,url:e.location.url}:null}function jn(e){return xn(e)?e.contacts.map(e=>({formattedName:e.name.formatted_name,firstName:e.name.first_name,lastName:e.name.last_name,phones:e.phones?.map(e=>e.phone)||[],emails:e.emails?.map(e=>e.email)||[]})):[]}function Mn(e){return Sn(e)?{messageId:e.reaction.message_id,emoji:e.reaction.emoji||null}:null}function Nn(e){return Cn(e)?{catalogId:e.order.catalog_id,text:e.order.text,items:e.order.product_items.map(e=>({productId:e.product_retailer_id,quantity:e.quantity,price:e.item_price,currency:e.currency}))}:null}let Pn=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),Fn=function(e){return e.Blocked=`BLOCKED`,e.Limited=`LIMITED`,e.Available=`AVAILABLE`,e}({}),In=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),Ln=function(e){return e.Verified=`verified`,e.PendingSubmission=`pending_submission`,e.Unverified=`unverified`,e.Rejected=`rejected`,e}({});export{$e as AUTHORIZATION_ERROR_CODES,y as AudioMediaTypesEnum,it as BLOCK_USER_ERROR_CODES,me as BlockUsersApi,Ee as BusinessProfileApi,pe as BusinessVerticalEnum,h as ButtonPositionEnum,at as CALLING_ERROR_CODES,he as CallingApi,l as CategoryEnum,ge as CommerceApi,_ as ComponentTypesEnum,ee as ConversationTypesEnum,de as CurrencyCodesEnum,fe as DataLocalizationRegionEnum,ae as DocumentMediaTypesEnum,_e as EncryptionApi,rt as FLOW_ERROR_CODES,x as FlowActionEnum,ve as FlowApi,be as FlowCategoryEnum,ye as FlowStatusEnum,S as FlowTypeEnum,ot as GROUP_ERROR_CODES,xe as GroupsApi,d as HttpMethodsEnum,tt as INTEGRITY_ERROR_CODES,ie as ImageMediaTypesEnum,m as InteractiveTypesEnum,ue as LanguagesEnum,k as Logger,Se as MarketingMessagesApi,Ce as MediaApi,C as MessageApi,C as MessagesApi,f as MessageTypesEnum,p as ParametersTypesEnum,we as PaymentsApi,Te as PhoneNumberApi,De as QrCodeApi,ce as ReferralSourceTypesEnum,Oe as RegistrationApi,le as RequestCodeMethodsEnum,nt as SEND_MESSAGE_ERROR_CODES,te as StatusEnum,re as StickerMediaTypesEnum,g as SubTypeEnum,se as SystemChangeTypesEnum,et as THROTTLING_ERROR_CODES,Be as TemplateApi,u as TemplateStatusEnum,Ve as TwoStepVerificationApi,ne as VideoMediaTypesEnum,Ze as WHATSAPP_ERROR_CODES,Pn as WabaAccountReviewStatus,In as WabaAccountStatus,He as WabaApi,Ln as WabaBusinessVerificationStatus,v as WabaConfigEnum,Fn as WabaHealthStatusCanSendMessage,Q as WebhookProcessor,oe as WebhookTypesEnum,Ht as WhatsApp,P as WhatsAppApiError,F as WhatsAppAuthorizationError,B as WhatsAppBlockUserError,V as WhatsAppCallingError,N as WhatsAppError,z as WhatsAppFlowError,H as WhatsAppGroupError,L as WhatsAppIntegrityError,Ct as WhatsAppNetworkError,R as WhatsAppSendMessageError,I as WhatsAppThrottlingError,wt as WhatsAppUnknownError,w as buildFieldsQueryString,en as constructFullUrl,Me as createAuthenticationTemplate,Ne as createCatalogTemplate,Pe as createCouponTemplate,Fe as createLimitedTimeOfferTemplate,Le as createMPMTemplate,Ie as createMediaCardCarouselTemplate,je as createOTPTemplate,Re as createProductCardCarouselTemplate,ze as createSPMTemplate,Ae as createTemplate,U as createWhatsAppApiError,Ye as decryptFlowRequest,Xe as encryptFlowResponse,sn as expressWebhookHandler,dn as extractMessageText,Ke as formatConfigTable,Je as generateEncryption,fn as generateXHub256Sig,jn as getContactsInfo,kn as getInteractiveReply,An as getLocationInfo,On as getMediaInfo,Nn as getOrderInfo,Mn as getReactionInfo,j as isApiPermissionErrorCode,gn as isAudioMessage,gt as isAuthorizationErrorCode,xt as isBlockUserErrorCode,yn as isButtonMessage,Tn as isButtonReply,M as isCallingErrorCode,xn as isContactsMessage,_n as isDocumentMessage,Kt as isFlowDataExchangeRequest,bt as isFlowErrorCode,qt as isFlowErrorRequest,Jt as isFlowPingRequest,St as isGroupErrorCode,mn as isImageMessage,vt as isIntegrityErrorCode,$ as isInteractiveMessage,En as isListReply,bn as isLocationMessage,W as isMetaError,Dn as isNfmReply,Cn as isOrderMessage,Sn as isReactionMessage,yt as isSendMessageErrorCode,vn as isStickerMessage,wn as isSystemMessage,pn as isTextMessage,_t as isThrottlingErrorCode,hn as isVideoMessage,Tt as isWhatsAppApiErrorResponse,Et as isWhatsAppAuthorizationError,jt as isWhatsAppBlockUserError,Mt as isWhatsAppCallingError,ht as isWhatsAppErrorCode,At as isWhatsAppFlowError,Nt as isWhatsAppGroupError,Ot as isWhatsAppIntegrityError,kt as isWhatsAppSendMessageError,Dt as isWhatsAppThrottlingError,cn as nextjsAppWebhookHandler,un as nextjsPagesWebhookHandler,Pt as normalizeMetaError,b as objectToQueryString,Qt as processFlowRequest,Yt as processWebhookMessages};
|
|
20
|
+
`)}function Bt(){try{let e=o(__dirname,`../../package.json`);return JSON.parse(a(e,`utf-8`)).version}catch{return`unknown`}}function Vt(){return`WhatsApp-Nodejs-SDK/${Bt()} (Node.js ${process.version})`}const K=new k(`WHATSAPP`,process.env.DEBUG===`true`);var Ht=class{config;requester;blockUsers;calling;commerce;groups;marketingMessages;messages;media;payments;phoneNumbers;twoStepVerification;flows;businessProfile;templates;encryption;qrCode;registration;waba;constructor(e){zt(),this.config=Ge(e),this.requester=new Rt(this.config[v.APIVersion],this.config[v.PhoneNumberId],this.config[v.AccessToken],this.config[v.BusinessAcctId],this.getUserAgent()),this.blockUsers=new me(this.config,this.requester),this.calling=new he(this.config,this.requester),this.commerce=new ge(this.config,this.requester),this.groups=new xe(this.config,this.requester),this.marketingMessages=new Se(this.config,this.requester),this.messages=new C(this.config,this.requester),this.media=new Ce(this.config,this.requester),this.payments=new we(this.config,this.requester),this.phoneNumbers=new Te(this.config,this.requester),this.twoStepVerification=new Ve(this.config,this.requester),this.flows=new ve(this.config,this.requester),this.businessProfile=new Ee(this.config,this.requester),this.templates=new Be(this.config,this.requester),this.encryption=new _e(this.config,this.requester),this.qrCode=new De(this.config,this.requester),this.registration=new Oe(this.config,this.requester),this.waba=new He(this.config,this.requester),K.log(`\n${Ke(this.config)}`)}updateTimeout(e){this.config[v.RequestTimeout]=e,this.requester.updateTimeout(e),K.log(`Timeout updated to ${e}ms`)}updateSenderNumberId(e){this.config[v.PhoneNumberId]=e,K.log(`Sender number ID updated to ${e}`)}updateAccessToken(e){this.config[v.AccessToken]=e,this.requester.updateAccessToken(e),K.log(`Access token updated`)}version(){return Bt()}static get Enums(){return c}getUserAgent(){return Vt()}generateEncryption(e){return Je(e||this.config[v.Passphrase])}};function Ut(e){return typeof e==`object`&&!!e}function q(e){return typeof e==`string`}const Wt=[x.DATA_EXCHANGE,x.INIT,x.BACK],Gt=[x.DATA_EXCHANGE,x.INIT];function Kt(e){if(!(`flow_token`in e&&q(e.flow_token)&&`action`in e))return!1;let{action:t,version:n,screen:r,data:i}=e,a=n===`3.0`,o=Wt.includes(t),s=r===void 0||q(r)&&r!==`SUCCESS`,c=t===x.DATA_EXCHANGE||Ut(i);return a&&o&&s&&c}function qt(e){if(!(`flow_token`in e&&q(e.flow_token)&&`action`in e))return!1;let{action:t,screen:n,data:r}=e,i=Gt.includes(t),a=q(n),o=Ut(r)&&`error_key`in r&&q(r.error)&&`error_message`in r&&q(r.error_message);return i&&a&&o}function Jt(e){return`action`in e&&e.action===`ping`}const J=new k(`WEBHOOK_UTILS`,process.env.DEBUG===`true`);async function Yt(e,t,n){try{let r=await e.json();if(n.rawHandler){let{rawHandler:e,rawHandlerFields:i}=n,a=r;if(i&&i.length>0){let e={...a,entry:a.entry.map(e=>({...e,changes:e.changes.filter(e=>i.includes(e.field))})).filter(e=>e.changes.length>0)};a=e.entry.length===0?null:e}a&&await e(t,a)}if(r.object!==`whatsapp_business_account`){let e=`Received webhook for non-WhatsApp event`;return J.warn(e),new Response(JSON.stringify({error:e}),{status:404})}let i=[];for(let e of r.entry)try{let r=e.changes;for(let i of r)i.field===`messages`?await nn(e.id,i.value,t,n):i.field===`account_update`?await X(e.id,i,n.accountUpdateHandler,t):i.field===`account_review_update`?await X(e.id,i,n.accountReviewUpdateHandler,t):i.field===`account_alerts`?await X(e.id,i,n.accountAlertsHandler,t):i.field===`business_capability_update`?await X(e.id,i,n.businessCapabilityUpdateHandler,t):i.field===`phone_number_name_update`?await X(e.id,i,n.phoneNumberNameUpdateHandler,t):i.field===`phone_number_quality_update`?await X(e.id,i,n.phoneNumberQualityUpdateHandler,t):i.field===`message_template_status_update`?await X(e.id,i,n.messageTemplateStatusUpdateHandler,t):i.field===`template_category_update`?await X(e.id,i,n.templateCategoryUpdateHandler,t):i.field===`message_template_quality_update`?await X(e.id,i,n.messageTemplateQualityUpdateHandler,t):i.field===`flows`?await X(e.id,i,n.flowsHandler,t):i.field===`security`?await X(e.id,i,n.securityHandler,t):i.field===`history`?await X(e.id,i,n.historyHandler,t):i.field===`smb_message_echoes`?await X(e.id,i,n.smbMessageEchoesHandler,t):i.field===`smb_app_state_sync`?await X(e.id,i,n.smbAppStateSyncHandler,t):i.field===`account_settings_update`?await X(e.id,i,n.accountSettingsUpdateHandler,t):i.field===`automatic_events`?await X(e.id,i,n.automaticEventsHandler,t):i.field===`business_status_update`?await X(e.id,i,n.businessStatusUpdateHandler,t):i.field===`calls`?await X(e.id,i,n.callsHandler,t):i.field===`group_lifecycle_update`?await X(e.id,i,n.groupLifecycleUpdateHandler,t):i.field===`group_participants_update`?await X(e.id,i,n.groupParticipantsUpdateHandler,t):i.field===`group_settings_update`?await X(e.id,i,n.groupSettingsUpdateHandler,t):i.field===`group_status_update`?await X(e.id,i,n.groupStatusUpdateHandler,t):i.field===`message_echoes`?await X(e.id,i,n.messageEchoesHandler,t):i.field===`message_template_components_update`?await X(e.id,i,n.messageTemplateComponentsUpdateHandler,t):i.field===`messaging_handovers`?await X(e.id,i,n.messagingHandoversHandler,t):i.field===`partner_solutions`?await X(e.id,i,n.partnerSolutionsHandler,t):i.field===`payment_configuration_update`?await X(e.id,i,n.paymentConfigurationUpdateHandler,t):i.field===`standby`?await X(e.id,i,n.standbyHandler,t):i.field===`template_correct_category_detection`?await X(e.id,i,n.templateCorrectCategoryDetectionHandler,t):i.field===`tracking_events`?await X(e.id,i,n.trackingEventsHandler,t):i.field===`user_preferences`?await X(e.id,i,n.userPreferencesHandler,t):J.warn(`Unhandled webhook field: ${i.field}`)}catch(t){let n=`Error processing webhook: ${t}`;J.error(n,{entry:e,error:t}),i.push(n)}return new Response(i.length>0?JSON.stringify({errors:i}):null,{status:200})}catch(e){return J.error(`Error processing webhook:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500})}}function Xt(){return{version:`3.0`,data:{status:`active`}}}function Zt(){return{data:{acknowledged:!0}}}async function Qt(e,t,n,r){try{let i=await e.text();if(!$t(i,e.headers.get(`x-hub-signature-256`),t.WEBHOOK_VERIFICATION_TOKEN||``))return J.warn(`Invalid request signature`),new Response(JSON.stringify({error:`Unauthorized`}),{status:401});let{decryptedBody:a,aesKeyBuffer:o,initialVectorBuffer:s}=Ye(JSON.parse(i),t),c=Jt(a),l=qt(a),u=Kt(a),d;d=c?S.Ping:l?S.Error:u?S.Change:S.All;let f=r.get(d);if(!f){if(d===S.Ping)f=()=>Xt();else if(d===S.Error)f=()=>Zt();else if(f=r.get(S.All),!f)return J.warn(`No handler registered for flow type:`,{flowType:d,action:a.action}),new Response(JSON.stringify({error:`Handler not found`}),{status:404})}let p=await f(n,a);if(l){J.warn(`Flow error notification received`,{error:a.data});let e=p||Zt();return new Response(JSON.stringify(e),{status:200,headers:{"Content-Type":`application/json`}})}if(c||u){let e=Xe(p,o,s);return new Response(e,{status:200,headers:{"Content-Type":`text/plain`}})}return J.warn(`Unknown flow request type:`,a),new Response(JSON.stringify({error:`Unknown request type`}),{status:400})}catch(e){return J.error(`Error handling flow request:`,e),new Response(JSON.stringify({error:`Internal server error`}),{status:500})}}function $t(e,t,n){if(!t)return J.warn(`Missing signature in request`),!1;let i=r.createHmac(`sha256`,n).update(e).digest(`hex`);return r.timingSafeEqual(Buffer.from(t.replace(`sha256=`,``)),Buffer.from(i))}function en(e,t){return`${e[`x-forwarded-proto`]||`http`}://${e.host||`localhost`}${t||`/`}`}function tn(e){return e.id?e.id:(e.type===f.Interactive||e.type===f.Button)&&`context`in e&&e.context?.id?e.context.id:``}async function nn(e,t,n,r){let i=t.metadata,a=e,o=i.display_phone_number,s=i.phone_number_id;if(`statuses`in t&&t.statuses){let e=t;for(let t of e.statuses){let e={wabaId:a,phoneNumberId:s,displayPhoneNumber:o,status:t};await rn(r.statusHandler,n,e)}return}if(`messages`in t&&t.messages){let e=t,i=e.contacts?.[0]?.profile?.name||``;for(let t of e.messages){let e={wabaId:a,phoneNumberId:s,displayPhoneNumber:o,profileName:i,message:t,messageId:tn(t)},c=t.type;await Y(r.preProcessHandler,n,e,`pre-process`),await Y(r.messageHandlers.get(c),n,e,c),await Y(r.postProcessHandler,n,e,`post-process`)}}}async function Y(e,t,n,r){if(e)try{await e(t,n)}catch(e){J.error(`Error in ${r} handler:`,{error:e,messageId:n.messageId})}}async function rn(e,t,n){if(e)try{await e(t,n)}catch(e){J.error(`Error in status handler:`,{error:e,statusId:n.status.id})}}async function X(e,t,n,r){if(n)try{await n(r,{wabaId:e,value:t.value})}catch(n){J.error(`Error in ${t.field} handler:`,{error:n,wabaId:e})}}const Z=new k(`WEBHOOK_PROCESSOR`,process.env.DEBUG===`true`);var Q=class{config;client;messageHandlers=new Map;statusHandler=void 0;preProcessHandler=void 0;postProcessHandler=void 0;rawHandler=void 0;flowHandlers=new Map;accountUpdateHandler=void 0;accountReviewUpdateHandler=void 0;accountAlertsHandler=void 0;businessCapabilityUpdateHandler=void 0;phoneNumberNameUpdateHandler=void 0;phoneNumberQualityUpdateHandler=void 0;messageTemplateStatusUpdateHandler=void 0;templateCategoryUpdateHandler=void 0;messageTemplateQualityUpdateHandler=void 0;flowsHandler=void 0;securityHandler=void 0;historyHandler=void 0;smbMessageEchoesHandler=void 0;smbAppStateSyncHandler=void 0;accountSettingsUpdateHandler=void 0;automaticEventsHandler=void 0;businessStatusUpdateHandler=void 0;callsHandler=void 0;groupLifecycleUpdateHandler=void 0;groupParticipantsUpdateHandler=void 0;groupSettingsUpdateHandler=void 0;groupStatusUpdateHandler=void 0;messageEchoesHandler=void 0;messageTemplateComponentsUpdateHandler=void 0;messagingHandoversHandler=void 0;partnerSolutionsHandler=void 0;paymentConfigurationUpdateHandler=void 0;standbyHandler=void 0;templateCorrectCategoryDetectionHandler=void 0;trackingEventsHandler=void 0;userPreferencesHandler=void 0;constructor(e){this.config=Ge(e),this.client=new Ht(e),Z.log(`WebhookProcessor instantiated`)}async processVerification(e,t,n){return e===`subscribe`&&t===this.config.WEBHOOK_VERIFICATION_TOKEN?{status:200,body:n||``,headers:{"Content-Type":`text/plain`}}:{status:403,body:JSON.stringify({error:`Forbidden`}),headers:{"Content-Type":`application/json`}}}async processWebhook(e){try{let t=await Yt(e,this.client,{messageHandlers:this.messageHandlers,statusHandler:this.statusHandler,preProcessHandler:this.preProcessHandler,postProcessHandler:this.postProcessHandler,rawHandler:this.rawHandler?.handler,rawHandlerFields:this.rawHandler?.fields,accountUpdateHandler:this.accountUpdateHandler,accountReviewUpdateHandler:this.accountReviewUpdateHandler,accountAlertsHandler:this.accountAlertsHandler,businessCapabilityUpdateHandler:this.businessCapabilityUpdateHandler,phoneNumberNameUpdateHandler:this.phoneNumberNameUpdateHandler,phoneNumberQualityUpdateHandler:this.phoneNumberQualityUpdateHandler,messageTemplateStatusUpdateHandler:this.messageTemplateStatusUpdateHandler,templateCategoryUpdateHandler:this.templateCategoryUpdateHandler,messageTemplateQualityUpdateHandler:this.messageTemplateQualityUpdateHandler,flowsHandler:this.flowsHandler,securityHandler:this.securityHandler,historyHandler:this.historyHandler,smbMessageEchoesHandler:this.smbMessageEchoesHandler,smbAppStateSyncHandler:this.smbAppStateSyncHandler,accountSettingsUpdateHandler:this.accountSettingsUpdateHandler,automaticEventsHandler:this.automaticEventsHandler,businessStatusUpdateHandler:this.businessStatusUpdateHandler,callsHandler:this.callsHandler,groupLifecycleUpdateHandler:this.groupLifecycleUpdateHandler,groupParticipantsUpdateHandler:this.groupParticipantsUpdateHandler,groupSettingsUpdateHandler:this.groupSettingsUpdateHandler,groupStatusUpdateHandler:this.groupStatusUpdateHandler,messageEchoesHandler:this.messageEchoesHandler,messageTemplateComponentsUpdateHandler:this.messageTemplateComponentsUpdateHandler,messagingHandoversHandler:this.messagingHandoversHandler,partnerSolutionsHandler:this.partnerSolutionsHandler,paymentConfigurationUpdateHandler:this.paymentConfigurationUpdateHandler,standbyHandler:this.standbyHandler,templateCorrectCategoryDetectionHandler:this.templateCorrectCategoryDetectionHandler,trackingEventsHandler:this.trackingEventsHandler,userPreferencesHandler:this.userPreferencesHandler}),n=await t.text(),r=t.headers.get(`content-type`)||`application/json`;return{status:t.status,body:n,headers:{"Content-Type":r}}}catch(e){return Z.log(`Error processing webhook: ${e}`),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async processFlow(e){try{let t=await Qt(e,this.config,this.client,this.flowHandlers),n=await t.text(),r=t.headers.get(`content-type`)||`text/plain`;return{status:t.status,body:n,headers:{"Content-Type":r}}}catch(e){return Z.log(`Error processing flow: ${e}`),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}onMessage(e,t){if(e===`statuses`)throw Error(`MessageTypesEnum.Statuses is deprecated. Use onStatus(handler) instead of onMessage(MessageTypesEnum.Statuses, handler)`);this.messageHandlers.set(e,t),Z.log(`Registered message handler for ${e}`)}onStatus(e){this.statusHandler=e,Z.log(`Registered status handler`)}onMessagePreProcess(e){this.preProcessHandler=e,Z.log(`Registered pre-process handler`)}onMessagePostProcess(e){this.postProcessHandler=e,Z.log(`Registered post-process handler`)}onRaw(e,t){this.rawHandler={handler:e,fields:t},Z.log(`Registered raw webhook handler${t?` for fields: ${t.join(`, `)}`:``}`)}onFlow(e,t){this.flowHandlers.set(e,t),Z.log(`Registered flow handler for ${e}`)}onText(e){this.messageHandlers.set(f.Text,e),Z.log(`Registered text message handler`)}onImage(e){this.messageHandlers.set(f.Image,e),Z.log(`Registered image message handler`)}onVideo(e){this.messageHandlers.set(f.Video,e),Z.log(`Registered video message handler`)}onAudio(e){this.messageHandlers.set(f.Audio,e),Z.log(`Registered audio message handler`)}onDocument(e){this.messageHandlers.set(f.Document,e),Z.log(`Registered document message handler`)}onSticker(e){this.messageHandlers.set(f.Sticker,e),Z.log(`Registered sticker message handler`)}onInteractive(e){this.messageHandlers.set(f.Interactive,e),Z.log(`Registered interactive message handler`)}onButton(e){this.messageHandlers.set(f.Button,e),Z.log(`Registered button message handler`)}onLocation(e){this.messageHandlers.set(f.Location,e),Z.log(`Registered location message handler`)}onContacts(e){this.messageHandlers.set(f.Contacts,e),Z.log(`Registered contacts message handler`)}onReaction(e){this.messageHandlers.set(f.Reaction,e),Z.log(`Registered reaction message handler`)}onOrder(e){this.messageHandlers.set(f.Order,e),Z.log(`Registered order message handler`)}onSystem(e){this.messageHandlers.set(f.System,e),Z.log(`Registered system message handler`)}onAccountUpdate(e){this.accountUpdateHandler=e,Z.log(`Registered account_update handler`)}onAccountReviewUpdate(e){this.accountReviewUpdateHandler=e,Z.log(`Registered account_review_update handler`)}onAccountAlerts(e){this.accountAlertsHandler=e,Z.log(`Registered account_alerts handler`)}onBusinessCapabilityUpdate(e){this.businessCapabilityUpdateHandler=e,Z.log(`Registered business_capability_update handler`)}onPhoneNumberNameUpdate(e){this.phoneNumberNameUpdateHandler=e,Z.log(`Registered phone_number_name_update handler`)}onPhoneNumberQualityUpdate(e){this.phoneNumberQualityUpdateHandler=e,Z.log(`Registered phone_number_quality_update handler`)}onMessageTemplateStatusUpdate(e){this.messageTemplateStatusUpdateHandler=e,Z.log(`Registered message_template_status_update handler`)}onTemplateCategoryUpdate(e){this.templateCategoryUpdateHandler=e,Z.log(`Registered template_category_update handler`)}onMessageTemplateQualityUpdate(e){this.messageTemplateQualityUpdateHandler=e,Z.log(`Registered message_template_quality_update handler`)}onFlows(e){this.flowsHandler=e,Z.log(`Registered flows handler`)}onSecurity(e){this.securityHandler=e,Z.log(`Registered security handler`)}onHistory(e){this.historyHandler=e,Z.log(`Registered history handler`)}onSmbMessageEchoes(e){this.smbMessageEchoesHandler=e,Z.log(`Registered smb_message_echoes handler`)}onSmbAppStateSync(e){this.smbAppStateSyncHandler=e,Z.log(`Registered smb_app_state_sync handler`)}onAccountSettingsUpdate(e){this.accountSettingsUpdateHandler=e,Z.log(`Registered account_settings_update handler`)}onAutomaticEvents(e){this.automaticEventsHandler=e,Z.log(`Registered automatic_events handler`)}onBusinessStatusUpdate(e){this.businessStatusUpdateHandler=e,Z.log(`Registered business_status_update handler`)}onCalls(e){this.callsHandler=e,Z.log(`Registered calls handler`)}onGroupLifecycleUpdate(e){this.groupLifecycleUpdateHandler=e,Z.log(`Registered group_lifecycle_update handler`)}onGroupParticipantsUpdate(e){this.groupParticipantsUpdateHandler=e,Z.log(`Registered group_participants_update handler`)}onGroupSettingsUpdate(e){this.groupSettingsUpdateHandler=e,Z.log(`Registered group_settings_update handler`)}onGroupStatusUpdate(e){this.groupStatusUpdateHandler=e,Z.log(`Registered group_status_update handler`)}onMessageEchoes(e){this.messageEchoesHandler=e,Z.log(`Registered message_echoes handler`)}onMessageTemplateComponentsUpdate(e){this.messageTemplateComponentsUpdateHandler=e,Z.log(`Registered message_template_components_update handler`)}onMessagingHandovers(e){this.messagingHandoversHandler=e,Z.log(`Registered messaging_handovers handler`)}onPartnerSolutions(e){this.partnerSolutionsHandler=e,Z.log(`Registered partner_solutions handler`)}onPaymentConfigurationUpdate(e){this.paymentConfigurationUpdateHandler=e,Z.log(`Registered payment_configuration_update handler`)}onStandby(e){this.standbyHandler=e,Z.log(`Registered standby handler`)}onTemplateCorrectCategoryDetection(e){this.templateCorrectCategoryDetectionHandler=e,Z.log(`Registered template_correct_category_detection handler`)}onTrackingEvents(e){this.trackingEventsHandler=e,Z.log(`Registered tracking_events handler`)}onUserPreferences(e){this.userPreferencesHandler=e,Z.log(`Registered user_preferences handler`)}getClient(){return this.client}getConfig(){return this.config}},an=class{processor;constructor(e){this.processor=new Q(e)}async processVerification(e,t,n){return await this.processor.processVerification(e,t,n)}async processWebhook(e){return await this.processor.processWebhook(e)}async processFlow(e){return await this.processor.processFlow(e)}constructFullUrl(e,t=``){return en(e,t)}applyHeaders(e,t){t.setHeader&&Object.entries(e.headers).forEach(([e,n])=>{t.setHeader?.(e,n)})}async autoRoute(e,t,...n){switch(e.method?.toUpperCase()){case`GET`:return await this.handleGet(e,t,...n);case`POST`:return await this.handlePost(e,t,...n);default:if(t.status&&t.json)return t.status(405).json({error:`Method Not Allowed`});throw Error(`Method Not Allowed`)}}get webhookProcessor(){return this.processor}},on=class extends an{async handleGet(e,t,n){try{let{"hub.mode":n,"hub.verify_token":r,"hub.challenge":i}=e.query,a=await this.processVerification(n||null,r||null,i||null);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handlePost(e,t,n){try{let n=this.constructFullUrl(e.headers,e.url),r=new globalThis.Request(n,{method:e.method,headers:e.headers,body:JSON.stringify(e.body)}),i=await this.processWebhook(r);return this.applyHeaders(i,t),t.status(i.status).send(i.body),i}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handleFlow(e,t,n){try{let n=this.constructFullUrl(e.headers,e.url),r=e.rawBody||(e.method===`POST`?JSON.stringify(e.body):void 0),i=new globalThis.Request(n,{method:e.method,headers:e.headers,body:r}),a=await this.processFlow(i);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return n(e),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}getHandlers(){return{GET:(e,t,n)=>this.handleGet(e,t,n),POST:(e,t,n)=>this.handlePost(e,t,n),webhook:(e,t,n)=>this.autoRoute(e,t,n),flow:(e,t,n)=>this.handleFlow(e,t,n),processor:this.webhookProcessor}}};function sn(e){return new on(e).getHandlers()}function cn(e){let t=new Q(e);return{GET:async e=>{try{let{searchParams:n}=new URL(e.url),r=n.get(`hub.mode`),i=n.get(`hub.verify_token`),a=n.get(`hub.challenge`),o=await t.processVerification(r,i,a);return new Response(o.body,{status:o.status,headers:o.headers})}catch(e){return console.error(`Webhook verification error:`,e),new Response(`Internal Server Error`,{status:500})}},POST:async e=>{try{let n=await t.processWebhook(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Webhook processing error:`,e),new Response(`Internal Server Error`,{status:500})}},webhook:{GET:async e=>{try{let{searchParams:n}=new URL(e.url),r=n.get(`hub.mode`),i=n.get(`hub.verify_token`),a=n.get(`hub.challenge`),o=await t.processVerification(r,i,a);return new Response(o.body,{status:o.status,headers:o.headers})}catch(e){return console.error(`Webhook verification error:`,e),new Response(`Internal Server Error`,{status:500})}},POST:async e=>{try{let n=await t.processWebhook(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Webhook processing error:`,e),new Response(`Internal Server Error`,{status:500})}}},flow:{GET:async e=>{try{let n=await t.processFlow(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Flow GET error:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500,headers:{"Content-Type":`application/json`}})}},POST:async e=>{try{let n=await t.processFlow(e);return new Response(n.body,{status:n.status,headers:n.headers})}catch(e){return console.error(`Flow POST error:`,e),new Response(JSON.stringify({error:`Internal Server Error`}),{status:500,headers:{"Content-Type":`application/json`}})}}},processor:t}}var ln=class extends an{async parseRequestBody(e,t=!1){if(e.method===`POST`&&!e.body){let n=[];if(typeof e[Symbol.asyncIterator]==`function`){for await(let t of e)n.push(t);let r=Buffer.concat(n).toString();if(t&&(e.rawBody=r),r.trim())try{e.body=JSON.parse(r)}catch{throw Error(`Invalid JSON in request body`)}else e.body={}}}}async handleGet(e,t){try{let{"hub.mode":n,"hub.verify_token":r,"hub.challenge":i}=e.query,a=await this.processVerification(n||null,r||null,i||null);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return console.error(`Webhook verification error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handlePost(e,t){try{await this.parseRequestBody(e)}catch(e){return console.error(`Webhook processing error:`,e),e instanceof Error&&e.message===`Invalid JSON in request body`?(t.status(400).json({error:`Invalid JSON`}),{status:400,body:JSON.stringify({error:`Invalid JSON`}),headers:{"Content-Type":`application/json`}}):(t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}})}try{let n=this.constructFullUrl(e.headers,e.url),r=new Request(n,{method:`POST`,headers:e.headers,body:JSON.stringify(e.body)}),i=await this.processWebhook(r);return this.applyHeaders(i,t),t.status(i.status).send(i.body),i}catch(e){return console.error(`Webhook processing error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}async handleFlow(e,t){try{await this.parseRequestBody(e,!0)}catch(e){return console.error(`Flow body parsing error:`,e),e instanceof Error&&e.message===`Invalid JSON in request body`?(t.status(400).json({error:`Invalid JSON`}),{status:400,body:JSON.stringify({error:`Invalid JSON`}),headers:{"Content-Type":`application/json`}}):(t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}})}try{let n=this.constructFullUrl(e.headers,e.url),r=e.rawBody||(e.method===`POST`?JSON.stringify(e.body):void 0),i=new Request(n,{method:e.method,headers:e.headers,body:r}),a=await this.processFlow(i);return this.applyHeaders(a,t),t.status(a.status).send(a.body),a}catch(e){return console.error(`Flow error:`,e),t.status(500).json({error:`Internal Server Error`}),{status:500,body:JSON.stringify({error:`Internal Server Error`}),headers:{"Content-Type":`application/json`}}}}getHandlers(){return{GET:(e,t)=>this.handleGet(e,t),POST:(e,t)=>this.handlePost(e,t),webhook:(e,t)=>this.autoRoute(e,t),flow:(e,t)=>this.handleFlow(e,t),processor:this.webhookProcessor}}};function un(e){return new ln(e).getHandlers()}function dn(e){switch(e.type){case f.Text:return e.text.body;case f.Image:return e.image.caption||`[Image]`;case f.Video:return e.video.caption||`[Video]`;case f.Audio:return e.audio.voice?`[Voice Message]`:`[Audio]`;case f.Document:return e.document.caption||e.document.filename||`[Document]`;case f.Sticker:return e.sticker.animated?`[Animated Sticker]`:`[Sticker]`;case f.Interactive:{let t=e.interactive;return t.type===`button_reply`?t.button_reply.title:t.type===`list_reply`?t.list_reply.title:t.type===`nfm_reply`?t.nfm_reply.body||t.nfm_reply.name||`[Form Reply]`:`[Interactive]`}case f.Button:return e.button.text;case f.Location:return e.location.name||e.location.address||`📍 ${e.location.latitude}, ${e.location.longitude}`;case f.Contacts:{let t=e.contacts.map(e=>e.name.formatted_name);return t.length===1?`👤 ${t[0]}`:`👤 ${t.length} contacts`}case f.Reaction:return e.reaction.emoji||`[Reaction removed]`;case f.Order:{let t=e.order.product_items.length;return`🛒 Order: ${t} item${t>1?`s`:``}`}case f.System:return e.system.body;case f.Unsupported:return`[Unsupported message]`;default:return`[${e.type}]`}}const fn=(e,t)=>n.createHmac(`sha256`,t).update(e,`utf-8`).digest(`hex`);function pn(e){return e.type===f.Text}function mn(e){return e.type===f.Image}function hn(e){return e.type===f.Video}function gn(e){return e.type===f.Audio}function _n(e){return e.type===f.Document}function vn(e){return e.type===f.Sticker}function $(e){return e.type===f.Interactive}function yn(e){return e.type===f.Button}function bn(e){return e.type===f.Location}function xn(e){return e.type===f.Contacts}function Sn(e){return e.type===f.Reaction}function Cn(e){return e.type===f.Order}function wn(e){return e.type===f.System}function Tn(e){return $(e)&&e.interactive.type===`button_reply`}function En(e){return $(e)&&e.interactive.type===`list_reply`}function Dn(e){return $(e)&&e.interactive.type===`nfm_reply`}function On(e){return mn(e)?{id:e.image.id,mimeType:e.image.mime_type,sha256:e.image.sha256,caption:e.image.caption}:hn(e)?{id:e.video.id,mimeType:e.video.mime_type,sha256:e.video.sha256,caption:e.video.caption}:gn(e)?{id:e.audio.id,mimeType:e.audio.mime_type,sha256:e.audio.sha256,voice:e.audio.voice}:_n(e)?{id:e.document.id,mimeType:e.document.mime_type,sha256:e.document.sha256,caption:e.document.caption,filename:e.document.filename}:vn(e)?{id:e.sticker.id,mimeType:e.sticker.mime_type,sha256:e.sticker.sha256,animated:e.sticker.animated}:null}function kn(e){return $(e)?e.interactive.type===`button_reply`?{type:`button_reply`,id:e.interactive.button_reply.id,title:e.interactive.button_reply.title}:e.interactive.type===`list_reply`?{type:`list_reply`,id:e.interactive.list_reply.id,title:e.interactive.list_reply.title,description:e.interactive.list_reply.description}:e.interactive.type===`nfm_reply`?{type:`nfm_reply`,id:e.interactive.nfm_reply.name,title:e.interactive.nfm_reply.body,responseJson:e.interactive.nfm_reply.response_json}:null:null}function An(e){return bn(e)?{latitude:e.location.latitude,longitude:e.location.longitude,name:e.location.name,address:e.location.address,url:e.location.url}:null}function jn(e){return xn(e)?e.contacts.map(e=>({formattedName:e.name.formatted_name,firstName:e.name.first_name,lastName:e.name.last_name,phones:e.phones?.map(e=>e.phone)||[],emails:e.emails?.map(e=>e.email)||[]})):[]}function Mn(e){return Sn(e)?{messageId:e.reaction.message_id,emoji:e.reaction.emoji||null}:null}function Nn(e){return Cn(e)?{catalogId:e.order.catalog_id,text:e.order.text,items:e.order.product_items.map(e=>({productId:e.product_retailer_id,quantity:e.quantity,price:e.item_price,currency:e.currency}))}:null}let Pn=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),Fn=function(e){return e.Blocked=`BLOCKED`,e.Limited=`LIMITED`,e.Available=`AVAILABLE`,e}({}),In=function(e){return e.Approved=`APPROVED`,e.Active=`ACTIVE`,e.Inactive=`INACTIVE`,e.Disabled=`DISABLED`,e}({}),Ln=function(e){return e.Verified=`verified`,e.PendingSubmission=`pending_submission`,e.Unverified=`unverified`,e.Rejected=`rejected`,e}({});export{$e as AUTHORIZATION_ERROR_CODES,y as AudioMediaTypesEnum,it as BLOCK_USER_ERROR_CODES,me as BlockUsersApi,Ee as BusinessProfileApi,pe as BusinessVerticalEnum,h as ButtonPositionEnum,at as CALLING_ERROR_CODES,he as CallingApi,l as CategoryEnum,ge as CommerceApi,_ as ComponentTypesEnum,ee as ConversationTypesEnum,de as CurrencyCodesEnum,fe as DataLocalizationRegionEnum,ae as DocumentMediaTypesEnum,_e as EncryptionApi,rt as FLOW_ERROR_CODES,x as FlowActionEnum,ve as FlowApi,be as FlowCategoryEnum,ye as FlowStatusEnum,S as FlowTypeEnum,ot as GROUP_ERROR_CODES,xe as GroupsApi,d as HttpMethodsEnum,tt as INTEGRITY_ERROR_CODES,ie as ImageMediaTypesEnum,m as InteractiveTypesEnum,ue as LanguagesEnum,k as Logger,Se as MarketingMessagesApi,Ce as MediaApi,C as MessageApi,C as MessagesApi,f as MessageTypesEnum,p as ParametersTypesEnum,we as PaymentsApi,Te as PhoneNumberApi,De as QrCodeApi,ce as ReferralSourceTypesEnum,Oe as RegistrationApi,le as RequestCodeMethodsEnum,nt as SEND_MESSAGE_ERROR_CODES,te as StatusEnum,re as StickerMediaTypesEnum,g as SubTypeEnum,se as SystemChangeTypesEnum,et as THROTTLING_ERROR_CODES,Be as TemplateApi,u as TemplateStatusEnum,Ve as TwoStepVerificationApi,ne as VideoMediaTypesEnum,Ze as WHATSAPP_ERROR_CODES,Pn as WabaAccountReviewStatus,In as WabaAccountStatus,He as WabaApi,Ln as WabaBusinessVerificationStatus,v as WabaConfigEnum,Fn as WabaHealthStatusCanSendMessage,Q as WebhookProcessor,oe as WebhookTypesEnum,Ht as WhatsApp,P as WhatsAppApiError,F as WhatsAppAuthorizationError,B as WhatsAppBlockUserError,V as WhatsAppCallingError,N as WhatsAppError,z as WhatsAppFlowError,H as WhatsAppGroupError,L as WhatsAppIntegrityError,Ct as WhatsAppNetworkError,R as WhatsAppSendMessageError,I as WhatsAppThrottlingError,wt as WhatsAppUnknownError,w as buildFieldsQueryString,en as constructFullUrl,Me as createAuthenticationTemplate,Ne as createCatalogTemplate,Pe as createCouponTemplate,Fe as createLimitedTimeOfferTemplate,Le as createMPMTemplate,Ie as createMediaCardCarouselTemplate,je as createOTPTemplate,Re as createProductCardCarouselTemplate,ze as createSPMTemplate,Ae as createTemplate,U as createWhatsAppApiError,Ye as decryptFlowRequest,Xe as encryptFlowResponse,sn as expressWebhookHandler,dn as extractMessageText,Ke as formatConfigTable,Je as generateEncryption,fn as generateXHub256Sig,jn as getContactsInfo,kn as getInteractiveReply,An as getLocationInfo,On as getMediaInfo,Nn as getOrderInfo,Mn as getReactionInfo,j as isApiPermissionErrorCode,gn as isAudioMessage,gt as isAuthorizationErrorCode,xt as isBlockUserErrorCode,yn as isButtonMessage,Tn as isButtonReply,M as isCallingErrorCode,xn as isContactsMessage,_n as isDocumentMessage,Kt as isFlowDataExchangeRequest,bt as isFlowErrorCode,qt as isFlowErrorRequest,Jt as isFlowPingRequest,St as isGroupErrorCode,mn as isImageMessage,vt as isIntegrityErrorCode,$ as isInteractiveMessage,En as isListReply,bn as isLocationMessage,W as isMetaError,Dn as isNfmReply,Cn as isOrderMessage,Sn as isReactionMessage,yt as isSendMessageErrorCode,vn as isStickerMessage,wn as isSystemMessage,pn as isTextMessage,_t as isThrottlingErrorCode,hn as isVideoMessage,Tt as isWhatsAppApiErrorResponse,Et as isWhatsAppAuthorizationError,jt as isWhatsAppBlockUserError,Mt as isWhatsAppCallingError,ht as isWhatsAppErrorCode,At as isWhatsAppFlowError,Nt as isWhatsAppGroupError,Ot as isWhatsAppIntegrityError,kt as isWhatsAppSendMessageError,Dt as isWhatsAppThrottlingError,cn as nextjsAppWebhookHandler,un as nextjsPagesWebhookHandler,Pt as normalizeMetaError,b as objectToQueryString,Qt as processFlowRequest,Yt as processWebhookMessages};
|
|
21
21
|
//# sourceMappingURL=index.js.map
|