Unofficial javascript wrapper to WhatsApp Cloud API.

Overview

heyooh

Ported in Zimbabwe🇿🇼 NPM npm npm

Unofficial javascript wrapper to WhatsApp Cloud API. Its the javascript port for heyoo

Features supported

  1. Sending messages
  2. Sending Media (images, audio, video and ducuments)
  3. Sending location
  4. Sending interactive buttons
  5. Sending template messages

Getting started

To get started with heyooh, you have to firstly install the libary either directly or using npm.

Installation directly

Use git to clone or you can also manually download the project repository just as shown below;

$ git clone https://github.com/JS-Hub-ZW/heyooh
$ cd heyooh

Installing from npm

# For Windows, Linux & Mac

npm install heyooh

Setting up

To get started using this package, you will need TOKEN and TEST WHATSAPP NUMBER which you can get by from Facebook Developer Portal

Here are steps to follow for you to get started

  1. Go to your apps
  2. create an app
  3. Select Bussiness >> Bussiness
  4. It will prompt you to enter basic app informations
  5. It will ask you to add products to your app a. Add WhatsApp Messenger
  6. Right there you will see a your TOKEN and TEST WHATSAPP NUMBER and its phone_number_id
  7. Lastly verify the number you will be using for testing on the To field.

Once you're follow the above procedures, now you're ready to start hacking with the Wrapper.

Authentication

Here how you authenticate your application, you need to specofy two things the TOKEN and phone_number_id of your test number

import {WhatsApp} from 'heyooh'
let messenger = new WhatsApp('TOKEN',  phone_number_id='104xxxxxx')

Once you have authenticated your app, now you can start using the above mentioned feature as shown above;

Sending Messanges

Here how to send messages;

messenger.send_message('Your message ', 'Mobile eg: 255757xxxxx')

Example

Here an example

messenger.send_message('Hi there just testiing', '255757902132')

Sending Images

When sending media(image, video, audio, gif and document ), you can either specify a link containing the media or specify object id, you can do this using the same method.

By default all media methods assume you're sending link containing media but you can change this by specifying the link=False.

Here an example;

messenger.send_image(
        image="https://i.imgur.com/Fh7XVYY.jpeg",
        recipient_id="255757xxxxxx",
)

Sending Video

Here an example;

messenger.send_video(
        video="https://www.youtube.com/watch?v=K4TOrB7at0Y",
        recipient_id="255757xxxxxx",
)

Sending Audio

Here an example;

messenger.send_audio(
        audio="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
        recipient_id="255757xxxxxx",
)

Sending Document

Here an example;

messenger.send_document(
        document="http://www.africau.edu/images/default/sample.pdf",
        recipient_id="255757xxxxxx",
)

Sending Location

Here an example;

messenger.send_location(
        lat=1.29,
        long=103.85,
        name="Singapore",
        address="Singapore",
        recipient_id="255757xxxxxx",
    )

Sending Interactive buttons

Here an example;

messenger.send_button(
        recipient_id="255757xxxxxx",
        button={
            "header": "Header Testing",
            "body": "Body Testing",
            "footer": "Footer Testing",
            "action": {
                "button": "Button Testing",
                "sections": [
                    {
                        "title": "iBank",
                        "rows": [
                            {"id": "row 1", "title": "Send Money", "description": ""},
                            {
                                "id": "row 2",
                                "title": "Withdraw money",
                                "description": "",
                            },
                        ],
                    }
                ],
            },
        },
)

Sending a Template Messages

Here how to send a pre-approved template message;

messenger.send_template("hello_world", "255757xxxxxx")

Sending a Template Messages with Components

You can now specify components like this

let components = [ 
  // Your components here
]

messenger.send_template("hello_world", "255757xxxxxx", components)

For moreabout components: https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates

Webhook

Webhooks are useful incase you're wondering how to respond to incoming message send by user, but I have created a starter webhook which you can then customize it according to your own plans.

To learn more about webhook and how to configure in your Facebook developer dashboard please have a look here.

Notification Payload Structure

This is the structure of the notifications that you will recieve from Whatsapp when a certain event is triggered

Example Notification Payload Nested Structure of the Payload
{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "WHATSAPP-BUSINESS-ACCOUNT-ID",
    "changes": [{
      "value": {
         "messaging_product": "whatsapp",
         "metadata": {
           "display_phone_number": "PHONE-NUMBER",
           "phone_number_id": "PHONE-NUMBER-ID"
         },
      # Additional arrays and objects
         "contacts": [{...}]
         "errors": [{...}]
         "messages": [{...}]
         "statuses": [{...}]
      },
      "field": "messages"
    }]
  }]
}

