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

@shoopi/whatsapp-cloud-api

v0.0.3

Published

Unofficial package wrapper for WhatsApp Cloud Api

Downloads

7

Readme

WhatsApp Cloud Api

This is an unofficial package for the WhatsApp Cloud Api, the project still under development.

Requirements

  • Access to the Cloud Api, you can read more here
  • A Redis server can download and remember use the command redis-stack-server to start it localy
  • Subscribed to the message webhook read more here

Installation

Install Whatsapp Cloud Api with npm

  npm install @shoopi/whatsapp-cloud-api

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

| Parameter | Description | Required | | :------------- | :----------------------------------------- | :------- | | ACCESS_TOKEN | Temporal o permanent WhatsApp Access token | ✅ | | VERIFY_TOKEN | Any secret string | ✅ | | WEBHOOK_PORT | The port to start the webhook | |

environment=DEV Will connect to the default local redis server

If you are using online redis server need to add those environment variables

REDIS_PORT

REDIS_USERNAME

REDIS_PASSWORD

Usage/Examples

import WhatsappCloudApi from "@shoopi/whatsapp-cloud-api";
import templates from "./templates.json";
import rules from "./rules.json";

function main() {
  new WhatsappCloudApi({
    templates: templates,
    rules: rules,
  });
}
main();

When use the discord bot have to add this environment variables

| Parameter | Description | Required | | :----------------------- | :-------------------------------------- | :------- | | DISCORD_TOKEN | The discord bot token | ✅ | | DISCORD_CLIENT | The discord bot client | ✅ | | DISCORD_GUILD_ID | The server where the bot will work | ✅ | | DISCORD_QUEUE_CHANNEL | The channel to send request to chat | ✅ | | DISCORD_CHATS_CATEGORY | By default will take the parent channel | |

Discord bot middleware for whatsapp cloud api

import DiscordPlugin from "@shoopi/whatsapp-cloud-api-plugin-discord";
import WhatsappCloudApi from "@shoopi/whatsapp-cloud-api";
import templates from "./templates.json";
import rules from "./rules.json";

function main() {
  const discordbot = DiscordPlugin.getInstance();
  discordbot.init();
  new WhatsappCloudApi({
    templates: templates,
    rules: rules,
    middlewares: [discordbot.getMiddleware()],
  });
}
main();

Template and Rules

To start the bot you need two params template and rules those can be a .json or variable but need to follow this structure

template

{
    "default_unknow_response":{
       "type":"text",
       "text":{
          "body":"Please select a valid option."
       }
    },
    "welcome_menu":{
       "type":"interactive",
       "interactive":{
          "type":"button",
          "header":{
             "type":"text",
             "text":"This is the header"
          },
          "body":{
             "text":"This is the body of your message"
          },
          "action":{
             "buttons":[
                {
                   "type":"reply",
                   "reply":{
                      "id":"button-one-id",
                      "title":"Button one"
                   }
                },
                {
                   "type":"reply",
                   "reply":{
                      "id":"button-two-id",
                      "title":"Button two"
                   }
                },
                {
                   "type":"reply",
                   "reply":{
                      "id":"button-three-id",
                      "title":"Button three"
                   }
                }
             ]
          }
       }
    },
    "response_one":{
       "type":"text",
       "text":{
            "body":"This is a response for the first button"
       }
    },
    "response_two":{
       "type":"text",
       "text":{
            "body":"This is a response for the second button"
       }
    },
    "response_three":{
       "type":"text",
       "text":{
            "body":"This is a response for the third button"
       }
    },
    "response_trigger":{
       "type":"text",
       "text":{
            "body":"This is a response for the trigger"
       }
    },
    "template_message":{
       "type":"template",
       "template":{
          "name":"sample_shipping_confirmation",
          "language":{
             "code":"en"
          },
          "components":[
             {
                "type":"body",
                "parameters":[
                   {
                      "type":"text",
                      "text":"1"
                   }
                ]
             }
          ]
       }
    }
}

The template need at least welcome_menu and default_unknow_response

Read the full documentation of all message type.

rules

[
    {
       "type":"interactive",
       "button_id":"button-one-id",
       "context":"user_request_information",
       "expected_response":{
          "type":"interactive"
       },
       "response":{
          "id":"response_one"
       }
    },
    {
       "type":"interactive",
       "button_id":"button-two-id",
       "context":"user_request_information",
       "expected_response":{
          "type":"interactive"
       },
       "response":{
          "id":"response_two"
       }
    },
    {
       "type":"interactive",
       "button_id":"button-three-id",
       "context":"user_request_information",
       "expected_response":{
          "type":"text"
       },
       "response":{
          "id":"response_three"
       }
    },
    {
       "type":"text",
       "triggers":[
          "this",
          "trigger",
          "i",
          "some"
       ],
       "context":"user_request_information",
       "expected_response":{
          "type":"text"
       },
       "matchs":2,
       "response":{
          "id":"response_trigger"
       }
    }
]

The type can be:

text
image
location
interactive
template

If the type is interactive and expect a button you have to pass the button_id

The context accept those types and can use whatever you want:

unknow
welcome
waiting_for_action
waiting_for_information
user_request_information
waiting_to_talk_with_human
talking_with_human

When use the triggers pass the array of words to trigger that rule and can set the numbers of matchs the default is 1

Roadmap

  • Image support

  • Location suport

  • Document support

  • Contact support

Contributing

Contributions are always welcome!

Feedback

If you have any feedback, please reach out to us at [email protected]