In this article, you’ll learn how to send WhatsApp messages from a Mendix Native app using JavaScript. We will open the WhatsApp application directly from the app and send a real-time message to a specified phone number with a single tap.
Right Click on JavaScript module -> Add Other -> JavaScript action -> give the name JS_Whatsapp.

Open JS_Whatsapp JavaScript action
Go to Settings -> Under the General tab add two string parameters,
first(number) and second(message).

Go to the code section and add the below code to import the Linking.
import { Linking } from "react-native";

Now remove this code code
throw new Error("JavaScript action was not implemented");
And add the below code between Begin & End user code.
if (number && message !== undefined && message !== null) {
const phone = number;
const encodedMessage = encodeURIComponent(message);
const url = `https://wa.me/${phone}?text=${encodedMessage}`;
await Linking.openURL(url);
}

Go to JavaScript_Native page -> take a button & give the name Whatsapp.

Double click on Whatsapp button -> In onClick events select call a nanoflow & create a new nanoflow(ACT_Whatsapp).

Open ACT_Whatsapp nanoflow -> drag & drop the JS_Whatsapp JavaScript action inside this nanoflow.

Double click on JS_Whatsapp and pass the number with country code 91 and message value in string format.


Now run the application & test it.

When you tap the WhatsApp button, the device opens the WhatsApp app and sends a real-time message to the given number.
Conclusion:
I hope this article has helped you understand How to Send WhatsApp Messages Using JavaScript In Mendix Native App.
Thanks for reading this! See you in the next blog post.
