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

heyooh

v1.2.3

Published

heyooh is a javascript port of heyoo(made in python). heyoo is a python wrapper for the Whatsapp Cloud API

Downloads

14

Readme

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

{
  "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