Hello Everyone
In this post, I am sharing a method to send WhatsApp messages from Oracle ADF Application using the "WhatsApp Click to Chat" feature as WhatsApp doesn't provide any official API.
Though it's an extremely simple way and we need not write a single line of code, We just need to pass some values in an URL to open WhatsApp Click to Chat console.
Created an ADF Application and a page in the view controller with two text fields and a button in it. It looks like this
and both fields are bonded to the managed bean variables
- <af:inputText label="Mobile No." id="it1" value="#{viewScope.SendWhatsAppBean.mobileNo}"
- autoSubmit="true"/>
- <af:inputText label="Message" id="it2" rows="2" value="#{viewScope.SendWhatsAppBean.message}"
- autoSubmit="true"/>
and managed bean just contain simple POJO variables
- package sendwhatsappadf.view.bean;
- public class SendWhatsAppBean {
- public SendWhatsAppBean() {
- }
- private String mobileNo;
- private String message;
- public void setMobileNo(String mobileNo) {
- this.mobileNo = mobileNo;
- }
- public String getMobileNo() {
- return mobileNo;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public String getMessage() {
- return message;
- }
- }
Next is to know about the browser-based WhatsApp click to chat feature, It makes use of an API URL
https://api.whatsapp.com/send?phone=&text=
Now on button click, we can pass phone number and text message in this URL to open click to chat console and in ADF we can do this using destination property of af:button.
- <af:button text="Send" id="b1" targetFrame="_blank"
- destination="https://api.whatsapp.com/send?phone=#{viewScope.SendWhatsAppBean.mobileNo}&text=#{viewScope.SendWhatsAppBean.message}"
- partialTriggers="it2 it1"/>
In the above XML source, we can see that both values are passed from managed bean variables.
Now run and check the application. Enter mobile no., text message on the page
On click of the Send button, WhatsApp click to chat console is opened in a new browser window.
and this button will open the WhatsApp QR code scanner window, In that window scan QR code with your phone and start sending messages.
Using this method we can pass values from ADF bindings to WhatsApp URL and send messages from ADF application.
Cheers 🙂 Happy Learning