whatsapp-api-js
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -1,2 +0,2 @@ | ||
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{default:()=>WhatsAppAPI});module.exports=__toCommonJS(src_exports);class WhatsAppAPI{token;appSecret;webhookVerifyToken;v;fetch;subtle;parsed;secure;on={};constructor({token,appSecret,webhookVerifyToken,v="v18.0",parsed=!0,secure=!0,ponyfill={}}){if(this.token=token,this.secure=!!secure,this.secure){if(this.appSecret=appSecret,typeof ponyfill.subtle!="object"&&(typeof crypto!="object"||typeof crypto?.subtle!="object"))throw new Error("subtle is not defined in the enviroment, please provide a valid ponyfill object with the parameter 'ponyfill.subtle'.");this.subtle=ponyfill.subtle||crypto.subtle}if(webhookVerifyToken&&(this.webhookVerifyToken=webhookVerifyToken),typeof ponyfill.fetch!="function"&&typeof fetch!="function")throw new Error("fetch is not defined in the enviroment, please provide a valid ponyfill function with the parameter 'ponyfill.fetch'.");this.fetch=ponyfill.fetch||fetch,this.v=v,this.parsed=!!parsed}async sendMessage(phoneID,to,message,context){const type=message._type,request={messaging_product:"whatsapp",type,to};request[type]=message._build(),context&&(request.context={message_id:context});const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(request)}),response=this.parsed?await(await promise).json():void 0,args={phoneID,to,type,message,request,id:response&&"messages"in response?response.messages[0].id:void 0,response};return this.offload(this.on?.sent,args),response??promise}async broadcastMessage(phoneID,to,message,batch_size=50,delay=1e3){const responses=[];if(batch_size<1)throw new RangeError("batch_size must be greater than 0");if(delay<0)throw new RangeError("delay must be greater or equal to 0");for(let i=0;i<to.length;i+=batch_size){i!==0&&await new Promise(resolve=>setTimeout(resolve,delay));for(const u of to.slice(i,i+batch_size))responses.push(this.sendMessage(phoneID,u,message))}return responses}async markAsRead(phoneID,messageId){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify({messaging_product:"whatsapp",status:"read",message_id:messageId})});return this.getBody(promise)}async createQR(phoneID,message,format="png"){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls?generate_qr_image=${format}&prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id??""}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async updateQR(phoneID,id,message){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}?prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async deleteQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async uploadMedia(phoneID,form,check=!0){if(check){if(!form||typeof form!="object"||!("get"in form)||typeof form.get!="function")throw new TypeError("File's Form must be an instance of FormData");const file=form.get("file");if(!file.type)throw new Error("File's Blob must have a type specified");if(!["audio/aac","audio/mp4","audio/mpeg","audio/amr","audio/ogg","text/plain","application/pdf","application/vnd.ms-powerpoint","application/msword","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","video/mp4","video/3gp","image/webp"].includes(file.type))throw new Error(`Invalid media type: ${file.type}`);const validMediaSizes={audio:16e6,text:1e8,application:1e8,image:5e6,video:16e6,sticker:5e5},mediaType=file.type==="image/webp"?"sticker":file.type.split("/")[0];if(file.size&&file.size>validMediaSizes[mediaType])throw new Error(`File is too big (${file.size} bytes) for a ${mediaType} (${validMediaSizes[mediaType]} bytes limit)`)}const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/media?messaging_product=whatsapp`,{method:"POST",body:form,headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"multipart/form-data"}});return this.getBody(promise)}fetchMedia(url){return this._authenicatedRequest(new URL(url))}async deleteMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async post(data,raw_body,signature){if(this.secure){if(!this.appSecret)throw 500;if(!this.subtle)throw 501;if(!raw_body)throw 400;if(signature=signature?.split("sha256=")[1],!signature)throw 401;const encoder=new TextEncoder,keyBuffer=encoder.encode(this.appSecret),key=await this.subtle.importKey("raw",keyBuffer,{name:"HMAC",hash:"SHA-256"},!0,["sign","verify"]),data2=encoder.encode(raw_body),result=await this.subtle.sign("HMAC",key,data2.buffer),check=Array.from(new Uint8Array(result)).map(b=>b.toString(16).padStart(2,"0")).join("");if(signature!==check)throw 401}if(!data.object)throw 400;const value=data.entry[0].changes[0].value,phoneID=value.metadata.phone_number_id;if("messages"in value){const message=value.messages[0],contact=value.contacts?.[0],from=contact?.wa_id??message.from,name=contact?.profile.name,args={phoneID,from,message,name,raw:data};this.offload(this.on?.message,args)}else if("statuses"in value){const statuses=value.statuses[0],phone=statuses.recipient_id,status=statuses.status,id=statuses.id,conversation=statuses.conversation,pricing=statuses.pricing,error=statuses.errors?.[0],args={phoneID,phone,status,id,conversation,pricing,error,raw:data};this.offload(this.on?.status,args)}return 200}get(params){if(!this.webhookVerifyToken)throw 500;const{"hub.mode":mode,"hub.verify_token":token,"hub.challenge":challenge}=params;if(!mode||!token)throw 400;if(mode==="subscribe"&&token===this.webhookVerifyToken)return challenge;throw 403}_authenicatedRequest(url){if(!url)throw new Error("URL must be specified");return this.fetch(url,{headers:{Authorization:`Bearer ${this.token}`}})}async getBody(promise){return this.parsed?await(await promise).json():promise}offload(f,...a){f&&Promise.resolve().then(()=>f(...a))}} | ||
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{default:()=>WhatsAppAPI});module.exports=__toCommonJS(src_exports);class WhatsAppAPI{token;appSecret;webhookVerifyToken;v;fetch;subtle;parsed;secure;on={};constructor({token,appSecret,webhookVerifyToken,v="v18.0",parsed=!0,secure=!0,ponyfill={}}){if(this.token=token,this.secure=!!secure,this.secure){if(this.appSecret=appSecret,typeof ponyfill.subtle!="object"&&(typeof crypto!="object"||typeof crypto?.subtle!="object"))throw new Error("subtle is not defined in the enviroment. Consider using a setup helper, defined at 'whatsapp-api-js/setup', or provide a valid ponyfill object with the argument 'ponyfill.subtle'.");this.subtle=ponyfill.subtle||crypto.subtle}if(webhookVerifyToken&&(this.webhookVerifyToken=webhookVerifyToken),typeof ponyfill.fetch!="function"&&typeof fetch!="function")throw new Error("fetch is not defined in the enviroment. Consider using a setup helper, defined at 'whatsapp-api-js/setup', or provide a valid ponyfill object with the argument 'ponyfill.fetch'.");this.fetch=ponyfill.fetch||fetch,this.v=v,this.parsed=!!parsed}async sendMessage(phoneID,to,message,context){const type=message._type,request={messaging_product:"whatsapp",type,to};request[type]=message._build(),context&&(request.context={message_id:context});const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(request)}),response=this.parsed?await(await promise).json():void 0,args={phoneID,to,type,message,request,id:response&&"messages"in response?response.messages[0].id:void 0,response};return this.offload(this.on?.sent,args),response??promise}async broadcastMessage(phoneID,to,message,batch_size=50,delay=1e3){const responses=[];if(batch_size<1)throw new RangeError("batch_size must be greater than 0");if(delay<0)throw new RangeError("delay must be greater or equal to 0");for(let i=0;i<to.length;i+=batch_size){i!==0&&await new Promise(resolve=>setTimeout(resolve,delay));for(const u of to.slice(i,i+batch_size))responses.push(this.sendMessage(phoneID,u,message))}return responses}async markAsRead(phoneID,messageId){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify({messaging_product:"whatsapp",status:"read",message_id:messageId})});return this.getBody(promise)}async createQR(phoneID,message,format="png"){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls?generate_qr_image=${format}&prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id??""}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async updateQR(phoneID,id,message){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}?prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async deleteQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async uploadMedia(phoneID,form,check=!0){if(check){if(!form||typeof form!="object"||!("get"in form)||typeof form.get!="function")throw new TypeError("File's Form must be an instance of FormData");const file=form.get("file");if(!file.type)throw new Error("File's Blob must have a type specified");if(!["audio/aac","audio/mp4","audio/mpeg","audio/amr","audio/ogg","text/plain","application/pdf","application/vnd.ms-powerpoint","application/msword","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","video/mp4","video/3gp","image/webp"].includes(file.type))throw new Error(`Invalid media type: ${file.type}`);const validMediaSizes={audio:16e6,text:1e8,application:1e8,image:5e6,video:16e6,sticker:5e5},mediaType=file.type==="image/webp"?"sticker":file.type.split("/")[0];if(file.size&&file.size>validMediaSizes[mediaType])throw new Error(`File is too big (${file.size} bytes) for a ${mediaType} (${validMediaSizes[mediaType]} bytes limit)`)}const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/media?messaging_product=whatsapp`,{method:"POST",body:form,headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"multipart/form-data"}});return this.getBody(promise)}fetchMedia(url){return this._authenicatedRequest(new URL(url))}async deleteMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async post(data,raw_body,signature){if(this.secure){if(!this.appSecret)throw 500;if(!this.subtle)throw 501;if(!raw_body)throw 400;if(signature=signature?.split("sha256=")[1],!signature)throw 401;const encoder=new TextEncoder,keyBuffer=encoder.encode(this.appSecret),key=await this.subtle.importKey("raw",keyBuffer,{name:"HMAC",hash:"SHA-256"},!0,["sign","verify"]),data2=encoder.encode(raw_body),result=await this.subtle.sign("HMAC",key,data2.buffer),check=Array.from(new Uint8Array(result)).map(b=>b.toString(16).padStart(2,"0")).join("");if(signature!==check)throw 401}if(!data.object)throw 400;const value=data.entry[0].changes[0].value,phoneID=value.metadata.phone_number_id;if("messages"in value){const message=value.messages[0],contact=value.contacts?.[0],from=contact?.wa_id??message.from,name=contact?.profile.name,args={phoneID,from,message,name,raw:data};this.offload(this.on?.message,args)}else if("statuses"in value){const statuses=value.statuses[0],phone=statuses.recipient_id,status=statuses.status,id=statuses.id,conversation=statuses.conversation,pricing=statuses.pricing,error=statuses.errors?.[0],args={phoneID,phone,status,id,conversation,pricing,error,raw:data};this.offload(this.on?.status,args)}return 200}get(params){if(!this.webhookVerifyToken)throw 500;const{"hub.mode":mode,"hub.verify_token":token,"hub.challenge":challenge}=params;if(!mode||!token)throw 400;if(mode==="subscribe"&&token===this.webhookVerifyToken)return challenge;throw 403}_authenicatedRequest(url){if(!url)throw new Error("URL must be specified");return this.fetch(url,{headers:{Authorization:`Bearer ${this.token}`}})}async getBody(promise){return this.parsed?await(await promise).json():promise}offload(f,...a){f&&Promise.resolve().then(()=>f(...a))}} | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var interactive_exports={};__export(interactive_exports,{ActionButtons:()=>ActionButtons,ActionCatalog:()=>ActionCatalog,ActionList:()=>ActionList,ActionProduct:()=>ActionProduct,Body:()=>Body,Button:()=>Button,Footer:()=>Footer,Header:()=>Header,Interactive:()=>Interactive,ListSection:()=>ListSection,Row:()=>Row});module.exports=__toCommonJS(interactive_exports);var import_types=require("../types.js"),import_globals=require("./globals.js");class Interactive extends import_types.ClientMessage{action;type;body;header;footer;get _type(){return"interactive"}constructor(action,body,header,footer){if(super(),action._type!=="product"&&!body)throw new Error("Interactive must have a body component");if(action._type==="product"&&header)throw new Error("Interactive must not have a header component if action is a single product");if(action._type==="product_list"&&header?.type!=="text")throw new Error("Interactive must have a text header component if action is a product list");if(header&&action._type!=="button"&&header?.type!=="text")throw new Error("Interactive header must be of type text");this.type=action._type,this.action=action,body&&(this.body=body),header&&(this.header=header),footer&&(this.footer=footer)}}class Body{text;constructor(text){if(text.length>1024)throw new Error("Body text must be less than 1024 characters");this.text=text}}class Footer{text;constructor(text){if(text.length>60)throw new Error("Footer text must be 60 characters or less");this.text=text}}class Header{type;text;image;document;video;constructor(object){if(typeof object=="string"){if(object.length>60)throw new Error("Header text must be 60 characters or less");this.type="text"}else if(this.type=object._type,object.caption)throw new Error(`Header ${this.type} must not have a caption`);this[this.type]=object}}class ActionButtons extends import_types.ClientLimitedMessageComponent{buttons;get _type(){return"button"}constructor(...button){super("Reply buttons","button",button,3);const ids=button.map(b=>b[b.type].id);if(ids.length!==new Set(ids).size)throw new Error("Reply buttons must have unique ids");const titles=button.map(b=>b[b.type].title);if(titles.length!==new Set(titles).size)throw new Error("Reply buttons must have unique titles");this.buttons=button}}class Button{type;reply;constructor(id,title){if(id.length>256)throw new Error("Button id must be 256 characters or less");if(/^ | $/.test(id))throw new Error("Button id cannot have leading or trailing spaces");if(!title.length)throw new Error("Button title cannot be an empty string");if(title.length>20)throw new Error("Button title must be 20 characters or less");this.type="reply",this.reply={title,id}}}class ActionList extends import_types.ClientLimitedMessageComponent{button;sections;get _type(){return"list"}constructor(button,...sections){if(super("Action","sections",sections,10),!button.length)throw new Error("Button content cannot be an empty string");if(button.length>20)throw new Error("Button content must be 20 characters or less");if(sections.length>1&&!sections.every(obj=>!!obj.title))throw new Error("All sections must have a title if more than 1 section is provided");this.button=button,this.sections=sections}}class ListSection extends import_types.Section{rows;constructor(title,...rows){super("ListSection","rows",rows,10,title),this.rows=rows}}class Row{id;title;description;constructor(id,title,description){if(id.length>200)throw new Error("Row id must be 200 characters or less");if(title.length>24)throw new Error("Row title must be 24 characters or less");if(description&&description.length>72)throw new Error("Row description must be 72 characters or less");this.id=id,this.title=title,description&&(this.description=description)}}class ActionCatalog{name;parameters;get _type(){return"catalog_message"}constructor(thumbnail){this.name="catalog_message",thumbnail&&(this.parameters={thumbnail_product_retailer_id:thumbnail.product_retailer_id})}}class ActionProduct{catalog_id;product_retailer_id;sections;get _type(){return this.product_retailer_id?"product":"product_list"}constructor(catalog_id,...products){const is_sections=(0,import_globals.isProductSections)(products);if(is_sections&&products.length>1){if(products.length>10)throw new Error("Catalog must have between 1 and 10 product sections");for(const obj of products)if(!obj.title)throw new Error("All sections must have a title if more than 1 section is provided")}this.catalog_id=catalog_id,is_sections?this.sections=products:this.product_retailer_id=products[0].product_retailer_id}}0&&(module.exports={ActionButtons,ActionCatalog,ActionList,ActionProduct,Body,Button,Footer,Header,Interactive,ListSection,Row}); | ||
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var interactive_exports={};__export(interactive_exports,{ActionButtons:()=>ActionButtons,ActionCatalog:()=>ActionCatalog,ActionList:()=>ActionList,ActionProduct:()=>ActionProduct,Body:()=>Body,Button:()=>Button,Footer:()=>Footer,Header:()=>Header,Interactive:()=>Interactive,ListSection:()=>ListSection,Row:()=>Row});module.exports=__toCommonJS(interactive_exports);var import_types=require("../types.js"),import_globals=require("./globals.js");class Interactive extends import_types.ClientMessage{action;body;header;footer;type;get _type(){return"interactive"}constructor(action,body,header,footer){if(super(),action._type!=="product"&&!body)throw new Error("Interactive must have a body component");if(action._type==="product"&&header)throw new Error("Interactive must not have a header component if action is a single product");if(action._type==="product_list"&&header?.type!=="text")throw new Error("Interactive must have a text header component if action is a product list");if(header&&action._type!=="button"&&header?.type!=="text")throw new Error("Interactive header must be of type text");this.type=action._type,this.action=action,body&&(this.body=body),header&&(this.header=header),footer&&(this.footer=footer)}}class Body{text;constructor(text){if(text.length>1024)throw new Error("Body text must be less than 1024 characters");this.text=text}}class Footer{text;constructor(text){if(text.length>60)throw new Error("Footer text must be 60 characters or less");this.text=text}}class Header{type;text;image;document;video;constructor(object){if(typeof object=="string"){if(object.length>60)throw new Error("Header text must be 60 characters or less");this.type="text"}else if(this.type=object._type,object.caption)throw new Error(`Header ${this.type} must not have a caption`);this[this.type]=object}}class ActionButtons extends import_types.ClientLimitedMessageComponent{buttons;get _type(){return"button"}constructor(...button){super("Reply buttons","button",button,3);const ids=button.map(b=>b[b.type].id);if(ids.length!==new Set(ids).size)throw new Error("Reply buttons must have unique ids");const titles=button.map(b=>b[b.type].title);if(titles.length!==new Set(titles).size)throw new Error("Reply buttons must have unique titles");this.buttons=button}}class Button{type;reply;constructor(id,title){if(id.length>256)throw new Error("Button id must be 256 characters or less");if(/^ | $/.test(id))throw new Error("Button id cannot have leading or trailing spaces");if(!title.length)throw new Error("Button title cannot be an empty string");if(title.length>20)throw new Error("Button title must be 20 characters or less");this.type="reply",this.reply={title,id}}}class ActionList extends import_types.ClientLimitedMessageComponent{button;sections;get _type(){return"list"}constructor(button,...sections){if(super("Action","sections",sections,10),!button.length)throw new Error("Button content cannot be an empty string");if(button.length>20)throw new Error("Button content must be 20 characters or less");if(sections.length>1&&!sections.every(obj=>!!obj.title))throw new Error("All sections must have a title if more than 1 section is provided");this.button=button,this.sections=sections}}class ListSection extends import_types.Section{rows;constructor(title,...rows){super("ListSection","rows",rows,10,title),this.rows=rows}}class Row{id;title;description;constructor(id,title,description){if(id.length>200)throw new Error("Row id must be 200 characters or less");if(title.length>24)throw new Error("Row title must be 24 characters or less");if(description&&description.length>72)throw new Error("Row description must be 72 characters or less");this.id=id,this.title=title,description&&(this.description=description)}}class ActionCatalog{name;parameters;get _type(){return"catalog_message"}constructor(thumbnail){this.name="catalog_message",thumbnail&&(this.parameters={thumbnail_product_retailer_id:thumbnail.product_retailer_id})}}class ActionProduct{catalog_id;product_retailer_id;sections;get _type(){return this.product_retailer_id?"product":"product_list"}constructor(catalog_id,...products){const is_sections=(0,import_globals.isProductSections)(products);if(is_sections&&products.length>1){if(products.length>10)throw new Error("Catalog must have between 1 and 10 product sections");for(const obj of products)if(!obj.title)throw new Error("All sections must have a title if more than 1 section is provided")}this.catalog_id=catalog_id,is_sections?this.sections=products:this.product_retailer_id=products[0].product_retailer_id}}0&&(module.exports={ActionButtons,ActionCatalog,ActionList,ActionProduct,Body,Button,Footer,Header,Interactive,ListSection,Row}); | ||
//# sourceMappingURL=interactive.js.map |
@@ -1,2 +0,2 @@ | ||
class WhatsAppAPI{token;appSecret;webhookVerifyToken;v;fetch;subtle;parsed;secure;on={};constructor({token,appSecret,webhookVerifyToken,v="v18.0",parsed=!0,secure=!0,ponyfill={}}){if(this.token=token,this.secure=!!secure,this.secure){if(this.appSecret=appSecret,typeof ponyfill.subtle!="object"&&(typeof crypto!="object"||typeof crypto?.subtle!="object"))throw new Error("subtle is not defined in the enviroment, please provide a valid ponyfill object with the parameter 'ponyfill.subtle'.");this.subtle=ponyfill.subtle||crypto.subtle}if(webhookVerifyToken&&(this.webhookVerifyToken=webhookVerifyToken),typeof ponyfill.fetch!="function"&&typeof fetch!="function")throw new Error("fetch is not defined in the enviroment, please provide a valid ponyfill function with the parameter 'ponyfill.fetch'.");this.fetch=ponyfill.fetch||fetch,this.v=v,this.parsed=!!parsed}async sendMessage(phoneID,to,message,context){const type=message._type,request={messaging_product:"whatsapp",type,to};request[type]=message._build(),context&&(request.context={message_id:context});const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(request)}),response=this.parsed?await(await promise).json():void 0,args={phoneID,to,type,message,request,id:response&&"messages"in response?response.messages[0].id:void 0,response};return this.offload(this.on?.sent,args),response??promise}async broadcastMessage(phoneID,to,message,batch_size=50,delay=1e3){const responses=[];if(batch_size<1)throw new RangeError("batch_size must be greater than 0");if(delay<0)throw new RangeError("delay must be greater or equal to 0");for(let i=0;i<to.length;i+=batch_size){i!==0&&await new Promise(resolve=>setTimeout(resolve,delay));for(const u of to.slice(i,i+batch_size))responses.push(this.sendMessage(phoneID,u,message))}return responses}async markAsRead(phoneID,messageId){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify({messaging_product:"whatsapp",status:"read",message_id:messageId})});return this.getBody(promise)}async createQR(phoneID,message,format="png"){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls?generate_qr_image=${format}&prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id??""}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async updateQR(phoneID,id,message){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}?prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async deleteQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async uploadMedia(phoneID,form,check=!0){if(check){if(!form||typeof form!="object"||!("get"in form)||typeof form.get!="function")throw new TypeError("File's Form must be an instance of FormData");const file=form.get("file");if(!file.type)throw new Error("File's Blob must have a type specified");if(!["audio/aac","audio/mp4","audio/mpeg","audio/amr","audio/ogg","text/plain","application/pdf","application/vnd.ms-powerpoint","application/msword","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","video/mp4","video/3gp","image/webp"].includes(file.type))throw new Error(`Invalid media type: ${file.type}`);const validMediaSizes={audio:16e6,text:1e8,application:1e8,image:5e6,video:16e6,sticker:5e5},mediaType=file.type==="image/webp"?"sticker":file.type.split("/")[0];if(file.size&&file.size>validMediaSizes[mediaType])throw new Error(`File is too big (${file.size} bytes) for a ${mediaType} (${validMediaSizes[mediaType]} bytes limit)`)}const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/media?messaging_product=whatsapp`,{method:"POST",body:form,headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"multipart/form-data"}});return this.getBody(promise)}fetchMedia(url){return this._authenicatedRequest(new URL(url))}async deleteMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async post(data,raw_body,signature){if(this.secure){if(!this.appSecret)throw 500;if(!this.subtle)throw 501;if(!raw_body)throw 400;if(signature=signature?.split("sha256=")[1],!signature)throw 401;const encoder=new TextEncoder,keyBuffer=encoder.encode(this.appSecret),key=await this.subtle.importKey("raw",keyBuffer,{name:"HMAC",hash:"SHA-256"},!0,["sign","verify"]),data2=encoder.encode(raw_body),result=await this.subtle.sign("HMAC",key,data2.buffer),check=Array.from(new Uint8Array(result)).map(b=>b.toString(16).padStart(2,"0")).join("");if(signature!==check)throw 401}if(!data.object)throw 400;const value=data.entry[0].changes[0].value,phoneID=value.metadata.phone_number_id;if("messages"in value){const message=value.messages[0],contact=value.contacts?.[0],from=contact?.wa_id??message.from,name=contact?.profile.name,args={phoneID,from,message,name,raw:data};this.offload(this.on?.message,args)}else if("statuses"in value){const statuses=value.statuses[0],phone=statuses.recipient_id,status=statuses.status,id=statuses.id,conversation=statuses.conversation,pricing=statuses.pricing,error=statuses.errors?.[0],args={phoneID,phone,status,id,conversation,pricing,error,raw:data};this.offload(this.on?.status,args)}return 200}get(params){if(!this.webhookVerifyToken)throw 500;const{"hub.mode":mode,"hub.verify_token":token,"hub.challenge":challenge}=params;if(!mode||!token)throw 400;if(mode==="subscribe"&&token===this.webhookVerifyToken)return challenge;throw 403}_authenicatedRequest(url){if(!url)throw new Error("URL must be specified");return this.fetch(url,{headers:{Authorization:`Bearer ${this.token}`}})}async getBody(promise){return this.parsed?await(await promise).json():promise}offload(f,...a){f&&Promise.resolve().then(()=>f(...a))}}export{WhatsAppAPI as default}; | ||
class WhatsAppAPI{token;appSecret;webhookVerifyToken;v;fetch;subtle;parsed;secure;on={};constructor({token,appSecret,webhookVerifyToken,v="v18.0",parsed=!0,secure=!0,ponyfill={}}){if(this.token=token,this.secure=!!secure,this.secure){if(this.appSecret=appSecret,typeof ponyfill.subtle!="object"&&(typeof crypto!="object"||typeof crypto?.subtle!="object"))throw new Error("subtle is not defined in the enviroment. Consider using a setup helper, defined at 'whatsapp-api-js/setup', or provide a valid ponyfill object with the argument 'ponyfill.subtle'.");this.subtle=ponyfill.subtle||crypto.subtle}if(webhookVerifyToken&&(this.webhookVerifyToken=webhookVerifyToken),typeof ponyfill.fetch!="function"&&typeof fetch!="function")throw new Error("fetch is not defined in the enviroment. Consider using a setup helper, defined at 'whatsapp-api-js/setup', or provide a valid ponyfill object with the argument 'ponyfill.fetch'.");this.fetch=ponyfill.fetch||fetch,this.v=v,this.parsed=!!parsed}async sendMessage(phoneID,to,message,context){const type=message._type,request={messaging_product:"whatsapp",type,to};request[type]=message._build(),context&&(request.context={message_id:context});const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(request)}),response=this.parsed?await(await promise).json():void 0,args={phoneID,to,type,message,request,id:response&&"messages"in response?response.messages[0].id:void 0,response};return this.offload(this.on?.sent,args),response??promise}async broadcastMessage(phoneID,to,message,batch_size=50,delay=1e3){const responses=[];if(batch_size<1)throw new RangeError("batch_size must be greater than 0");if(delay<0)throw new RangeError("delay must be greater or equal to 0");for(let i=0;i<to.length;i+=batch_size){i!==0&&await new Promise(resolve=>setTimeout(resolve,delay));for(const u of to.slice(i,i+batch_size))responses.push(this.sendMessage(phoneID,u,message))}return responses}async markAsRead(phoneID,messageId){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/messages`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify({messaging_product:"whatsapp",status:"read",message_id:messageId})});return this.getBody(promise)}async createQR(phoneID,message,format="png"){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls?generate_qr_image=${format}&prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id??""}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async updateQR(phoneID,id,message){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}?prefilled_message=${message}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async deleteQR(phoneID,id){const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/message_qrdls/${id}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async retrieveMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async uploadMedia(phoneID,form,check=!0){if(check){if(!form||typeof form!="object"||!("get"in form)||typeof form.get!="function")throw new TypeError("File's Form must be an instance of FormData");const file=form.get("file");if(!file.type)throw new Error("File's Blob must have a type specified");if(!["audio/aac","audio/mp4","audio/mpeg","audio/amr","audio/ogg","text/plain","application/pdf","application/vnd.ms-powerpoint","application/msword","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","video/mp4","video/3gp","image/webp"].includes(file.type))throw new Error(`Invalid media type: ${file.type}`);const validMediaSizes={audio:16e6,text:1e8,application:1e8,image:5e6,video:16e6,sticker:5e5},mediaType=file.type==="image/webp"?"sticker":file.type.split("/")[0];if(file.size&&file.size>validMediaSizes[mediaType])throw new Error(`File is too big (${file.size} bytes) for a ${mediaType} (${validMediaSizes[mediaType]} bytes limit)`)}const promise=this.fetch(`https://graph.facebook.com/${this.v}/${phoneID}/media?messaging_product=whatsapp`,{method:"POST",body:form,headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"multipart/form-data"}});return this.getBody(promise)}fetchMedia(url){return this._authenicatedRequest(new URL(url))}async deleteMedia(id,phoneID){const params=phoneID?`phone_number_id=${phoneID}`:"",promise=this.fetch(`https://graph.facebook.com/${this.v}/${id}?${params}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.token}`}});return this.getBody(promise)}async post(data,raw_body,signature){if(this.secure){if(!this.appSecret)throw 500;if(!this.subtle)throw 501;if(!raw_body)throw 400;if(signature=signature?.split("sha256=")[1],!signature)throw 401;const encoder=new TextEncoder,keyBuffer=encoder.encode(this.appSecret),key=await this.subtle.importKey("raw",keyBuffer,{name:"HMAC",hash:"SHA-256"},!0,["sign","verify"]),data2=encoder.encode(raw_body),result=await this.subtle.sign("HMAC",key,data2.buffer),check=Array.from(new Uint8Array(result)).map(b=>b.toString(16).padStart(2,"0")).join("");if(signature!==check)throw 401}if(!data.object)throw 400;const value=data.entry[0].changes[0].value,phoneID=value.metadata.phone_number_id;if("messages"in value){const message=value.messages[0],contact=value.contacts?.[0],from=contact?.wa_id??message.from,name=contact?.profile.name,args={phoneID,from,message,name,raw:data};this.offload(this.on?.message,args)}else if("statuses"in value){const statuses=value.statuses[0],phone=statuses.recipient_id,status=statuses.status,id=statuses.id,conversation=statuses.conversation,pricing=statuses.pricing,error=statuses.errors?.[0],args={phoneID,phone,status,id,conversation,pricing,error,raw:data};this.offload(this.on?.status,args)}return 200}get(params){if(!this.webhookVerifyToken)throw 500;const{"hub.mode":mode,"hub.verify_token":token,"hub.challenge":challenge}=params;if(!mode||!token)throw 400;if(mode==="subscribe"&&token===this.webhookVerifyToken)return challenge;throw 403}_authenicatedRequest(url){if(!url)throw new Error("URL must be specified");return this.fetch(url,{headers:{Authorization:`Bearer ${this.token}`}})}async getBody(promise){return this.parsed?await(await promise).json():promise}offload(f,...a){f&&Promise.resolve().then(()=>f(...a))}}export{WhatsAppAPI as default}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{ClientMessage,ClientLimitedMessageComponent,Section}from"../types.js";import{isProductSections}from"./globals.js";class Interactive extends ClientMessage{action;type;body;header;footer;get _type(){return"interactive"}constructor(action,body,header,footer){if(super(),action._type!=="product"&&!body)throw new Error("Interactive must have a body component");if(action._type==="product"&&header)throw new Error("Interactive must not have a header component if action is a single product");if(action._type==="product_list"&&header?.type!=="text")throw new Error("Interactive must have a text header component if action is a product list");if(header&&action._type!=="button"&&header?.type!=="text")throw new Error("Interactive header must be of type text");this.type=action._type,this.action=action,body&&(this.body=body),header&&(this.header=header),footer&&(this.footer=footer)}}class Body{text;constructor(text){if(text.length>1024)throw new Error("Body text must be less than 1024 characters");this.text=text}}class Footer{text;constructor(text){if(text.length>60)throw new Error("Footer text must be 60 characters or less");this.text=text}}class Header{type;text;image;document;video;constructor(object){if(typeof object=="string"){if(object.length>60)throw new Error("Header text must be 60 characters or less");this.type="text"}else if(this.type=object._type,object.caption)throw new Error(`Header ${this.type} must not have a caption`);this[this.type]=object}}class ActionButtons extends ClientLimitedMessageComponent{buttons;get _type(){return"button"}constructor(...button){super("Reply buttons","button",button,3);const ids=button.map(b=>b[b.type].id);if(ids.length!==new Set(ids).size)throw new Error("Reply buttons must have unique ids");const titles=button.map(b=>b[b.type].title);if(titles.length!==new Set(titles).size)throw new Error("Reply buttons must have unique titles");this.buttons=button}}class Button{type;reply;constructor(id,title){if(id.length>256)throw new Error("Button id must be 256 characters or less");if(/^ | $/.test(id))throw new Error("Button id cannot have leading or trailing spaces");if(!title.length)throw new Error("Button title cannot be an empty string");if(title.length>20)throw new Error("Button title must be 20 characters or less");this.type="reply",this.reply={title,id}}}class ActionList extends ClientLimitedMessageComponent{button;sections;get _type(){return"list"}constructor(button,...sections){if(super("Action","sections",sections,10),!button.length)throw new Error("Button content cannot be an empty string");if(button.length>20)throw new Error("Button content must be 20 characters or less");if(sections.length>1&&!sections.every(obj=>!!obj.title))throw new Error("All sections must have a title if more than 1 section is provided");this.button=button,this.sections=sections}}class ListSection extends Section{rows;constructor(title,...rows){super("ListSection","rows",rows,10,title),this.rows=rows}}class Row{id;title;description;constructor(id,title,description){if(id.length>200)throw new Error("Row id must be 200 characters or less");if(title.length>24)throw new Error("Row title must be 24 characters or less");if(description&&description.length>72)throw new Error("Row description must be 72 characters or less");this.id=id,this.title=title,description&&(this.description=description)}}class ActionCatalog{name;parameters;get _type(){return"catalog_message"}constructor(thumbnail){this.name="catalog_message",thumbnail&&(this.parameters={thumbnail_product_retailer_id:thumbnail.product_retailer_id})}}class ActionProduct{catalog_id;product_retailer_id;sections;get _type(){return this.product_retailer_id?"product":"product_list"}constructor(catalog_id,...products){const is_sections=isProductSections(products);if(is_sections&&products.length>1){if(products.length>10)throw new Error("Catalog must have between 1 and 10 product sections");for(const obj of products)if(!obj.title)throw new Error("All sections must have a title if more than 1 section is provided")}this.catalog_id=catalog_id,is_sections?this.sections=products:this.product_retailer_id=products[0].product_retailer_id}}export{ActionButtons,ActionCatalog,ActionList,ActionProduct,Body,Button,Footer,Header,Interactive,ListSection,Row}; | ||
import{ClientMessage,ClientLimitedMessageComponent,Section}from"../types.js";import{isProductSections}from"./globals.js";class Interactive extends ClientMessage{action;body;header;footer;type;get _type(){return"interactive"}constructor(action,body,header,footer){if(super(),action._type!=="product"&&!body)throw new Error("Interactive must have a body component");if(action._type==="product"&&header)throw new Error("Interactive must not have a header component if action is a single product");if(action._type==="product_list"&&header?.type!=="text")throw new Error("Interactive must have a text header component if action is a product list");if(header&&action._type!=="button"&&header?.type!=="text")throw new Error("Interactive header must be of type text");this.type=action._type,this.action=action,body&&(this.body=body),header&&(this.header=header),footer&&(this.footer=footer)}}class Body{text;constructor(text){if(text.length>1024)throw new Error("Body text must be less than 1024 characters");this.text=text}}class Footer{text;constructor(text){if(text.length>60)throw new Error("Footer text must be 60 characters or less");this.text=text}}class Header{type;text;image;document;video;constructor(object){if(typeof object=="string"){if(object.length>60)throw new Error("Header text must be 60 characters or less");this.type="text"}else if(this.type=object._type,object.caption)throw new Error(`Header ${this.type} must not have a caption`);this[this.type]=object}}class ActionButtons extends ClientLimitedMessageComponent{buttons;get _type(){return"button"}constructor(...button){super("Reply buttons","button",button,3);const ids=button.map(b=>b[b.type].id);if(ids.length!==new Set(ids).size)throw new Error("Reply buttons must have unique ids");const titles=button.map(b=>b[b.type].title);if(titles.length!==new Set(titles).size)throw new Error("Reply buttons must have unique titles");this.buttons=button}}class Button{type;reply;constructor(id,title){if(id.length>256)throw new Error("Button id must be 256 characters or less");if(/^ | $/.test(id))throw new Error("Button id cannot have leading or trailing spaces");if(!title.length)throw new Error("Button title cannot be an empty string");if(title.length>20)throw new Error("Button title must be 20 characters or less");this.type="reply",this.reply={title,id}}}class ActionList extends ClientLimitedMessageComponent{button;sections;get _type(){return"list"}constructor(button,...sections){if(super("Action","sections",sections,10),!button.length)throw new Error("Button content cannot be an empty string");if(button.length>20)throw new Error("Button content must be 20 characters or less");if(sections.length>1&&!sections.every(obj=>!!obj.title))throw new Error("All sections must have a title if more than 1 section is provided");this.button=button,this.sections=sections}}class ListSection extends Section{rows;constructor(title,...rows){super("ListSection","rows",rows,10,title),this.rows=rows}}class Row{id;title;description;constructor(id,title,description){if(id.length>200)throw new Error("Row id must be 200 characters or less");if(title.length>24)throw new Error("Row title must be 24 characters or less");if(description&&description.length>72)throw new Error("Row description must be 72 characters or less");this.id=id,this.title=title,description&&(this.description=description)}}class ActionCatalog{name;parameters;get _type(){return"catalog_message"}constructor(thumbnail){this.name="catalog_message",thumbnail&&(this.parameters={thumbnail_product_retailer_id:thumbnail.product_retailer_id})}}class ActionProduct{catalog_id;product_retailer_id;sections;get _type(){return this.product_retailer_id?"product":"product_list"}constructor(catalog_id,...products){const is_sections=isProductSections(products);if(is_sections&&products.length>1){if(products.length>10)throw new Error("Catalog must have between 1 and 10 product sections");for(const obj of products)if(!obj.title)throw new Error("All sections must have a title if more than 1 section is provided")}this.catalog_id=catalog_id,is_sections?this.sections=products:this.product_retailer_id=products[0].product_retailer_id}}export{ActionButtons,ActionCatalog,ActionList,ActionProduct,Body,Button,Footer,Header,Interactive,ListSection,Row}; | ||
//# sourceMappingURL=interactive.js.map |
@@ -16,6 +16,2 @@ import { ClientMessage, ClientLimitedMessageComponent, Section, type InteractiveAction } from "../types.js"; | ||
/** | ||
* The type of the interactive message | ||
*/ | ||
readonly type: InteractiveAction["_type"]; | ||
/** | ||
* The body component of the interactive message | ||
@@ -33,2 +29,6 @@ */ | ||
/** | ||
* The type of the interactive message | ||
*/ | ||
readonly type: InteractiveAction["_type"]; | ||
/** | ||
* @override | ||
@@ -42,5 +42,5 @@ * @internal | ||
* @param action - The action component of the interactive message | ||
* @param body - The body component of the interactive message | ||
* @param header - The header component of the interactive message | ||
* @param footer - The footer component of the interactive message | ||
* @param body - The body component of the interactive message, it may be undefined if not needed. | ||
* @param header - The header component of the interactive message, it may be undefined if not needed. | ||
* @param footer - The footer component of the interactive message, it may be undefined if not needed. | ||
* @throws If body is not provided, unless action is an {@link ActionProduct} with a single product | ||
@@ -47,0 +47,0 @@ * @throws If header is provided for an {@link ActionProduct} with a single product |
@@ -472,3 +472,3 @@ /** | ||
}; | ||
export type ServerMessageTypes = ServerTextMessage | ServerAudioMessage | ServerDocumentMessage | ServerImageMessage | ServerStickerMessage | ServerVideoMessage | ServerLocationMessage | ServerContactsMessage | ServerInteractiveMessage | ServerButtonMessage | ServerReactionMessage | ServerOrderMessage | ServerUnknownMessage; | ||
export type ServerMessageTypes = ServerTextMessage | ServerAudioMessage | ServerDocumentMessage | ServerImageMessage | ServerStickerMessage | ServerVideoMessage | ServerLocationMessage | ServerContactsMessage | ServerInteractiveMessage | ServerButtonMessage | ServerReactionMessage | ServerOrderMessage | ServerSystemMessage | ServerUnknownMessage; | ||
export type ServerMessage = { | ||
@@ -490,16 +490,25 @@ from: string; | ||
acknowledged: boolean; | ||
created_timestamp: number; | ||
created_timestamp: string; | ||
hash: string; | ||
}; | ||
/** | ||
* Never saw this property on the wild, but it's documented | ||
*/ | ||
errors?: [ServerError]; | ||
referral?: { | ||
source_url: string; | ||
source_id: string; | ||
source_type: string; | ||
source_type: "ad" | "post"; | ||
headline: string; | ||
body: string; | ||
media_type: string; | ||
ctwa_clid: string; | ||
media_type: "image" | "video"; | ||
} & ({ | ||
media_type: "image"; | ||
image_url: string; | ||
} | { | ||
media_type: "video"; | ||
video_url: string; | ||
thumbnail_url: string; | ||
}; | ||
}); | ||
} & ServerMessageTypes; | ||
@@ -512,7 +521,10 @@ export type ServerContacts = { | ||
}; | ||
export type ServerInitiation = "user_initiated" | "business_initated" | "referral_conversion"; | ||
export type ServerStatus = "sent" | "delivered" | "read" | "failed" | "deleted"; | ||
export type ServerInitiation = "authentication" | "marketing" | "utility" | "service" | "referral_conversion"; | ||
export type ServerStatus = "sent" | "delivered" | "read" | "failed"; | ||
export type ServerPricing = { | ||
pricing_model: "CBP"; | ||
billable: boolean; | ||
/** | ||
* @deprecated Since v16 with the release of the new pricing model | ||
*/ | ||
billable?: boolean; | ||
category: ServerInitiation; | ||
@@ -528,4 +540,8 @@ }; | ||
export type ServerError = { | ||
code: string; | ||
code: number; | ||
title: string; | ||
message: string; | ||
error_data: { | ||
details: string; | ||
}; | ||
}; | ||
@@ -532,0 +548,0 @@ export type GetParams = { |
{ | ||
"name": "whatsapp-api-js", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"author": "Secreto31126", | ||
@@ -138,5 +138,5 @@ "description": "A TypeScript server agnostic Whatsapp's Official API framework", | ||
"@types/express": "^4.17.17", | ||
"@types/node": "18.17.17", | ||
"@typescript-eslint/eslint-plugin": "6.7.0", | ||
"@typescript-eslint/parser": "6.7.0", | ||
"@types/node": "18.18.1", | ||
"@typescript-eslint/eslint-plugin": "6.7.3", | ||
"@typescript-eslint/parser": "6.7.3", | ||
"@vercel/node": "^3.0.4", | ||
@@ -147,6 +147,6 @@ "all-contributors-cli": "^6.26.1", | ||
"esbuild": "0.19.0", | ||
"eslint": "8.49.0", | ||
"eslint": "8.50.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-tsdoc": "0.2.17", | ||
"glob": "10.3.4", | ||
"glob": "10.3.10", | ||
"mocha": "10.2.0", | ||
@@ -157,4 +157,4 @@ "prettier": "3.0.3", | ||
"typescript": "5.2.2", | ||
"undici": "5.24.0" | ||
"undici": "5.25.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
561703
3580