meta-cloud-api 0.1.12 → 0.1.13
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/api/base.d.mts +1 -1
- package/dist/api/base.d.ts +1 -1
- package/dist/api/businessProfile.d.mts +1 -1
- package/dist/api/businessProfile.d.ts +1 -1
- package/dist/api/businessProfile.js +1 -1
- package/dist/api/businessProfile.mjs +1 -1
- package/dist/api/encryption.d.mts +1 -1
- package/dist/api/encryption.d.ts +1 -1
- package/dist/api/encryption.js +1 -1
- package/dist/api/flow.d.mts +1 -1
- package/dist/api/flow.d.ts +1 -1
- package/dist/api/flow.js +1 -1
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/api/media.d.mts +1 -1
- package/dist/api/media.d.ts +1 -1
- package/dist/api/media.js +1 -1
- package/dist/api/messages.d.mts +1 -1
- package/dist/api/messages.d.ts +1 -1
- package/dist/api/messages.js +1 -1
- package/dist/api/messages.mjs +1 -1
- package/dist/api/phoneNumber.d.mts +1 -1
- package/dist/api/phoneNumber.d.ts +1 -1
- package/dist/api/phoneNumber.js +1 -1
- package/dist/api/qrCode.d.mts +1 -1
- package/dist/api/qrCode.d.ts +1 -1
- package/dist/api/qrCode.js +1 -1
- package/dist/api/registration.d.mts +1 -1
- package/dist/api/registration.d.ts +1 -1
- package/dist/api/registration.js +1 -1
- package/dist/api/template.d.mts +1 -1
- package/dist/api/template.d.ts +1 -1
- package/dist/api/template.js +1 -1
- package/dist/api/template.mjs +1 -1
- package/dist/api/twoStepVerification.d.mts +1 -1
- package/dist/api/twoStepVerification.d.ts +1 -1
- package/dist/api/twoStepVerification.js +1 -1
- package/dist/api/waba.d.mts +1 -1
- package/dist/api/waba.d.ts +1 -1
- package/dist/api/waba.js +1 -1
- package/dist/api/waba.mjs +1 -1
- package/dist/{enums-D7paGoTY.d.mts → enums-DEhBfoMC.d.mts} +16 -11
- package/dist/{enums-D7paGoTY.d.ts → enums-DEhBfoMC.d.ts} +16 -11
- package/dist/httpsClient.d.mts +1 -1
- package/dist/httpsClient.d.ts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/request.d.mts +1 -1
- package/dist/request.d.ts +1 -1
- package/dist/types/base.d.mts +1 -1
- package/dist/types/base.d.ts +1 -1
- package/dist/types/businessProfile.d.mts +1 -1
- package/dist/types/businessProfile.d.ts +1 -1
- package/dist/types/config.d.mts +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/encryption.d.mts +1 -1
- package/dist/types/encryption.d.ts +1 -1
- package/dist/types/enums.d.mts +1 -1
- package/dist/types/enums.d.ts +1 -1
- package/dist/types/enums.js +1 -1
- package/dist/types/enums.js.map +1 -1
- package/dist/types/enums.mjs +1 -1
- package/dist/types/enums.mjs.map +1 -1
- package/dist/types/flow.d.mts +1 -1
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/httpsClient.d.mts +1 -1
- package/dist/types/httpsClient.d.ts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/media.d.mts +1 -1
- package/dist/types/media.d.ts +1 -1
- package/dist/types/messages.d.mts +1 -1
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/phoneNumber.d.mts +1 -1
- package/dist/types/phoneNumber.d.ts +1 -1
- package/dist/types/qrCode.d.mts +1 -1
- package/dist/types/qrCode.d.ts +1 -1
- package/dist/types/registration.d.mts +1 -1
- package/dist/types/registration.d.ts +1 -1
- package/dist/types/request.d.mts +1 -1
- package/dist/types/request.d.ts +1 -1
- package/dist/types/template.d.mts +1 -1
- package/dist/types/template.d.ts +1 -1
- package/dist/types/twoStepVerification.d.mts +1 -1
- package/dist/types/twoStepVerification.d.ts +1 -1
- package/dist/types/waba.d.mts +1 -1
- package/dist/types/waba.d.ts +1 -1
- package/dist/types/webhook.d.mts +4 -20
- package/dist/types/webhook.d.ts +4 -20
- package/dist/types/webhook.js +1 -1
- package/dist/types/webhook.js.map +1 -1
- package/dist/types/webhook.mjs +1 -1
- package/dist/types/webhook.mjs.map +1 -1
- package/dist/types/whatsapp.d.mts +1 -1
- package/dist/types/whatsapp.d.ts +1 -1
- package/dist/utils/filters.d.mts +3 -2
- package/dist/utils/filters.d.ts +3 -2
- package/dist/utils/filters.js +1 -1
- package/dist/utils/filters.js.map +1 -1
- package/dist/utils/filters.mjs +1 -1
- package/dist/utils/filters.mjs.map +1 -1
- package/dist/utils/importConfig.d.mts +1 -1
- package/dist/utils/importConfig.d.ts +1 -1
- package/dist/utils/importConfig.js +1 -1
- package/dist/utils/importConfig.mjs +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/webhook.d.mts +19 -10
- package/dist/webhook.d.ts +19 -10
- package/dist/webhook.js +1 -1
- package/dist/webhook.js.map +1 -1
- package/dist/webhook.mjs +1 -1
- package/dist/webhook.mjs.map +1 -1
- package/dist/whatsapp.d.mts +1 -1
- package/dist/whatsapp.d.ts +1 -1
- package/dist/whatsapp.js +1 -1
- package/dist/whatsapp.js.map +1 -1
- package/dist/whatsapp.mjs +1 -1
- package/dist/whatsapp.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
|
|
|
2
2
|
import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
|
|
3
3
|
import { TwoStepVerificationClass } from '../types/twoStepVerification.mjs';
|
|
4
4
|
import BaseAPI from './base.mjs';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DEhBfoMC.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
7
7
|
|
|
8
8
|
declare class TwoStepVerificationAPI extends BaseAPI implements TwoStepVerificationClass {
|
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
|
|
|
2
2
|
import { RequesterClass, ResponseSuccess } from '../types/request.js';
|
|
3
3
|
import { TwoStepVerificationClass } from '../types/twoStepVerification.js';
|
|
4
4
|
import BaseAPI from './base.js';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DEhBfoMC.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
8
|
declare class TwoStepVerificationAPI extends BaseAPI implements TwoStepVerificationClass {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var I=(S,R)=>{for(var t in R)G(S,t,{get:R[t],enumerable:!0})},T=(S,R,t,D)=>{if(R&&typeof R=="object"||typeof R=="function")for(let A of B(R))!O.call(S,A)&&A!==t&&G(S,A,{get:()=>R[A],enumerable:!(D=i(R,A))||D.enumerable});return S};var K=S=>T(G({},"__esModule",{value:!0}),S);var H={};I(H,{default:()=>U});module.exports=K(H);var P=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var M="BaseAPI",l=!1,_=new P(M,process.env.DEBUG==="true"||l),N=class{config;client;constructor(R,t){this.config=R,this.client=t,_.log("Initialized with HTTPSClient")}sendJson(R,t,D,A){return this.client.getJson(R,t,D,A)}sendFormData(R,t,D,A){return this.client.sendFormData(R,t,D,A)}sendUrlEncodedForm(R,t,D,A){return this.client.sendUrlEncodedForm(R,t,D,A)}};var U=class extends N{constructor(R,t){super(R,t)}async setTwoStepVerificationCode(R){let t={pin:R};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};
|
|
2
2
|
//# sourceMappingURL=twoStepVerification.js.map
|
package/dist/api/waba.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
|
|
|
2
2
|
import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
|
|
3
3
|
import { WABAClass, WabaAccountFieldsParam, WabaAccount, WabaSubscriptions, UpdateWabaSubscription } from '../types/waba.mjs';
|
|
4
4
|
import BaseAPI from './base.mjs';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DEhBfoMC.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
7
7
|
|
|
8
8
|
declare class WabaAPI extends BaseAPI implements WABAClass {
|
package/dist/api/waba.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
|
|
|
2
2
|
import { RequesterClass, ResponseSuccess } from '../types/request.js';
|
|
3
3
|
import { WABAClass, WabaAccountFieldsParam, WabaAccount, WabaSubscriptions, UpdateWabaSubscription } from '../types/waba.js';
|
|
4
4
|
import BaseAPI from './base.js';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DEhBfoMC.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
8
|
declare class WabaAPI extends BaseAPI implements WABAClass {
|
package/dist/api/waba.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var l=(A,t)=>{for(var R in t)U(A,R,{get:t[R],enumerable:!0})},T=(A,t,R,S)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of O(t))!I.call(A,i)&&i!==R&&U(A,i,{get:()=>t[i],enumerable:!(S=G(t,i))||S.enumerable});return A};var p=A=>T(U({},"__esModule",{value:!0}),A);var F={};l(F,{default:()=>N});module.exports=p(F);function B(A){if(!A)return"";let t="";return Array.isArray(A)?t=A.join(","):t=Object.entries(A).filter(([R,S])=>S).map(([R])=>R).join(","),t?`?fields=${t}`:""}var D=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var K="BaseAPI",M=!1,_=new D(K,process.env.DEBUG==="true"||M),P=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}sendJson(t,R,S,i){return this.client.getJson(t,R,S,i)}sendFormData(t,R,S,i){return this.client.sendFormData(t,R,S,i)}sendUrlEncodedForm(t,R,S,i){return this.client.sendUrlEncodedForm(t,R,S,i)}};var N=class extends P{constructor(t,R){super(t,R)}async getWabaAccount(t){let R=B(t)?.replace(/,/g,"%2C");return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}${R}`,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:R}){let S={override_callback_uri:t,verify_token:R};return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,JSON.stringify(S))}async unsubscribeFromWaba(){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}};
|
|
2
2
|
//# sourceMappingURL=waba.js.map
|
package/dist/api/waba.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function U(S){if(!S)return"";let R="";return Array.isArray(S)?R=S.join(","):R=Object.entries(S).filter(([t,A])=>A).map(([t])=>t).join(","),R?`?fields=${R}`:""}var D=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var
|
|
1
|
+
function U(S){if(!S)return"";let R="";return Array.isArray(S)?R=S.join(","):R=Object.entries(S).filter(([t,A])=>A).map(([t])=>t).join(","),R?`?fields=${R}`:""}var D=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var B="BaseAPI",G=!1,O=new D(B,process.env.DEBUG==="true"||G),P=class{config;client;constructor(R,t){this.config=R,this.client=t,O.log("Initialized with HTTPSClient")}sendJson(R,t,A,i){return this.client.getJson(R,t,A,i)}sendFormData(R,t,A,i){return this.client.sendFormData(R,t,A,i)}sendUrlEncodedForm(R,t,A,i){return this.client.sendUrlEncodedForm(R,t,A,i)}};var N=class extends P{constructor(R,t){super(R,t)}async getWabaAccount(R){let t=U(R)?.replace(/,/g,"%2C");return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}${t}`,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:R,verify_token:t}){let A={override_callback_uri:R,verify_token:t};return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,JSON.stringify(A))}async unsubscribeFromWaba(){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}};export{N as default};
|
|
2
2
|
//# sourceMappingURL=waba.mjs.map
|
|
@@ -15,17 +15,22 @@ declare enum HttpMethodsEnum {
|
|
|
15
15
|
Delete = "DELETE"
|
|
16
16
|
}
|
|
17
17
|
declare enum MessageTypesEnum {
|
|
18
|
-
Audio = "audio"
|
|
19
|
-
Contacts = "contacts"
|
|
20
|
-
Document = "document"
|
|
21
|
-
Image = "image"
|
|
22
|
-
Interactive = "interactive"
|
|
23
|
-
Location = "location"
|
|
24
|
-
Reaction = "sticker"
|
|
25
|
-
Sticker = "sticker"
|
|
26
|
-
Template = "template"
|
|
27
|
-
Text = "text"
|
|
28
|
-
Video = "video"
|
|
18
|
+
Audio = "audio",
|
|
19
|
+
Contacts = "contacts",
|
|
20
|
+
Document = "document",
|
|
21
|
+
Image = "image",
|
|
22
|
+
Interactive = "interactive",
|
|
23
|
+
Location = "location",
|
|
24
|
+
Reaction = "sticker",
|
|
25
|
+
Sticker = "sticker",
|
|
26
|
+
Template = "template",
|
|
27
|
+
Text = "text",
|
|
28
|
+
Video = "video",
|
|
29
|
+
Button = "button",
|
|
30
|
+
Order = "order",
|
|
31
|
+
System = "system",
|
|
32
|
+
Unknown = "unknown",
|
|
33
|
+
'*' = "*"
|
|
29
34
|
}
|
|
30
35
|
declare enum ParametersTypesEnum {
|
|
31
36
|
Currency = "currency",
|
|
@@ -15,17 +15,22 @@ declare enum HttpMethodsEnum {
|
|
|
15
15
|
Delete = "DELETE"
|
|
16
16
|
}
|
|
17
17
|
declare enum MessageTypesEnum {
|
|
18
|
-
Audio = "audio"
|
|
19
|
-
Contacts = "contacts"
|
|
20
|
-
Document = "document"
|
|
21
|
-
Image = "image"
|
|
22
|
-
Interactive = "interactive"
|
|
23
|
-
Location = "location"
|
|
24
|
-
Reaction = "sticker"
|
|
25
|
-
Sticker = "sticker"
|
|
26
|
-
Template = "template"
|
|
27
|
-
Text = "text"
|
|
28
|
-
Video = "video"
|
|
18
|
+
Audio = "audio",
|
|
19
|
+
Contacts = "contacts",
|
|
20
|
+
Document = "document",
|
|
21
|
+
Image = "image",
|
|
22
|
+
Interactive = "interactive",
|
|
23
|
+
Location = "location",
|
|
24
|
+
Reaction = "sticker",
|
|
25
|
+
Sticker = "sticker",
|
|
26
|
+
Template = "template",
|
|
27
|
+
Text = "text",
|
|
28
|
+
Video = "video",
|
|
29
|
+
Button = "button",
|
|
30
|
+
Order = "order",
|
|
31
|
+
System = "system",
|
|
32
|
+
Unknown = "unknown",
|
|
33
|
+
'*' = "*"
|
|
29
34
|
}
|
|
30
35
|
declare enum ParametersTypesEnum {
|
|
31
36
|
Currency = "currency",
|
package/dist/httpsClient.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Agent } from 'https';
|
|
2
|
-
import { H as HttpMethodsEnum } from './enums-
|
|
2
|
+
import { H as HttpMethodsEnum } from './enums-DEhBfoMC.mjs';
|
|
3
3
|
import { HttpsClientClass, HttpsClientResponseClass, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.mjs';
|
|
4
4
|
|
|
5
5
|
declare class HttpsClient implements HttpsClientClass {
|
package/dist/httpsClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Agent } from 'https';
|
|
2
|
-
import { H as HttpMethodsEnum } from './enums-
|
|
2
|
+
import { H as HttpMethodsEnum } from './enums-DEhBfoMC.js';
|
|
3
3
|
import { HttpsClientClass, HttpsClientResponseClass, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.js';
|
|
4
4
|
|
|
5
5
|
declare class HttpsClient implements HttpsClientClass {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { IRequest, IResponse, default as WebhookHandler } from './webhook.mjs';
|
|
2
2
|
import WhatsApp from './whatsapp.mjs';
|
|
3
3
|
export { WabaConfigType } from './types/config.mjs';
|
|
4
|
-
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-
|
|
4
|
+
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
5
|
export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.mjs';
|
|
6
6
|
export { BaseClass } from './types/base.mjs';
|
|
7
7
|
export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { IRequest, IResponse, default as WebhookHandler } from './webhook.js';
|
|
2
2
|
import WhatsApp from './whatsapp.js';
|
|
3
3
|
export { WabaConfigType } from './types/config.js';
|
|
4
|
-
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-
|
|
4
|
+
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
5
|
export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, RequesterResponseInterface, ResponseData, ResponsePagination, ResponseSuccess } from './types/request.js';
|
|
6
6
|
export { BaseClass } from './types/base.js';
|
|
7
7
|
export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Ne=Object.create;var H=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var de=(r,t)=>{for(var s in t)H(r,s,{get:t[s],enumerable:!0})},Re=(r,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Me(t))!Be.call(r,o)&&o!==s&&H(r,o,{get:()=>t[o],enumerable:!(i=Oe(t,o))||i.enumerable});return r};var Ue=(r,t,s)=>(s=r!=null?Ne(De(r)):{},Re(t||!r||!r.__esModule?H(s,"default",{value:r,enumerable:!0}):s,r)),xe=r=>Re(H({},"__esModule",{value:!0}),r);var it={};de(it,{AudioMediaTypesEnum:()=>te,BusinessVerticalEnum:()=>le,ButtonPositionEnum:()=>X,ButtonTypesEnum:()=>V,CategoryEnum:()=>k,ComponentTypesEnum:()=>Y,ConversationTypesEnum:()=>Z,CurrencyCodesEnum:()=>ne,DataLocalizationRegionEnum:()=>pe,DocumentMediaTypesEnum:()=>ee,FlowCategoryEnum:()=>Ie,FlowStatusEnum:()=>Se,HttpMethodsEnum:()=>P,ImageMediaTypesEnum:()=>C,InteractiveTypesEnum:()=>j,LanguagesEnum:()=>ae,MessageTypesEnum:()=>L,ParametersTypesEnum:()=>u,ReferralSourceTypesEnum:()=>oe,RequestCodeMethodsEnum:()=>re,StatusEnum:()=>Q,StickerMediaTypesEnum:()=>E,SystemChangeTypesEnum:()=>ie,TemplateStatusEnum:()=>$,VideoMediaTypesEnum:()=>z,WabaAccountReviewStatus:()=>be,WabaAccountStatus:()=>_e,WabaBusinessVerificationStatus:()=>Te,WabaConfigEnum:()=>h,WabaHealthStatusCanSendMessage:()=>Ae,WebhookHandler:()=>F,WebhookTypesEnum:()=>se,default:()=>st,generateXHub256Sig:()=>tt,importConfig:()=>fe,isMetaError:()=>K,objectToQueryString:()=>_});module.exports=xe(it);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 ve="WEBHOOK",Fe=!1,T=new m(ve,process.env.DEBUG==="true"||Fe),F=class{config;messageHandlers=new Map;eventHandlers=new Map;constructor(t){this.config=t,T.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?(T.log("Webhook verified successfully"),s.status(200).send(n)):(T.log("Webhook verification failed"),s.status(403).end())}async handleWebhookRequest(t,s){let i=t.body;if(i.object!=="whatsapp_business_account"){T.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){T.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:f,phoneNumberId:i,originalData:n};switch(f){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),T.log(`Registered handler for message type: ${t}`)}onEvent(t,s){this.eventHandlers.set(t,s),T.log(`Registered handler for event field: ${t}`)}};var ce={};de(ce,{AudioMediaTypesEnum:()=>te,BusinessVerticalEnum:()=>le,ButtonPositionEnum:()=>X,ButtonTypesEnum:()=>V,CategoryEnum:()=>k,ComponentTypesEnum:()=>Y,ConversationTypesEnum:()=>Z,CurrencyCodesEnum:()=>ne,DataLocalizationRegionEnum:()=>pe,DocumentMediaTypesEnum:()=>ee,HttpMethodsEnum:()=>P,ImageMediaTypesEnum:()=>C,InteractiveTypesEnum:()=>j,LanguagesEnum:()=>ae,MessageTypesEnum:()=>L,ParametersTypesEnum:()=>u,ReferralSourceTypesEnum:()=>oe,RequestCodeMethodsEnum:()=>re,StatusEnum:()=>Q,StickerMediaTypesEnum:()=>E,SystemChangeTypesEnum:()=>ie,TemplateStatusEnum:()=>$,VideoMediaTypesEnum:()=>z,WabaConfigEnum:()=>h,WebhookTypesEnum:()=>se});var k=(i=>(i.Authentication="AUTHENTICATION",i.Marketing="MARKETING",i.Utility="UTILITY",i))(k||{}),$=(i=>(i.Approved="APPROVED",i.Pending="PENDING",i.Rejected="REJECTED",i))($||{}),P=(o=>(o.Get="GET",o.Post="POST",o.Put="PUT",o.Delete="DELETE",o))(P||{}),L=(d=>(d.Audio="audio",d.Contacts="contacts",d.Document="document",d.Image="image",d.Interactive="interactive",d.Location="location",d.Reaction="sticker",d.Sticker="sticker",d.Template="template",d.Text="text",d.Video="video",d))(L||{}),u=(l=>(l.Currency="currency",l.DateTime="date_time",l.Document="document",l.Image="image",l.Text="text",l.Video="video",l.Payload="payload",l))(u||{}),j=(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))(j||{}),V=(s=>(s.QuickReply="quick_reply",s.URL="url",s))(V||{}),X=(i=>(i[i.First=0]="First",i[i.Second=1]="Second",i[i.Third=2]="Third",i))(X||{}),Y=(o=>(o.Header="HEADER",o.Body="BODY",o.Button="BUTTON",o.Footer="FOOTER",o))(Y||{}),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||{}),Q=(i=>(i.Delivered="delivered",i.Read="read",i.Sent="sent",i))(Q||{}),z=(s=>(s.Mp4="video/mp4",s.Threegp="video/3gp",s))(z||{}),E=(t=>(t.Webp="image/webp",t))(E||{}),C=(s=>(s.Jpeg="image/jpeg",s.Png="image/png",s))(C||{}),ee=(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))(ee||{}),te=(n=>(n.Aac="audio/aac",n.Mp4="audio/mp4",n.Mpeg="audio/mpeg",n.Amr="audio/amr",n.Ogg="audio/ogg",n))(te||{}),se=(d=>(d.Audio="audio",d.Button="button",d.Document="document",d.Text="text",d.Image="image",d.Interactive="interactive",d.Order="order",d.Sticker="sticker",d.System="system",d.Unknown="unknown",d.Video="video",d))(se||{}),ie=(s=>(s.CustomerChangedNumber="customer_changed_number",s.CustomerIdentityChanged="customer_identity_changed",s))(ie||{}),oe=(s=>(s.Ad="ad",s.Post="post",s))(oe||{}),re=(s=>(s.Sms="SMS",s.Voice="VOICE",s))(re||{}),ae=(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))(ae||{}),ne=(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))(ne||{}),pe=(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))(pe||{}),le=(R=>(R.ALCOHOL="ALCOHOL",R.APPAREL="APPAREL",R.AUTO="AUTO",R.BEAUTY="BEAUTY",R.EDU="EDU",R.ENTERTAIN="ENTERTAIN",R.EVENT_PLAN="EVENT_PLAN",R.FINANCE="FINANCE",R.GOVT="GOVT",R.GROCERY="GROCERY",R.HEALTH="HEALTH",R.HOTEL="HOTEL",R.NONPROFIT="NONPROFIT",R.ONLINE_GAMBLING="ONLINE_GAMBLING",R.OTC_DRUGS="OTC_DRUGS",R.OTHER="OTHER",R.PHYSICAL_GAMBLING="PHYSICAL_GAMBLING",R.PROF_SERVICES="PROF_SERVICES",R.RESTAURANT="RESTAURANT",R.RETAIL="RETAIL",R.TRAVEL="TRAVEL",R))(le||{});var qe="BaseAPI",Ge=!1,We=new m(qe,process.env.DEBUG==="true"||Ge),g=class{config;client;constructor(t,s){this.config=t,this.client=s,We.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 J(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 _=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 S=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}${J(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=_({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 I=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",He=!1,me=new m(ye,process.env.DEBUG==="true"||He),w=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 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 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 N=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 M=class extends g{endpoint="phone_numbers";constructor(t,s){super(t,s)}async getPhoneNumberById(t){let s=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 D=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 B=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)}`,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)}`,this.config.REQUEST_TIMEOUT,null)}};var x=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 v=class extends g{constructor(t,s){super(t,s)}async getWabaAccount(t){let s=J(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 he=require("https");var Le="HttpsClient",Je=!1,Ke=new m(Le,process.env.DEBUG==="true"||Je),q=class{agent;constructor(){this.agent=new he.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 A=await fetch(l,{method:i,headers:o,body:f,signal:p.signal});return Ke.log(`${i} : ${l} - ${JSON.stringify(A)}`),clearTimeout(b),new ge(A)}catch(A){throw A}}},ge=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)}}};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 ke="REQUESTER",$e=!1,ue=new m(ke,process.env.DEBUG==="true"||$e),G=class{client;accessToken;phoneNumberId;businessAcctId;apiVersion;userAgent;host;protocol="https:";constructor(t,s,i,o,n,f){this.client=new q,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)}`;ue.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 A=await b.json();throw K(A)?A:{name:"MetaError",message:"Unknown error occurred",error:{message:A.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 je="UTILS",Ve=!1,Pe=new m(je,process.env.DEBUG==="true"||Ve),Xe="graph.facebook.com",Ye=3e3,Ze=30,Qe=2e4,ze=r=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!r?.accessToken)throw Pe.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},fe=r=>{ze(r);let t={WA_BASE_URL:process.env.WA_BASE_URL||Xe,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||"")||Ye,MAX_RETRIES_AFTER_WAIT:parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||Ze,REQUEST_TIMEOUT:parseInt(process.env.REQUEST_TIMEOUT||"")||Qe,DEBUG:process.env.DEBUG==="true"};return Pe.log(`Configuration loaded for App Id ${t.M4D_APP_ID}`),t};var Ee="WHATSAPP",Ce=!1,W=new m(Ee,process.env.DEBUG==="true"||Ce),et="WA_SDK",y=class{config;requester;messages;templates;phoneNumber;qrCode;encryption;twoStepVerification;registration;media;waba;flow;businessProfile;static Enums=ce;constructor(t){this.config=fe(t),this.requester=new G(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 M(this.config,this.requester),this.qrCode=new D(this.config,this.requester),this.encryption=new I(this.config,this.requester),this.twoStepVerification=new x(this.config,this.requester),this.registration=new B(this.config,this.requester),this.media=new N(this.config,this.requester),this.waba=new v(this.config,this.requester),this.flow=new w(this.config,this.requester),this.businessProfile=new S(this.config,this.requester),W.log("WhatsApp Node.js SDK instantiated!")}userAgent(){return`${et}/0.0.1 (Node.js ${process.version})`}updateTimeout(t){return this.config.REQUEST_TIMEOUT=t,W.log(`Updated request timeout to ${t}ms`),!0}updatePhoneNumberId(t){return this.config.WA_PHONE_NUMBER_ID=t,W.log(`Updated sender phone number id to ${t}`),!0}updateAccessToken(t){return this.config.CLOUD_API_ACCESS_TOKEN=t,W.log("Updated access token"),!0}updateWabaId(t){return this.config.WA_BUSINESS_ACCOUNT_ID=t,W.log(`Updated business account id to ${t}`),!0}};var be=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(be||{}),Ae=(i=>(i.Blocked="BLOCKED",i.Limited="LIMITED",i.Available="AVAILABLE",i))(Ae||{}),_e=(o=>(o.Approved="APPROVED",o.Active="ACTIVE",o.Inactive="INACTIVE",o.Disabled="DISABLED",o))(_e||{}),Te=(o=>(o.Verified="verified",o.PendingSubmission="pending_submission",o.Unverified="unverified",o.Rejected="rejected",o))(Te||{});var Se=(n=>(n.Draft="DRAFT",n.Published="PUBLISHED",n.Throttled="THROTTLED",n.Blocked="BLOCKED",n.Deprecated="DEPRECATED",n))(Se||{}),Ie=(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))(Ie||{});var we=Ue(require("crypto")),tt=(r,t)=>we.createHmac("sha256",t).update(r,"utf-8").digest("hex");var st=y;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 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});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|