Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

whatsapp-api-js

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whatsapp-api-js - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

types/interactive.js

5

fetch.js

@@ -11,5 +11,8 @@ const fetch = require('node-fetch');

* @param {Object} object Each type of message requires a specific type of object, for example, the "image" type requires an url and optionally captions. Use the constructors for each specific type of message (contacts, interactive, location, media, template*, text) *TBD
* @returns {Promise} The fetch promise
*/
function messages(token, v, phoneID, to, object) {
const type = object.constructor.name.toLowerCase();
const type = object._;
delete object._;
const body = JSON.stringify({

@@ -16,0 +19,0 @@ messaging_product: "whatsapp",

12

index.js

@@ -1,2 +0,2 @@

const Fetch = require('./fetch').fetch;
const fetch = require('./fetch').fetch;

@@ -22,3 +22,3 @@ class WhatsAppAPI {

* @returns {Promise} The fetch promise
*/
*/
sendMessage(phoneID, to, object) {

@@ -28,3 +28,4 @@ if (!phoneID) throw new Error("Phone ID must be specified");

if (!object) throw new Error("Message must have a message object");
return Fetch.messages(this.token, this.v, phoneID, to, object);
if (!object._) throw new Error("There has been a breaking update in whatsapp-api-js@0.0.4 and @0.1.0, please check the documentation for more information on how to use the new version, or downgrade using 'npm i whatsapp-api-js@0.0.3'. Sorry for any inconvenience :/");
return fetch.messages(this.token, this.v, phoneID, to, object);
}

@@ -34,6 +35,7 @@ }

module.exports = {
WhatsApp: WhatsAppAPI,
Handlers: require('./requests').handlers,
WhatsAppAPI,
Handlers: require('./requests'),
Types: {
Contacts: require('./types/contacts'),
Interactive: require('./types/interactive'),
Location: require('./types/location'),

@@ -40,0 +42,0 @@ Media: require('./types/media'),

{
"name": "whatsapp-api-js",
"version": "0.0.4",
"version": "0.1.0",
"description": "A Whatsapp Official API helper for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,6 +26,4 @@ # whatsapp-api-js

```js
const WhatsAppAPI = require("whatsapp-api-js").WhatsApp;
const Handler = require("whatsapp-api-js").Handlers;
const { WhatsAppAPI, Handlers } = require("whatsapp-api-js");
const { Text, Media, Contacts } = require("whatsapp-api-js").Types;
const { Name, Phones, Birthday } = Contacts;

@@ -39,3 +37,3 @@ const Token = "YOUR_TOKEN";

// The Handlers work with any middleware, as long as you pass the correct data
return Handler.post(JSON.parse(e.data), onMessage);
return Handlers.post(JSON.parse(e.data), onMessage);
}

@@ -50,7 +48,14 @@

if (message.type === "contacts") Whatsapp.sendMessage(phoneID, phone, new Contacts.Contacts([
new Name(name, "First name", "Last name"),
new Phones(phone),
new Birthday("2022", "04", "25"),
]));
if (message.type === "contacts") Whatsapp.sendMessage(phoneID, phone, new Contacts.Contacts(
[
new Contacts.Name(name, "First name", "Last name"),
new Contacts.Phone(phone),
new Contacts.Birthday("2022", "04", "25"),
],
[
new Contacts.Name("John", "First name", "Last name"),
new Contacts.Organization("Company", "Department", "Title"),
new Contacts.Url("https://www.google.com", "WORK"),
]
));
}

@@ -65,3 +70,3 @@ ```

```js
const Handler = require("whatsapp-api-js").Handlers;
const { Handlers } = require("whatsapp-api-js");

@@ -71,3 +76,3 @@ // Assuming get is called on a GET request to your server

// The Handlers work with any middleware, as long as you pass the correct data
return Handler.get(JSON.parse(e.params), "your_verify_token");
return Handlers.get(JSON.parse(e.params), "your_verify_token");
}

@@ -74,0 +79,0 @@ ```

@@ -52,3 +52,3 @@ /**

callback(phoneID, phone, message, name, data);
callback(phoneID, phone, id, message, name, data);

@@ -62,2 +62,2 @@ return 200;

exports.handlers = { get, post };
module.exports = { get, post };

@@ -5,3 +5,3 @@ class Contacts {

*
* @param {...Array} contact Array of contact's components, built using the contact's builder module. They can be: addresses, birthday, emails, name, org, phones and urls.
* @param {...Array} contact Array of contact's components, built using the contact's builder module. They can be: Address, Birthday, Email, Name, Organization, Phone and Url.
*/

@@ -17,3 +17,4 @@ constructor(...contact) {

for (const component of components) {
const name = component.constructor.name.toLowerCase();
const name = component._;
delete component._;

@@ -30,5 +31,7 @@ if (name === "birthday") contact.birthday = component.birthday;

if (!contact.name) throw new Error("Contact must have a name object");
if (!contact.name) throw new Error("Contact must have a name component");
this.contacts.push(contact);
}
this._ = "contacts";
}

@@ -40,3 +43,3 @@ }

*/
class Addresses {
class Address {
/**

@@ -62,2 +65,3 @@ * Builds an address object for a contact.

if (type) this.type = type;
this._ = "addresses";
}

@@ -83,2 +87,3 @@ }

this.birthday = `${year}-${month}-${day}`;
this._ = "birthday";
}

@@ -90,3 +95,3 @@ }

*/
class Emails {
class Email {
/**

@@ -102,2 +107,3 @@ * Builds an email object for a contact.

if (type) this.type = type;
this._ = "emails";
}

@@ -134,2 +140,3 @@ }

if (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");
this._ = "name";
}

@@ -141,3 +148,3 @@ }

*/
class Org {
class Organization {
/**

@@ -154,2 +161,3 @@ * Builds an organization object for a contact

if (title) this.title = title;
this._ = "org";
}

@@ -161,3 +169,3 @@ }

*/
class Phones {
class Phone {
/**

@@ -175,2 +183,3 @@ * Builds a phone object for a contact.

if (wa_id) this.wa_id = wa_id;
this._ = "phones";
}

@@ -182,5 +191,5 @@ }

*/
class Urls {
class Url {
/**
* Builds a url object for a contact.
* Builds an url object for a contact.
* A contact can contain multiple urls.

@@ -194,5 +203,6 @@ *

if (type) this.type = type;
this._ = "urls";
}
}
module.exports = { Contacts, Addresses, Birthday, Emails, Name, Org, Phones, Urls };
module.exports = { Contacts, Address, Birthday, Email, Name, Organization, Phone, Url };

@@ -17,2 +17,3 @@ class Location {

if (address) this.address = address;
this._ = "location";
}

@@ -19,0 +20,0 @@ }

@@ -14,2 +14,3 @@ /**

this[isItAnID ? "id" : "link"] = audio;
this._ = "audio";
}

@@ -35,2 +36,3 @@ }

if (filename) this.filename = filename;
this._ = "document";
}

@@ -54,2 +56,3 @@ }

if (caption) this.caption = caption;
this._ = "image";
}

@@ -70,2 +73,3 @@ }

this.sticker = sticker;
this._ = "sticker";
}

@@ -86,2 +90,3 @@ }

this.video = video;
this._ = "video";
}

@@ -88,0 +93,0 @@ }

@@ -13,2 +13,3 @@ /**

if (preview_url) this.preview_url = preview_url;
this._ = "text";
}

@@ -15,0 +16,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc