Android Code Snippet WhatsApp: Send Message to specific phone number

Discussion in 'Code Snippets' started by Star-Dust, Sep 28, 2017.

  1. Star-Dust

    Star-Dust Expert Licensed User

    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

    Code:
    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: Nov 25, 2017
  2. Star-Dust

    Star-Dust Expert Licensed User

    I am also append an already working project. ;)
     

    Attached Files:

    Last edited: Sep 28, 2017
  3. eelias

    eelias Active Member Licensed User

    Hi there, very interesting this code, however... I need to something that send automatically, without having to interact... any clues?
     
  4. Star-Dust

    Star-Dust Expert Licensed 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.
     
    GIS likes this.
  5. NJDude

    NJDude Expert Licensed 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).
     
  6. Star-Dust

    Star-Dust Expert Licensed 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 ...
     
  7. NJDude

    NJDude Expert Licensed User

    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 likes this.
  8. Star-Dust

    Star-Dust Expert Licensed User

    In any case, Google+ and smarthwatch let you do it ... and do not use hacker methods
     
  9. NJDude

    NJDude Expert Licensed User

    True, very very limited anyway.
     
  10. Star-Dust

    Star-Dust Expert Licensed User

    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.
     
  11. NJDude

    NJDude Expert Licensed User

    That's no fun :p
     
  12. eelias

    eelias Active Member Licensed User

    This guy is reporting that it works, however I have no idea how to convert this to b4a

    Code:
    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);
     
  13. NJDude

    NJDude Expert Licensed User

    That's similar to what's done HERE
     
  14. Mohamed_rama

    Mohamed_rama Member

    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??
     
  15. Star-Dust

    Star-Dust Expert Licensed User

    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
     
  16. DonManfred

    DonManfred Expert Licensed User

    also note to post the question in english.
    Or use the french forum to post french questions.
     
    peacemaker and Star-Dust like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice