npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

waeasyapi

v2.0.0

Published

[![npm](https://img.shields.io/npm/v/waeasyapi.svg?maxAge=2592000?style=flat-square)](https://www.npmjs.com/package/waeasyapi)

Downloads

40

Readme

WA Easy API Node SDK

npm

Official nodejs library for WA Easy API.

Read up here for getting started and understanding messaging flow: https://waeasyapi.com/

Installation

npm i waeasyapi

Documentation

Documentation of WA Easy API's API and their usage is available at https://waeasyapi.com

Basic Usage

Instantiate the waeasyapi instance with acc_id & acc_secret.

You can obtain the keys from the dashboard app (https://waeasyapi.com/).

const WAEasyAPI = require('waeasyapi');

const waInstance = new WAEasyAPI({
  acc_id: 'YOUR_ACC_ID',
  acc_secret: 'YOUR_ACC_SECRET',
});

Available methods (messaging):

// number must start with the country's dialing code

// eg - For USA: 158883993
// eg - For India: 919876543210

// eg - send a text message
const message = 'Hello from WA Easy API';
waInstance.sendTextMessage(number, message);
// eg - send an approved WhatsApp template
const template = 'approved_template_name';

// if there are variables in the template
// eg: "Your order {{1}} for a total of {{2}} is confirmed. The expected delivery is {{3}}."
const params = {
  language: {
      code: 'en',
      policy: 'deterministic'
  },
  components: [{
    type: 'body',
    parameters: [
      { type: 'text', text: 'ORDER_ID_199' }, // for {{1}}
      { type: 'text', text: 'USD 199.00' }, // {{2}}
      { type: 'text', text: 'today' } // {{3}}
    ]
  }]
}

// if there are no variables in the template 
// and it's english template, you can keep params = {} or leave it

waInstance.sendTemplateMessage(number, template, params);
// eg - send a url message with preview
waInstance.sendURLMessage(number, url);

// eg - send an audio message via a http / https url
const params = { link: `your_audio_link` }; // or id: 'uploaded_media_id' - required
waInstance.sendAudioMessage(number, params);

// eg - send an image message via a http / https url
const params = { 
  link: `your_image_link`, // or id: 'uploaded_media_id' - required
  caption: `your_image_caption` // optional
};
waInstance.sendImageMessage(number, params);

// eg - send a video message via a http / https url
const params = { 
  link: `your_video_link`, // or id: 'uploaded_media_id' - required
  caption: `your_video_caption` // optional
};
waInstance.sendVideoMessage(number, params);

// eg - send a document message via a http / https url
const params = { 
  link: `your_document_link`, // or id: 'uploaded_media_id' - required
  filename: `your_document_name` // optional
};
waInstance.sendDocumentMessage(number, params);

// eg - send a sticker message via a http / https url
const params = { 
  id: `uploaded_media_id`, // required - must be uploaded before sending
};
waInstance.sendStickerMessage(number, params);
// eg - send a location message 
const params = {
  longitude: -122.425332, // required
  latitude: 37.758056, // required
  name: 'Facebook HQ', // optional
  address: "1 Hacker Way, Menlo Park, CA 94025" // optional
};
waInstance.sendLocationMessage(number, params);
// eg - send a contact message
const params = [
  {
    name: {
      formatted_name: 'Robin White', // required
      first_name: 'Robin', // optional
      last_name: 'White', // optional
    },

    phones: [{ 
      phone: '+18787878787', // required
      wa_id: '18787878787' // optional
    }],

    emails: [{ email: '[email protected]' }] // optional
  }
];
waInstance.sendContactMessage(number, params);
// eg - send an interactive message 
// const params = {
//   type: 'list', // type = list OR button
//   header: {},
//   body: {},
//   footer: {},
//   action: {}
// };

const params = {
  type: 'list',
  header: {
    type: 'text',
    text: 'WA Easy API - Get Started'
  },
  body: {
    text: "WA Easy API is an official WhatsApp Business API and Messagin Platform."
  },
  footer: {
    text: "Thanks for choosing us."
  },
  action: {
    button: "Continue",
    sections:[
      {
        rows: [
          {
            id: "waeasyapi-basic-monthly",
            title: "WA Easy API - Basic I",
            description: "Best for developers ($49/monthly)",           
          },
          {
            id: "waeasyapi-premium-monthly",
            title: "WA Easy API - Premium I",
            description: "Best for developers and businesses both ($99/monthly)",           
          },
          {
            id: "waeasyapi-basic-yearly",
            title: "WA Easy API - Basic II",
            description: "Best for developers ($499/yearly)",           
          },
          {
            id: "waeasyapi-premium-yearly",
            title: "WA Easy API - Premium II",
            description: "Best for developers and businesses both ($899/yearly)",           
          }
        ]
      }
    ]
  }
};
waInstance.sendInteractiveMessage(number, params);

Available methods (media):


// eg - get your uploaded media
waInstance.getMedia(mediaId);

// eg - upload your media
// send a post (`multipart/form-data`) request with the media on `file` key to
// basic auth is acceptable with acc_id as username & acc_secret as password
// https://api.waeasyapi.com/v1/media/upload

// acceptable content types

// audio - audio/aac, audio/mp4, audio/amr, audio/mpeg, audio/ogg; codecs=opus 
// Note: The base audio/ogg type is not supported.

// document - Any valid MIME-type.

// image - image/jpeg, image/png

// sticker - image/webp

// video - video/mp4, video/3gpp
// Note: Only H.264 video codec and AAC audio codec is supported. 
// Note: Only videos with a single audio stream are supported.

Available methods (profile):


// eg - get your profile photo
waInstance.getProfilePhoto();

// eg - get your profile about
waInstance.getProfileAbout();

// eg - get your business profile
waInstance.getBusinessProfile();

// eg - delete your business photo
waInstance.deleteProfilePhoto();

// eg - change your profile photo
// photo = base64 string of image
waInstance.changeProfilePhoto(photo);

// eg - change your profile about
const about = 'Hey! I\'m using WA Easy API!';
waInstance.changeProfileAbout(about);

// eg - change your business profile
const params = {
  description: 'Official WhatsApp Business APIs & Messaging Platform',
  vertical: 'Professional Services',
  address: 'California, USA',
  email: '[email protected]',
  websites: ['https://waeasyapi.com']
}
waInstance.changeBusinessProfile(params);

// acceptable business verticals are
// const verticals = [
//   'Automotive',
//   'Beauty, Spa and Salon',
//   'Clothing and Apparel',
//   'Education',
//   'Entertainment',
//   'Event Planning and Service',
//   'Finance and Banking',
//   'Food and Grocery',
//   'Public Service',
//   'Hotel and Lodging',
//   'Medical and Health',
//   'Non-profit',
//   'Professional Services',
//   'Shopping and Retail',
//   'Travel and Transportation',
//   'Restaurant',
//   'Other'
// ]

Available methods (template):


// eg - create and submit a WhatsApp template message
const params = {
  name: 'template_name',
  category: 'OTP',
  language: 'en',
  components: [
    { type: 'HEADER', format: 'TEXT', text: 'I am header.' },  // format = TEXT | IMAGE | VIDEO | DOCUMENT
    { type: 'BODY', text: 'I am body.' },
    { type: 'FOOTER', text: 'I am footer.' },
    { 
      type: 'BUTTONS', 
      buttons: [ // for quick reply buttons, type = QUICK_REPLY
        { type: 'PHONE_NUMBER', text: 'Call Us', phone_number: '+18887777877' },
        { type: 'URL', text: 'Visit Website', url: 'https://waeasyapi.com' },
      ]
    },
  ]
}
waInstance.createTemplate(params);

// eg - delete a template 
// (note: your might not be able to delete sample templates)

// templateName = name_of_the_template
waInstance.deleteTemplate(templateName);

// eg - get the list of your templates or sync with facebook
waInstance.getTemplates();

Every resource method returns a promise.

waInstance.sendTextMessage(number, message)
  .then(response => {
    // handle success
  })
  .catch(error => {
    // handle error
  });

If you want to use callbacks instead of promises, every resource method will accept a callback function as a last parameter. The callback functions will behave as Error First Callbacks

waInstance.sendTextMessage(number, message),
  (error, response) => {
    if (error) {
      // handle error
    } else {
      // handle success
    }
  }
);

Example - Node.js

// number must start with the country's dialing code

const WAEasyAPI = require('waeasyapi');

const waInstance = new WAEasyAPI({
  acc_id: 'YOUR_ACC_ID',
  acc_secret: 'YOUR_ACC_SECRET',
});

waInstance.sendTextMessage('19876543210', 'Hello WA Easy API!')
  .then(response => {
    // handle success
  })
  .catch(error => {
    // handle error
  });

Example - Typescript or ESNext

// number must start with the country's dialing code

import WAEasyAPI from 'waeasyapi';

const waInstance = new WAEasyAPI({
  acc_id: 'YOUR_ACC_ID',
  acc_secret: 'YOUR_ACC_SECRET',
});

waInstance.sendTextMessage('19876543210', 'Hello WA Easy API!'),
  (error, response) => {
    if (error) {
      // handle error
    } else {
      // handle success
    }
  }
);

Licence

MIT Licensed. See LICENSE.txt for more details