Recieving notifications

To receive notifications such as customer messages, alerts and other callbacks from WhatsApp

import Server from './classes/server'
import 'dotenv/config'

let notificationServer = new Server(
    process.env.LISTEN_PORT,
    process.env.VERIFY_TOKEN
)

let app = notificationsServer.start(async (rawData ,processedPayload) => {
  // Do your stuff here
  let messages = processedPayload.get_messages()
  let metadata = processedPayload.get_contacts()
  let contacts = processedPayload.get_contacts()
  let status = processedPayload.get_statuses()

  // Do other stuff here
})

rawData -> This is raw data straight from WhatsApp processedPayload -> This is an object of ProcessPayload it gives access to the raw_data plus helper methods

Note: Beginners should work more with processed since it saves you time and minimizes errors

Tip: You can refactor it to look more presentable

import handleNotifications from 'path/to/file'

let app = notificationServer.start(handleNotifications)

Getting media links

To retrive actual media link

let message = processedPayload.get_messages()[0]
let mediaData = await messenger.get_media(message.image.id)

NOTE: The URL you get is only available for a 5 minutes, so you may need to download it and store it somewhere, or use it as quick as possible

For more info check Notification Payload refernce and Notification Payload Examples

Issues

If you will face any issue with the usage of this package please raise one so as we can quickly fix it as soon as possible;

Contributing

This is an opensource project under MIT License so any one is welcome to contribute from typo, to source code to documentation, JUST FORK IT.

All the credit

  1. kalebu
  2. takunda
  3. Contribute to get added here
You might also like...

Bot WhatsApp multi device / multi perangkat menggunakan lib / api baileys-md. Give star ⭐

Bot WhatsApp multi device / multi perangkat menggunakan lib / api baileys-md. Give star ⭐

Requirements • Installation • Thanks to • Official Group Bot • Donate Information Chika-Md adalah bot yang awalnya memakai base dari Hisoka-Morou. Chi

Dec 25, 2022

Easiest medium to use buttons with any discord API wrapper

Easiest medium to use buttons with any discord API wrapper

Discord Buttons Plugin Easiest medium to use buttons with any discord API wrapper /* Generate 1st Button with "Yes" lable on it */ const button1

May 14, 2022

spotify.ts is an wrapper built around Spotify's Web API

spotify.ts About spotify.ts is an wrapper built around Spotify's Web API. Features Fast Object Oriented Typescript, ESM, CJS support Easy to Use Insta

Nov 17, 2022

The node.js v18 API wrapper for discordlist.gg

About This is an unofficial discordlist.gg package written for Typecript and JavaScript to interact with its public API. If you need help using this p

Dec 13, 2022

Bot Whatsapp Multi-Device Using Javascript

Bot Whatsapp Multi-Device Using Javascript

Rzky Multi Device Gunakan dengan risiko Anda sendiri! Dibuat dengan Baileys dan Map() ( sebagai command handler ) Options Options pada command, yang a

Dec 20, 2022

A simple and easy-to-use WhatsApp bot project based on Multi-Device Baileys and written in JavaScript

A simple and easy-to-use WhatsApp bot project based on Multi-Device Baileys and written in JavaScript

MIZUHARA ANIME THEMED FULL FLEDGED MULTI DEVICE WHATSAPP BOT WITH COOL FEATURES A Full Fledged MD Bot For Bot Lovers REQUIREMENTS • HOW TO INSTALL? •

Oct 25, 2022

Use Discord like cloud storage.

DISCORD-DRIVE-CLIENT Use Discord like cloud storage. Release TODO: Screenshot list Release TODO: Release Coming soon.. Warning Abusing this client can

Mar 22, 2022

Queen Amdi is a chat bot for WhatsApp.

Queen Amdi is a chat bot for WhatsApp.

👸 💎 QUEEN AMDI BOT 💎 👸 Whatsapp භාවිතා කිරීම පහසු සහ විනෝදජනක කරයි. Whatsapp සඳහා පළමු සිංහල පරිශීලක බොට් ද වේ. Whatsapp Group | Youtube Channel Q

Dec 28, 2022

whatsapp bot build with nodejs

A whatsapp bot made using adiwajshing/Baileys library Install ⬇️ git clone https://github.com/justpiple/whatsapp-bot/ cd whatsapp-bot npm i For

