Automatic whatsapp message posting ..!

2

I have had the need as everyone to be able to create an application in my case with Php and Js; to send messages using the WhatsApp API. As many of us already know it is possible to send with the help of the link that whatsapp provides, with the help of that link I am a little bit more mature and I wanted to see if I can count on the support of any of you to follow this development.

So far I have a small application that lets you write the number and the text then concatenates these two variables to the url of whatsapp api, until this step the application is not completely automatic since after giving in send you redirects to the whatsapp page is where I'm planning to have a script automatically press the send button and close the whatsapp window returning to the application and send another message.

var sam = document.getElementsByClassName("_2lkdt");
sam[0].click();

Where _2lkdt is the class that has the send button. Problems that I have identified:

  • The class of the button at each start or reload the page of whatsappweb will change
  • I do not know much about how to make the Scrapig js or in php the code that I sent was tested in the Chorme console
  • asked by Santiago Gutierrez 20.04.2018 в 23:45
    source

    1 answer

    3

    The short answer: CAN NOT BE

    The not-so-short answer:

    You can not execute a button on an external page from PHP since all PHP codes are executed on the server side and not on the client side. The PHP code does not run in any browser, so in essence there is no link to click, even if you try to do web scraping the only thing available is the reference of the button but you will not be able to execute said button.

      

    Of course on the server side you can run a submit event using   web scraping however the 'Send' button on the screen   whatsap is not a submit type, for that reason you could not do it   this way.

    If you want to guide things on the client's side, you would need to resort to browser robotic such as Selenium .

    The same I show you several solutions that I have made so you can check for yourself:

    Possible solution 1: We are going to assume that you do a POST to a php server that redirects the page after loading, we will execute some script.

    JS:

    $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: 'whatsap.php',
                    data: JSON.stringify({ whatsap: 'https://api.whatsapp.com/send?phone=numerodetelefonodewhatsapp&text=urldelmensaje' }),
                    contentType: 'application/json; charset=utf-8'
                });
    

    PHP:

       <?php 
        $link = json_decode(file_get_contents('php://input'), true);
        header('Location: '. $link['whatsap']);
        exit();
       ?>
    
      

    Solution 1 .. Failed: We can not get the page from javascript.

    Possible solution 2: Web scraping

    PHP: (I will use simple_html_dom for the PHP Scraping webpage):

    <?php
    
    include_once('./simple_html_dom.php');
    $url = 'https://api.whatsapp.com/send?';
    $data =  http_build_query(array(
        'phone'=>$_POST['phone'],
        'text'=>$_POST['text']
    ));
    $html = file_get_html($url.$data);
    $button =  $html->find('#action-button');
    
    var_dump($button); //Aqui tienes el boton pero no puedes ejecutar el evento click.
    
    ?>
    
      

    Solution 2 .. Failed: You can not run a click event using webScraping.

    Possible solution 3: Paint the content of the whatsap page on your page.

    PHP

    <?php
    $url = 'https://api.whatsapp.com/send?';
    $data =  http_build_query(array(
        'phone'=> 'tutelefono',
        'text'=> 'mensaje'
    ));
    $html = file_get_contents($url.$data);
    echo $html;
    
    ?>
    
      

    Solution 3 .. Failed: You will receive the following message from the whatsap security team. : (

        
    answered by 21.04.2018 в 05:50