skip to Main Content

I am sending message from Facebook whatsapp api to my number for testing. Message is sent from php but not recieved on mobile. Did I must register business on facebook?

{"messaging_product":"whatsapp","contacts":[{"input":"923040165804","wa_id":"923040165804"}],"messages":[{"id":"wamid.HBgMOTIzMDQwMTY1ODA0FQIAERgSOEM3RDJDRDMyMkFENkIzMTgyAA=="}]}

this php code that I am using.

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://graph.facebook.com/v13.0/********/messages/',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>json_encode(array("to"=> $number, "messaging_product" => 'whatsapp', "recipient_type" => 'individual',"type"=>"text", 'text'=> array('body'=>'hello_wo332233rld','preview_url'=>'false'))),
            CURLOPT_HTTPHEADER => array(
                'Authorization: Bearer '.$chatApiToken,
                'Content-Type: application/json'
            ),
        ));

        $response = curl_exec($curl);
        curl_close($curl);
        echo $response;

3

Answers


  1. Same issue here. And sending from dev console template, same issue too.
    After change the phone number, it has worked. I don’t know if will work at the production environment, but…

    Login or Signup to reply.
  2. Hey I came across the same problem and the solution was to upgrade whatsapp to the latest version on my phone. I added some troubleshooting issues to the Ruby library that could help with similar problems.

    Login or Signup to reply.
  3. Here is a sample code, hope it helps. It works for me

    Point to remember
    Mentioning a template name is mandatory. The messages are subject to the approved templates

         $number = $_GET['number']; //you can use POST, I tried GET for testing
         $template = array(
           'name'=>'hello_world', //your your own or any default template. The names and samples are listed under message templates
           'language'=>array('code'=>'en_us') //you can use yours
           );
    
         $endpoint = 'https://graph.facebook.com/v15.0/USE_YOUR_OWN/messages';
         $params = array('messaging_product'=>'whatsapp', 'to'=>$number, 'type'=>'template', 'from'=>'91xxxxxxxxxx', 'access_token'=>'YOUR_ACCESS_TOKEN','template'=>json_encode($template));
    
           $headers = array('Authorization'=>'YOUR_ACCESS_TOKEN','Content-Type'=>'application/json', 'User-Agent'=>'(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36');
           $url = $endpoint . '?' . http_build_query($params);
      //echo $params.'<br>';
           $ch = curl_init();
           curl_setopt( $ch,CURLOPT_URL, $endpoint);
           curl_setopt( $ch,CURLOPT_POST, true );
           curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
           curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
           curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
           curl_setopt( $ch,CURLOPT_POSTFIELDS, $params);
           $result = curl_exec($ch );
           echo $result; //you can skip this, I did it to check the results
           curl_close( $ch );
    

    This finally echos the result as

    {"messaging_product":"whatsapp","contacts":[{"input":"15645446547","wa_id":"15645446547"}],"messages":[{"id":"wamid.HBgLMTU2NDU0NDY1NDcVAgARGBIwNjJEMjc3NzIzQzA2RjY2QTYA"}]}
    

    And the message is getting received.

    refer the following thread on how to pass a parameter AKA "passing components"

    How to send the components in whatsapp cloud api?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search