Node-RED Send Messages to WhatsApp Number

In this tutorial, we will learn how to send simple text messages to our WhatsApp number using Node-RED. Node-Red is a free-to-use tool used in IoT applications that provides visual programming through connecting nodes wired together as flows. We will use CallMeBot API to send the messages from Node-RED to our WhatsApp account. CallMeBot is a free WhatsApp API that is helpful in sending message notifications, sensor readings, motion detection and door-opening alerts.

Node-RED Send Messages to WhatsApp Number

WhatsApp Messenger Introduction

WhatsApp Messenger is a famous, free, and most widely used platform to share instant messages, voice messages, voice calls, video calls, and shared documents owned by an American company known as Meta or Facebook. It is available to download and install for Android and iOS based smartphones. Anyone can sign up for this service by using his mobile phone number, and users must have an active mobile internet connection to use this service.

This application was initially developed by WhatsApp Inc. of Mountain View, California, and later on, acquired by Facebook (Meta).

CallMeBot WhatsApp API Introduction

CallMeBot is a free and easy-to-use API to send WhatsApp messages. This API is a service that allows you to send yourself messages in real-time. You only have to register your phone and take note of your API key! It’s easy to use and you can receive real-time alerts in all your projects.

We will use this service to send messages on our WhatsApp number. It is a gateway service that allows us to send messages to ourselves from any HTTP client.

How to Get CallMeBot API Key

You need to get the API key from the bot before using the API:

  • Add the phone number +34 621073245 to your Phone Contacts. (Name it as you wish)
  • Send this message I allow callmebot to send me messages to the new Contact created (using WhatsApp of course)
  • Wait until you receive the message “API Activated for your phone number. Your APIKEY is XXXXXX” from the bot.
  • Note: If you don’t receive the API Key in 2 minutes, please try again after 24hs.

The WhatsApp message from the bot will contain the API key needed to send messages using the API.

CallMeBot Get API Key

Setting up Node-Red WhatsApp Nodes

We will use Node-Red to send messages to our WhatsApp account. In order to get started with Node-Red on Raspberry Pi, refer to the guide:

To access Node-RED, we need the IP address of our Raspberry Pi and the port number on which Node-RED is accessible. By default, it starts on port 1880. Open any web browser and enter the RPI IP address followed by the port number.

192.168.18.8:1880

Creating Flow to Send Simple Text Message to WhatsApp Account

This will open the Node-RED interface. You can start creating the flow.

access Node-RED

Head over to Menu > Manage Palette > Install. Type node-red-contrib-whatsapp-cmb in the search bar and press enter. Install the Node-RED node which sends WhatsApp messages with CallMeBot.

Node-RED Install WhatsApp Node

After the installation completes, the WhatsApp node will be present in the palette as shown below:

Node-RED WhatsApp Node in Palette

Now drag an inject node, Send Message node and debug node to the flow as shown below:

Node-RED Add Nodes to Flow for WhatsApp simple message

Now double click the inject node to edit its properties as shown below.

We use msg.text to send the message in the form of a string. Specify the message that you want to send. ‘Sending simple text message.’ is the string that we want to send to our WhatsApp number. Click the Done button when you have made the changes.

Node-RED Edit Inject Node for WhatsApp simple message

Now double click the Send Message node to edit its properties. Click the pencil icon to add your WhatsApp account.

Node-RED Edit Send Message Node for WhatsApp simple message 1

Specify the name, phone number in international format (example: 913012222222) and the API key received from CallMeBot. Then click the Update button.

Node-RED Edit Send Message Node for WhatsApp simple message 2

Now set the Message field as ‘msg.text’ and click the Done button.

Node-RED Edit Send Message Node for WhatsApp simple message 3

Demonstration

Wire the nodes as shown below:

Now deploy the changes by clicking the Deploy button found at the top.

Node-RED Send simple message to WhatsApp wire nodes and deploy

To test the WhatsApp Send Message feature, click the left square on the inject node to initiate the process. You will receive a notification on the top showing that it was successfully injected.

Node-RED Send simple message to WhatsApp testing

After a few moments, open your WhatsApp account to view the message sent from CallMeBot through Node-RED.

Node-RED Send simple message to WhatsApp demo

You may also like to read:

Leave a Comment