Android Code Snippet WhatsApp: Send Message to specific phone number

WhatsApp a few years ago had published APIs that allowed to send messages to a specific number. For some time, those methods no longer work and new methods appear on the official website.
(see: https://faq.whatsapp.com/en/android/28000012)

You can now open a conversation with a phone number but not preset the message. Or, in the opposite direction, determine which message but not specify who should receive it.

Yet with Google+ (and all Browser) you can select the user and the message with the entry. So there is an official method and is not documented. Or these bees are paid for commercial use.
The only documentation that is found and how to send a message set to a specific user across the Web. (https://faq.whatsapp.com/en/android/26000030/?category=5245251)

By using this I created a small code that allows an App to send a specific message to a specific user. Anyway, you have to confirm by WhatsApp .... but it is already something ... I attach the code

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private EditTextNumber As EditText
    Private EditTextMessange As EditText
    'Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ButtonSend_Click

    Dim Intent1 As Intent
    Intent1.Initialize(Intent1.ACTION_VIEW, $"https://api.whatsapp.com/send?phone=${EditTextNumber.Text}&text=${EditTextMessange.Text}"$)
    StartActivity(Intent1)


'    Dim HtmlCode As String = $"<html><center><a href="https://api.whatsapp.com/send?phone=${EditTextNumber.Text}&text=${EditTextMessange.Text}">SEND </a></center></html>"$
'    Log(HtmlCode)
'    If File.Exists(File.DirRootExternal,"wa.html") Then  File.Delete(File.DirRootExternal,"wa.html")
'    File.WriteString(File.DirRootExternal,"wa.html",HtmlCode)
'    WebView1.LoadHtml(File.ReadString(File.DirRootExternal,"wa.html"))
End Sub

There is a second alternative. I have seen on sale APIs from third-party distributors that allow you to send messages with WhatsApp to specific numbers ... But I did not test if they are valid.
 
Last edited:

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there, very interesting this code, however... I need to something that send automatically, without having to interact... any clues?
 

Star-Dust

Expert
Licensed User
Longtime User
A method exists because Google + sends you voice messages on WhatsApp without asking for authorization ... directly.
The same is my smarthwatch.

There are fewer known "APIs", probably paid, which they consider to be doing this.

At the moment, I just have this to use APIs for the WEB, because the "APIs" for Android allow even less.
 
  • Like
Reactions: GIS

NJDude

Expert
Licensed User
Longtime User
Hi there, very interesting this code, however... I need to something that send automatically, without having to interact... any clues?
This question/request pops up all the time and the answer is always the same: Cannot be done because there's no official WhatsApp API (and I don't think ever will for many reasons).
 

Star-Dust

Expert
Licensed User
Longtime User
This question/request pops up all the time and the answer is always the same: Cannot be done because there's no official WhatsApp API (and I don't think ever will for many reasons).
I found paid APIs that do it, I do not know if they are official. But I still believe that they exist because some Apps do it.

They are not public for obvious reasons.

Security is the first reason.
Eg:
Some time ago I studied a tutorial for B4A, I noticed that you can read WhatsAPP's specific notifications.
And I began to develop eun apps that spit the notifications, and I rolled all the messages on my tablet on the tablet.
This was for my convenience.
It would also allow me to respond to messages.

But I realized it could also be used to spy on someone ...
 

NJDude

Expert
Licensed User
Longtime User
I found paid APIs that do it, I do not know if they are official. But I still believe that they exist because some Apps do it.

They are not public for obvious reasons.

Security is the first reason.
Eg:
Some time ago I studied a tutorial for B4A, I noticed that you can read WhatsAPP's specific notifications.
And I began to develop eun apps that spit the notifications, and I rolled all the messages on my tablet on the tablet.
This was for my convenience.
It would also allow me to respond to messages.

But I realized it could also be used to spy on someone ...
Exactly, the MAIN reason is security (and privacy as well as spam)

There are no OFFICIAL APIs, the ones found in the wild are "hacks" which might work until WhatsApp plug the holes.
 

Star-Dust

Expert
Licensed User
Longtime User
In any case, Google+ and smarthwatch let you do it ... and do not use hacker methods
 

Star-Dust

Expert
Licensed User
Longtime User
I found paid APIs that do it, I do not know if they are official. But I still believe that they exist because some Apps do it.

They are not public for obvious reasons.

Security is the first reason.
Eg:
Some time ago I studied a tutorial for B4A, I noticed that you can read WhatsAPP's specific notifications.
And I began to develop eun apps that spit the notifications, and I rolled all the messages on my tablet on the tablet.
This was for my convenience.
It would also allow me to respond to messages.

But I realized it could also be used to spy on someone ...
PS. If you want to spy on WhatsApp, you read the notifications and send it by other methods ... Telegram, Allo, what do you like :p

I recommend that you do not use what I have written for illegitimate use but only for experimental and / or exercise purposes.
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
This guy is reporting that it works, however I have no idea how to convert this to b4a

B4X:
String toNumber = "+91 98765 43210"; // contains spaces.
toNumber = toNumber.replace("+", "").replace(" ", "");

Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.putExtra("jid", toNumber + "@s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage("com.whatsapp");
sendIntent.setType("text/plain");
startActivity(sendIntent);
 
Slt je suis nouveau.svp puis avoir des conseil sur l'utilisation de b4a pour le développement d'une application de messagerie comme whatsap et télégram??
 

Star-Dust

Expert
Licensed User
Longtime User
Slt je suis nouveau.svp puis avoir des conseil sur l'utilisation de b4a pour le développement d'une application de messagerie comme whatsap et télégram??
This is not the right thread. Here you find a code that allows you to send a message from your App through WA.

If you want to create your own messaging, open a new question on the forum
 

DonManfred

Expert
Licensed User
Longtime User
also note to post the question in english.
Or use the french forum to post french questions.
 

Star-Dust

Expert
Licensed User
Longtime User
Top