Nov 23, 2022
Comments
  • Support for parameters on send_template

    Support for parameters on send_template

    https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates

    add support for setting the header parameters { "messaging_product": "whatsapp", "to": "5XXXXXXXXXXX", "type": "template", "template": { "name": "test_template", "language": { "code": "es_MX" }, "components": [{ "type": "header", "parameters": [ { "type": "text","text": "111" } ] } ] } } and body parameters like this { "messaging_product": "whatsapp", "to": "5XXXXXXXXXXX", "type": "template", "template": { "name": "prueba_confirmacion_turno", "language": { "code": "es_MX" }, "components": [{ "type": "body", "parameters": [ { "type": "text","text": "111" },{ "type": "text","text": "222" },{ "type": "text","text": "333" },{ "type": "text","text": "444" } ] } ] } }

    opened by dardoguidobono 2
Owner
JS Hub Zimbabwe
Javscript Hub Zimbabwe
JS Hub Zimbabwe
Simple WhatsApp Bot Script using WhatsApp Web Multi-Device API

Shiina Mashiro MD Shiina Multi Device Using NodeJS Framework & Baileys WhatsApp Web API Information WhatsApp Bot using WhatsApp Web API. If you find a

Hafidz Al-Ghifari 3 Feb 4, 2022
whatsapp api to remote your whatsapp device. Support multi device, multi client. Still update to more feature. Please fork, star, donate and share.

Ndalu-wa-client DEPENDENCIES : { "@adiwajshing/baileys": "^4.2.0", "@adiwajshing/keyed-db": "^0.2.4", "axios": "^0.27.2", "body-parser

null 29 Jan 4, 2023
World first fully customizeble user bot for Whatsapp 😎 With enjoyable ththings and fun to use Whatsapp ✨️

⚡ The Alpha-X Whatsapp User Bot ?? ~ ᴡᴏʀʟᴅ ꜰɪʀꜱᴛ ꜰᴜʟʟ ᴄᴜꜱᴛᴏᴍɪᴢᴀʙʟᴇ ᴜꜱᴇʀ ʙᴏᴛ ꜰᴏʀ ᴡʜᴀᴛꜱᴀᴘᴘ ~ ?? What is Alpha-X ?? Alpha-X , is a WhatsApp helper bot wr

Official Alpha-X-Team Account 17 Jul 29, 2022
Um sistema de tickets muito simples baseado em mensagens do WhatsApp, que permite multiusuários na mesma conta do WhatsApp.

Press-Ticket Manual de Instalação INSTALL.md Changelog 05/04/2022 Iniciar com o menu lateral fechado 30/03/2022 Atualização da lib wwebjs para a versã

Robson Tenorio 93 Dec 27, 2022
Whatsapp Bot with multi-device support Your Personal Assistance on Whatsapp

BotsApp-MD Whatsapp Bot with multi-device support Your Personal Assisstant, on WhatsApp! Deployment Easiest Way Head over to botsapp-md to deploy. Tak

Peter Dorglo 14 Jan 1, 2023
Simple WhatsApp MD BOT. Get a API key from ZEN API

ALIEN ALFA-MD Contact Me: ❗❗FORK THIS BEFORE PROCEEDING Use This Button To Fork Now Scan QR Code For Session Change Session In Github ⚠️ Session Chang

TOXIC ALIEN 46 Dec 28, 2022
A unofficial discord.js fork for creating selfbots [Based on discord.js v13]

About discord.js-selfbot-v13 is a Node.js module that allows user accounts to interact with the Discord API v9. I don't take any responsibility for bl

March 7th 239 Jan 4, 2023
Ekşi Sözlük için Entry No girerek Entry'i resimli hale getirip paylaşmanız için geliştirilmiş bir araç. [unofficial]

eksiprettier Ekşi Sözlük için Entry No girerek Entry'i resimli hale getirip paylaşmanız için geliştirilmiş bir araç. [unofficial] Nasıl Kullanılır? Ön

Y. Emre BAKKAL 6 Oct 12, 2022
Api Whatsapp Baileys - Single Device

Api do Whatsapp ?? Um servidor de API do WhatsApp gratuito do serviço https://apigratis.com.br Sobre Ainda estamos em desenvolvimentos, erros podem oc

Jonathan Henrique 11 Nov 9, 2022
Vio-MD is multi-device whatsapp bot using library @adiwajshing/baileys and example bot of Violetics API

Vio Multi Device WhatsApp Bot Use at your own risk! Build with Baileys and JavaScript's native Map class ( as a command handler ), using https://viole

Violetics 4 May 31, 2022