whatsapp-api-js
Advanced tools
Comparing version 0.1.2 to 0.1.3
50
index.js
@@ -11,3 +11,5 @@ const { Contacts } = require('./types/contacts'); | ||
/** | ||
* The main class | ||
* @typedef {Object} WhatsAppAPI The main API object | ||
* @property {String} token The API token | ||
* @property {String} v The API version to use | ||
*/ | ||
@@ -65,3 +67,47 @@ class WhatsAppAPI { | ||
/** | ||
* Document this please | ||
* @namespace Exports | ||
* @property {WhatsAppAPI} WhatsAppAPI The main API object | ||
* @property {Object} Handlers The handlers object | ||
* @property {Function} Handlers.post The post handler | ||
* @property {Function} Handlers.get The get handler | ||
* @property {Object} Types The API types objects | ||
* @property {Object} Types.Contacts The Contacts module | ||
* @property {Contacts} Types.Contacts.Contacts The API Contacts type object | ||
* @property {Address} Types.Contacts.Address The API Address type object | ||
* @property {Birthday} Types.Contacts.Birthday The API Birthday type object | ||
* @property {Email} Types.Contacts.Email The API Email type object | ||
* @property {Name} Types.Contacts.Name The API Name type object | ||
* @property {Organization} Types.Contacts.Organization The API Organization type object | ||
* @property {Phone} Types.Contacts.Phone The API Phone type object | ||
* @property {Url} Types.Contacts.Url The API Url type object | ||
* @property {Object} Types.Interactive The Interactive module | ||
* @property {Interactive} Types.Interactive.Interactive The API Interactive type object | ||
* @property {Body} Types.Interactive.Body The API Body type object | ||
* @property {Footer} Types.Interactive.Footer The API Footer type object | ||
* @property {Header} Types.Interactive.Header The API Header type object | ||
* @property {ActionList} Types.Interactive.ActionList The API Action type object | ||
* @property {Section} Types.Interactive.Section The API Section type object | ||
* @property {Row} Types.Interactive.Row The API Row type object | ||
* @property {ActionButtons} Types.Interactive.ActionButtons The API Action type object | ||
* @property {Button} Types.Interactive.Button The API Button type object | ||
* @property {Location} Types.Location The API Location type object | ||
* @property {Object} Types.Media The Media module | ||
* @property {Media} Types.Media.Media Placeholder, don't use | ||
* @property {Audio} Types.Media.Audio The API Audio type object | ||
* @property {Document} Types.Media.Document The API Document type object | ||
* @property {Image} Types.Media.Image The API Image type object | ||
* @property {Sticker} Types.Media.Sticker The API Sticker type object | ||
* @property {Video} Types.Media.Video The API Video type object | ||
* @property {Object} Types.Template The Template module | ||
* @property {Template} Types.Template.Template The API Template type object | ||
* @property {Language} Types.Template.Language The API Language type object | ||
* @property {ButtonComponent} Types.Template.ButtonComponent The API ButtonComponent type object | ||
* @property {UrlButton} Types.Template.UrlButton The API UrlButton type object | ||
* @property {PayloadButton} Types.Template.PayloadButton The API PayloadButton type object | ||
* @property {HeaderComponent} Types.Template.HeaderComponent The API HeaderComponent type object | ||
* @property {BodyComponent} Types.Template.BodyComponent The API BodyComponent type object | ||
* @property {Parameter} Types.Template.Parameter The API Parameter type object | ||
* @property {Currency} Types.Template.Currency The API Currency type object | ||
* @property {DateTime} Types.Template.DateTime The API DateTime type object | ||
* @property {Text} Types.Text The API Text type object | ||
*/ | ||
@@ -68,0 +114,0 @@ module.exports = { |
{ | ||
"name": "whatsapp-api-js", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A Whatsapp Official API helper for Node.js", | ||
@@ -8,3 +8,5 @@ "main": "index.js", | ||
"test": "node --inspect test.js", | ||
"debug": "node --inspect index.js" | ||
"debug": "node --inspect index.js", | ||
"document": "./node_modules/.bin/jsdoc -d ./documentation -t ./node_modules/docdash -R ./README.md . ./types", | ||
"win-document": ".\\node_modules\\.bin\\jsdoc -d ./documentation -t ./node_modules/docdash -R ./README.md . ./types" | ||
}, | ||
@@ -26,4 +28,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"docdash": "^1.2.0", | ||
"jsdoc": "^3.6.10" | ||
} | ||
} |
@@ -87,2 +87,7 @@ # whatsapp-api-js | ||
## Documentation | ||
The package documentation is available in [whatsappapijs.web.app](https://whatsappapijs.web.app/). | ||
Contacts and Interactive are still missing some documentation, will be added soon. | ||
## Comments | ||
@@ -89,0 +94,0 @@ |
@@ -5,2 +5,3 @@ /** | ||
* | ||
* @ignore | ||
* @param {Object} params The GET request parameters in object format | ||
@@ -34,2 +35,3 @@ * @param {String} verify_token The verification token | ||
* | ||
* @ignore | ||
* @param {Object} data The post data sent by Whatsapp, already parsed to object | ||
@@ -36,0 +38,0 @@ * @param {Function} callback The function to be called if the post request is valid. The callback is called with the bot's phoneID {String}, the user's phone number {String}, the messages object {Object}, the username {String}, and last the raw data from the API {Object} |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Contacts API object | ||
* | ||
* @property {Array<Object>} contacts The contacts of the message | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Contacts { | ||
@@ -117,7 +123,7 @@ /** | ||
* @param {String} formatted_name Full name, as it normally appears | ||
* @param {(String|void)} first_name First name | ||
* @param {(String|void)} last_name Last name | ||
* @param {(String|void)} middle_name Middle name | ||
* @param {(String|void)} suffix Name suffix | ||
* @param {(String|void)} prefix Name prefix | ||
* @param {String} [first_name] First name | ||
* @param {String} [last_name] Last name | ||
* @param {String} [middle_name] Middle name | ||
* @param {String} [suffix] Name suffix | ||
* @param {String} [prefix] Name prefix | ||
* @throws {Error} If formatted_name is not defined | ||
@@ -124,0 +130,0 @@ * @throws {Error} If no other component apart from formatted_name is defined |
const Text = require("./text"); | ||
const { Image, Document, Video } = require("./media"); | ||
/** | ||
* Interactive API object | ||
* | ||
* @property {(ActionList|ActionButtons)} action The action component of the interactive message | ||
* @property {Body} body The body component of the interactive message | ||
* @property {Header} [header] The header component of the interactive message | ||
* @property {Footer} [footer] The footer component of the interactive message | ||
* @property {String} _ The type of the interactive message, for internal use only | ||
*/ | ||
class Interactive { | ||
@@ -10,4 +19,4 @@ /** | ||
* @param {Body} body The body component of the interactive message | ||
* @param {(Header|Void)} header The header component of the interactive message | ||
* @param {(Footer|Void)} footer The footer component of the interactive message | ||
* @param {Header} [header] The header component of the interactive message | ||
* @param {Footer} [footer] The footer component of the interactive message | ||
* @throws {Error} If action is not provided | ||
@@ -149,3 +158,3 @@ * @throws {Error} If body is not provided | ||
* @param {String} title The title of the row. Maximum length: 24 characters. | ||
* @param {(String|Void)} description The description of the row. Maximum length: 72 characters. | ||
* @param {String} [description] The description of the row. Maximum length: 72 characters. | ||
* @throws {Error} If id is not provided | ||
@@ -152,0 +161,0 @@ * @throws {Error} If id is over 200 characters |
@@ -1,2 +0,11 @@ | ||
class Location { | ||
/** | ||
* Location API component | ||
* | ||
* @property {Number} latitude The latitude of the location | ||
* @property {Number} longitude The longitude of the location | ||
* @property {String} [name] The name of the location | ||
* @property {String} [address] The address of the location | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Location { | ||
/** | ||
@@ -7,4 +16,4 @@ * Create a Location object for the API | ||
* @param {Number} latitude Latitude of the location | ||
* @param {(String|Void)} name Name of the location | ||
* @param {(String|Void)} address Address of the location, only displayed if name is present | ||
* @param {String} [name] Name of the location | ||
* @param {String} [address] Address of the location, only displayed if name is present | ||
*/ | ||
@@ -11,0 +20,0 @@ constructor(longitude, latitude, name, address) { |
@@ -0,1 +1,9 @@ | ||
/** | ||
* Placeholder class for all the media types | ||
* | ||
* @property {String} type The type of the media | ||
* @property {String} [id] The id of the media | ||
* @property {String} [link] The link of the media | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Media { | ||
@@ -22,2 +30,4 @@ /** | ||
/** | ||
* Audio API component | ||
* | ||
* @extends Media | ||
@@ -39,3 +49,7 @@ */ | ||
/** | ||
* Document API component | ||
* | ||
* @extends Media | ||
* @property {String} [caption] The file's caption | ||
* @property {String} [filename] The file's filename | ||
*/ | ||
@@ -48,4 +62,4 @@ class Document extends Media { | ||
* @param {Boolean} isItAnID Whether document is an id (true) or a link (false) | ||
* @param {(String|Void)} caption Describes the specified document media | ||
* @param {(String|Void)} filename Describes the filename for the specific document | ||
* @param {String} [caption] Describes the specified document media | ||
* @param {String} [filename] Describes the filename for the specific document | ||
*/ | ||
@@ -61,3 +75,6 @@ constructor(document, isItAnID = false, caption, filename) { | ||
/** | ||
* Image API component | ||
* | ||
* @extends Media | ||
* @property {String} [caption] The file's caption | ||
*/ | ||
@@ -70,3 +87,3 @@ class Image extends Media { | ||
* @param {Boolean} isItAnID Whether document is an id (true) or a link (false) | ||
* @param {(String|Void)} caption Describes the specified image media | ||
* @param {String} [caption] Describes the specified image media | ||
*/ | ||
@@ -81,2 +98,4 @@ constructor(image, isItAnID = false, caption) { | ||
/** | ||
* Sticker API component | ||
* | ||
* @extends Media | ||
@@ -97,2 +116,4 @@ */ | ||
/** | ||
* Video API component | ||
* | ||
* @extends Media | ||
@@ -99,0 +120,0 @@ */ |
const Text = require("./text"); | ||
const { Image, Document, Video } = require("./media"); | ||
/** | ||
* Template API object | ||
* | ||
* @property {String} name The name of the template | ||
* @property {Language} language The language of the template | ||
* @property {Array<(HeaderComponent|BodyComponent|ButtonComponent)>} [components] The components of the template | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Template { | ||
@@ -10,11 +18,11 @@ /** | ||
* @param {(String|Language)} language The code of the language or locale to use. Accepts both language and language_locale formats (e.g., en and en_US). | ||
* @param {...(HeaderComponent|BodyComponent|ButtonComponent)} component Components objects containing the parameters of the message. For text-based templates, the only supported component is BodyComponent. | ||
* @param {...(HeaderComponent|BodyComponent|ButtonComponent)} components Components objects containing the parameters of the message. For text-based templates, the only supported component is BodyComponent. | ||
* @throws {Error} If name is not provided | ||
* @throws {Error} If language is not provided | ||
*/ | ||
constructor(name, language, ...component) { | ||
constructor(name, language, ...components) { | ||
if (!name) throw new Error("Template must have a name"); | ||
if (!language) throw new Error("Template must have a language"); | ||
const indexes = component.filter(e => e instanceof ButtonComponent).map(e => e.index); | ||
const indexes = components.filter(e => e instanceof ButtonComponent).map(e => e.index); | ||
if (indexes.length !== new Set(indexes).size) throw new Error("ButtonComponents must have unique ids"); | ||
@@ -24,3 +32,3 @@ | ||
this.language = language instanceof Language ? language : new Language(language); | ||
if (component) this.components = component; | ||
if (components) this.components = components; | ||
@@ -31,2 +39,8 @@ this._ = "template"; | ||
/** | ||
* Language API object | ||
* | ||
* @property {String} code The code of the language or locale to use. Accepts both language and language_locale formats (e.g., en and en_US). | ||
* @property {String} policy The language policy | ||
*/ | ||
class Language { | ||
@@ -48,4 +62,60 @@ /** | ||
/** | ||
* Template Component | ||
* Currency API object | ||
* | ||
* @property {Number} amount_1000 The amount of the currency by 1000 | ||
* @property {String} code The currency code | ||
* @property {String} fallback_value The fallback value | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Currency { | ||
/** | ||
* Builds a currency object for a Parameter | ||
* | ||
* @param {Number} amount_1000 Amount multiplied by 1000 | ||
* @param {String} code Currency code as defined in ISO 4217 | ||
* @param {String} fallback_value Default text if localization fails | ||
* @throws {Error} If amount_1000 is not provided | ||
* @throws {Error} If code is not provided | ||
* @throws {Error} If fallback_value is not provided | ||
*/ | ||
constructor(amount_1000, code, fallback_value) { | ||
if (!amount_1000 && amount_1000 !== 0) throw new Error("Currency must have an amount_1000"); | ||
if (!code) throw new Error("Currency must have a code"); | ||
if (!fallback_value) throw new Error("Currency must have a fallback_value"); | ||
this.amount_1000 = amount_1000; | ||
this.code = code; | ||
this.fallback_value = fallback_value; | ||
this._ = "currency"; | ||
} | ||
} | ||
/** | ||
* DateTime API object | ||
* | ||
* @property {String} fallback_value The fallback value | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class DateTime { | ||
/** | ||
* Builds a date_time object for a Parameter | ||
* | ||
* @param {String} fallback_value Default text. For Cloud API, we always use the fallback value, and we do not attempt to localize using other optional fields. | ||
* @throws {Error} If fallback_value is not provided | ||
*/ | ||
constructor(fallback_value) { | ||
if (!fallback_value) throw new Error("Currency must have a fallback_value"); | ||
this.fallback_value = fallback_value; | ||
this._ = "date_time"; | ||
} | ||
} | ||
/** | ||
* Components API object | ||
* | ||
* @property {String} type The type of the component | ||
* @property {String} sub_type The subtype of the component | ||
* @property {String} index The index of the component | ||
* @property {Array<(UrlButton|PayloadButton)>} parameters The parameters of the component | ||
*/ | ||
class ButtonComponent { | ||
@@ -78,3 +148,6 @@ /** | ||
/** | ||
* ButtonComponent Parameter | ||
* Button Parameter API object | ||
* | ||
* @property {String} type The type of the button | ||
* @property {String} text The text of the button | ||
*/ | ||
@@ -96,3 +169,6 @@ class UrlButton { | ||
/** | ||
* ButtonComponent Parameter | ||
* Button Parameter API object | ||
* | ||
* @property {String} type The type of the button | ||
* @property {String} payload The payload of the button | ||
*/ | ||
@@ -114,9 +190,12 @@ class PayloadButton { | ||
/** | ||
* Template Component | ||
* Components API object | ||
* | ||
* @property {String} type The type of the component | ||
* @property {Array<Parameter>} [parameters] The parameters of the component | ||
*/ | ||
class HeaderComponent { | ||
class HeaderComponent { | ||
/** | ||
* Builds a header component for a Template message | ||
* | ||
* @param {...(Text|Currency|DateTime|Image|Document|Video|Parameter)} parameters Parameters of the body component | ||
* @param {...(Text|Currency|DateTime|Image|Document|Video)} parameters Parameters of the body component | ||
*/ | ||
@@ -130,3 +209,6 @@ constructor(...parameters) { | ||
/** | ||
* Template Component | ||
* Components API object | ||
* | ||
* @property {String} type The type of the component | ||
* @property {Array<Parameter>} [parameters] The parameters of the component | ||
*/ | ||
@@ -137,3 +219,3 @@ class BodyComponent { | ||
* | ||
* @param {...(Text|Currency|DateTime|Image|Document|Video|Parameter)} parameters Parameters of the body component | ||
* @param {...(Text|Currency|DateTime|Image|Document|Video)} parameters Parameters of the body component | ||
*/ | ||
@@ -147,3 +229,11 @@ constructor(...parameters) { | ||
/** | ||
* HeaderComponent|BodyComponent parameter | ||
* Parameter API object | ||
* | ||
* @property {String} type The type of the parameter | ||
* @property {String} [text] The text of the parameter | ||
* @property {Currency} [currency] The currency of the parameter | ||
* @property {DateTime} [datetime] The datetime of the parameter | ||
* @property {Image} [image] The image of the parameter | ||
* @property {Document} [document] The document of the parameter | ||
* @property {Video} [video] The video of the parameter | ||
*/ | ||
@@ -168,45 +258,2 @@ class Parameter { | ||
/** | ||
* Parameter parameter | ||
*/ | ||
class Currency { | ||
/** | ||
* Builds a currency object for a Parameter | ||
* | ||
* @param {Number} amount_1000 Amount multiplied by 1000 | ||
* @param {String} code Currency code as defined in ISO 4217 | ||
* @param {String} fallback_value Default text if localization fails | ||
* @throws {Error} If amount_1000 is not provided | ||
* @throws {Error} If code is not provided | ||
* @throws {Error} If fallback_value is not provided | ||
*/ | ||
constructor(amount_1000, code, fallback_value) { | ||
if (!amount_1000 && amount_1000 !== 0) throw new Error("Currency must have an amount_1000"); | ||
if (!code) throw new Error("Currency must have a code"); | ||
if (!fallback_value) throw new Error("Currency must have a fallback_value"); | ||
this.amount_1000 = amount_1000; | ||
this.code = code; | ||
this.fallback_value = fallback_value; | ||
this._ = "currency"; | ||
} | ||
} | ||
/** | ||
* Parameter parameter | ||
*/ | ||
class DateTime { | ||
/** | ||
* Builds a date_time object for a Parameter | ||
* | ||
* @param {String} fallback_value Default text. For Cloud API, we always use the fallback value, and we do not attempt to localize using other optional fields. | ||
* @throws {Error} If fallback_value is not provided | ||
*/ | ||
constructor(fallback_value) { | ||
if (!fallback_value) throw new Error("Currency must have a fallback_value"); | ||
this.fallback_value = fallback_value; | ||
this._ = "date_time"; | ||
} | ||
} | ||
module.exports = { | ||
@@ -213,0 +260,0 @@ Template, |
@@ -1,2 +0,9 @@ | ||
class Text { | ||
/** | ||
* Text API object | ||
* | ||
* @property {String} body Body of the message. Maximum length: 1024 characters. | ||
* @property {Boolean} preview_url Whether to enable preview for the text message | ||
* @property {String} _ The type of the object, for internal use only | ||
*/ | ||
class Text { | ||
/** | ||
@@ -3,0 +10,0 @@ * Create a Text object for the API |
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
52927
18
1071
98
2