whatsapp-api-js
Version:
A TypeScript server agnostic Whatsapp's Official API framework
3 lines (2 loc) • 3.95 kB
JavaScript
;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 contacts_exports={};__export(contacts_exports,{Address:()=>Address,Birthday:()=>Birthday,Contacts:()=>Contacts,Email:()=>Email,Name:()=>Name,Organization:()=>Organization,Phone:()=>Phone,Url:()=>Url});module.exports=__toCommonJS(contacts_exports);var import_types=require("../types.js");class Contacts extends import_types.ClientMessage{component;get _type(){return"contacts"}constructor(...contact){super(),this.component=[];for(const components of contact){const contact2={};for(const component of components){const name=component._type;if(component._many)contact2[name]||Object.defineProperty(contact2,name,{value:[],enumerable:!0}),contact2[name].push(component._build());else{if(contact2[name])throw new Error(`Contact already has a ${name} component and _many is set to false`);contact2[name]=component._build()}}if(!contact2.name)throw new Error("Contact must have a name component");this.component.push(contact2)}}_build(){return JSON.stringify(this.component)}}class Address extends import_types.ContactMultipleComponent{country;country_code;state;city;street;zip;type;get _type(){return"addresses"}constructor(country,country_code,state,city,street,zip,type){super(),country&&(this.country=country),country_code&&(this.country_code=country_code),state&&(this.state=state),city&&(this.city=city),street&&(this.street=street),zip&&(this.zip=zip),type&&(this.type=type)}}class Birthday extends import_types.ContactUniqueComponent{birthday;get _type(){return"birthday"}constructor(year,month,day){if(super(),year.length!==4)throw new Error("Year must be 4 digits");if(month.length!==2)throw new Error("Month must be 2 digits");if(day.length!==2)throw new Error("Day must be 2 digits");this.birthday=`${year}-${month}-${day}`}_build(){return this.birthday}}class Email extends import_types.ContactMultipleComponent{email;type;get _type(){return"emails"}constructor(email,type){super(),email&&(this.email=email),type&&(this.type=type)}}class Name extends import_types.ContactUniqueComponent{formatted_name;first_name;last_name;middle_name;suffix;prefix;get _type(){return"name"}constructor(formatted_name,first_name,last_name,middle_name,suffix,prefix){if(super(),this.formatted_name=formatted_name,first_name&&(this.first_name=first_name),last_name&&(this.last_name=last_name),middle_name&&(this.middle_name=middle_name),suffix&&(this.suffix=suffix),prefix&&(this.prefix=prefix),Object.keys(this).length<2)throw new Error("Name must have at least one of the following: first_name, last_name, middle_name, prefix, suffix")}}class Organization extends import_types.ContactUniqueComponent{company;department;title;get _type(){return"org"}constructor(company,department,title){super(),company&&(this.company=company),department&&(this.department=department),title&&(this.title=title)}}class Phone extends import_types.ContactMultipleComponent{phone;type;wa_id;get _type(){return"phones"}constructor(phone,type,wa_id){super(),phone&&(this.phone=phone),type&&(this.type=type),wa_id&&(this.wa_id=wa_id)}}class Url extends import_types.ContactMultipleComponent{url;type;get _type(){return"urls"}constructor(url,type){super(),url&&(this.url=url),type&&(this.type=type)}}0&&(module.exports={Address,Birthday,Contacts,Email,Name,Organization,Phone,Url});
//# sourceMappingURL=contacts.js.map