phpfacebook-graph-apiwhatsapp

How can I send messages to WhatsApp using WhatsApp Cloud API without registering the recipient number prior to sending message?


I can send WhatsApp messages using the below code but it requires registering the recipient number using OTP in developers.facebook.com before I can send messages to that number.

In real-life examples, there are lots of websites or web services which sends WhatsApp messages to their customer which doesn't require OTP or any registration of number.

For example, I bought a couple of T-shirts online and they sent details of my purchase on my WhatsApp number without requiring me to share any OTP or consent. How can achieve the same?

$curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://graph.facebook.com/v16.0/123337764081651/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 => '{"messaging_product": "whatsapp", "recipient_type": "individual", "to": "918420XXXXXX", "type": "image", "image": {"link": "' . $img_url . '"}}',
      CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
        'Authorization: Bearer EAAHPmTzaDUQBAFGMxCRAM9m0asdwdwdwaQZCvlZBWZCUeD64acFzJ7INPauBKMlZB4jasdwdasasasCz6ZB4pRsFol2OwZArw6paNasdsdsa4dC0ZBoUjq2b6w1w75lptPbpZC2nsUqSds8ZAS6frP8kIhEeKSW2bbjZAU2GiWSevZCTxmpiMBWMkdZAV7ZCNIZD'
      ),
    ));
    $response = curl_exec($curl);
    //echo $response;
    curl_close($curl);

Solution

  • Probably you are using a testing phone number, you can add up to 5 test phone numbers and it is required to verify each one, Read this for more details.

    If you add a real business phone number then it won't require verification to send a message to any user's number.