No Particular Method

    TypeScript icon, indicating that this package has built-in type declarations

    0.2.7-alpha-02 • Public • Published

    This repository is a fork of 🤗:

    Changes made here:

    • Added to_phone_number so you can identify which phone number was the one receiving the message.
    • Added support for "reply" from template button (support for type 'button' in messages).
    • Added 'parameters' type for template header component.
    • Added a logging callback for each message sent so you can log each sent message easily.
    • Other details: to see all the changes made you can compare the two repositories.

    Note: This repo is published to

    Note2: I built a chats visualization frontend compatible here that you can use

    The following lines are the README of the original work.


    whatsapp-cloud-api is a Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API.

    Contains built-in Typescript declarations.

    run tests, lint, build npm publish npm npm bundle size npm


    Using npm:

    npm i whatsapp-cloud-api

    Using yarn:

    yarn add whatsapp-cloud-api


    import { createBot } from 'whatsapp-cloud-api';
    // or if using require:
    // const { createBot } = require('whatsapp-cloud-api');
    (async () => {
      try {
        // replace the values below
        const from = 'YOUR_WHATSAPP_PHONE_NUMBER_ID';
        const to = 'PHONE_NUMBER_OF_RECIPIENT';
        const webhookVerifyToken = 'YOUR_WEBHOOK_VERIFICATION_TOKEN';
        // Create a bot that can send messages
        const bot = createBot(from, token);
        // Send text message
        const result = await bot.sendText(to, 'Hello world');
        // Start express server to listen for incoming messages
        // NOTE: See below under `Documentation/Tutorial` to learn how
        // you can verify the webhook URL and make the server publicly available
        await bot.startExpressServer({
        // Listen to ALL incoming messages
        // NOTE: remember to always run: await bot.startExpressServer() first
        bot.on('message', async (msg) => {
          if (msg.type === 'text') {
            await bot.sendText(msg.from, 'Received your text message!');
          } else if (msg.type === 'image') {
            await bot.sendText(msg.from, 'Received your image!');
      } catch (err) {



    Sending other message types (read more in API reference):

    // Send image
    const result = await bot.sendImage(to, '', {
      caption: 'Random jpg',
    // Send location
    const result = await bot.sendLocation(to, 40.7128, -74.0060, {
      name: 'New York',
    // Send template
    const result = await bot.sendTemplate(to, 'hello_world', 'en_us');

    Customized express server (read more below):

    import cors from 'cors';
    // Create bot...
    const bot = createBot(...);
    // Customize server
    await bot.startExpressServer({
      webhookVerifyToken: 'my-verification-token',
      port: 3000,
      webhookPath: `/custom/webhook`,
      useMiddleware: (app) => {

    Listening to other message types (read more in API reference):

    const bot = createBot(...);
    await bot.startExpressServer({ webhookVerifyToken });
    // Listen to incoming text messages ONLY
    bot.on('text', async (msg) => {
      await bot.sendText(msg.from, 'Received your text!');
    // Listen to incoming image messages ONLY
    bot.on('image', async (msg) => {
      await bot.sendText(msg.from, 'Received your image!');


    1. Verifying your Webhook URL

    By default, the endpoint for whatsapp-related requests will be: /webhook/whatsapp. This means that locally, your URL will be: http://localhost/webhook/whatsapp.

    You can use a reverse proxy to make the server publicly available. An example of this is ngrok.

    You can read more on the Tutorial.

    2. Handling incoming messages

    The implementation above creates an express server for you through which it listens to incoming messages. There may be plans to support other types of server in future (PRs are welcome! :)).

    You can change the port as follows:

    await bot.startExpressServer({
      port: 3000,

    By default, all requests are handled by the POST|GET /webhook/whatsapp endpoint. You can change this as below:

    await bot.startExpressServer({
      webhookPath: `/custom/webhook`,

    Note: Remember the leading /; i.e. don't use custom/whatsapp; instead use /custom/whatsapp.

    If you are already running an express server in your application, you can avoid creating a new one by using it as below:

    // your code...
    import express from 'express';
    const app = express();
    // use the `app` variable below:
    await bot.startExpressServer({

    To add middleware:

    import cors from 'cors';
    await bot.startExpressServer({
      useMiddleware: (app) => {

    Full customized setup:

    import cors from 'cors';
    await bot.startExpressServer({
      webhookVerifyToken: 'my-verification-token',
      port: 3000,
      webhookPath: `/custom/webhook`,
      useMiddleware: (app) => {

    3. on() listener

    This library uses a single process pubsub, which means that it won't work well if you're deploying on multi-instance clusters, e.g. distributed Kubernetes clusters. In future, there may be plans to export/support a pubsub reference which can be stored in extenal storage, e.g. redis (PRs are welcome! :)).


    # install npm modules
    npm i
    # eslint
    npm run lint
    # typescript check
    npm run ts-check
    # test
    ## Read 'Local Testing' below before running this
    npm t
    # build
    npm run build

    Local Testing

    Create a .env file in the root of your project:



    In case using a scoped package, you can publish as follows:

    npm run build
    npm publish --access public


    Library API inspired by node-telegram-bot-api.

    Pull Requests

    Any and all PRs are open.


    npm i @josue.0/whatsapp-cloud-api

    DownloadsWeekly Downloads






    Unpacked Size

    112 kB

    Total Files


    Last publish


    • j05u3