phpwhatsappwhatsapi

Whatsapp API - send a notification message to another phone number


I was looking for a way to send notifications directly to the customer phone number using the Whatsapp API

I found an article on a site that explains in detail how to activate and use the Whatsapp API.

Add the phone number +34 644 76 66 43 into your Phone Contacts. (Name it it as you wish)

Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)

Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot.

Note: If you don't receive the ApiKey in 2 minutes, please try again after 24hs.

The WhatsApp message from the bot will contain the apikey needed to send messages using the API.

You can send text messages using the API after receiving the confirmation.

Perfect receipt apikey

How to send WhatsApp Messages from PHP using CURL Library It is very simple to send WhatsApp messages from PHP using the cURL Library. I would recommend to create a function and then call to the function every time that you want to send a message.

First, create the function "send_whatsapp" in your php code as follow:

function send_whatsapp($message="Test"){
    $phone="NUMBER";  // Enter your phone number here
    $apikey="YOUR_API_KEY";       // Enter your personal apikey received in step 3 above

    $url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey;

    if($ch = curl_init($url))
    {
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $html = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        // echo "Output:".$html;  // you can print the output for troubleshooting
        curl_close($ch);
        return (int) $status;
    }
    else
    {
        return false;
    }
}

Just update the $phone and $apikey variable with the ones that you obtained during the step 3 above.

And then call to the function from any place in your code.

send_whatsapp("this is a test from PHP");    //Text message that your would like to send

You can call to the send_whatsapp function from different places in your code.

QUESTION

Perfect this will send me a message every time to the number I specified to activate the notification system.

But what if I want to send it not to my number but to the customer number?


Solution

  • I believe you're missing two concepts here. If you want to send messages from your personal phone number, you need to host & run your own solution (I don't think you'd like to allow anybody else out there to get all your stuff).

    If you are asking for a service provider to set up a number for you and offer you a gateway service for that purpose, there are several alternatives out there. Google them. You'll find two options; Facebook/Whatsapp API connected providers and 'free riders' that will set that up for you at a cost.

    The solution you mention is called call me bot and it is just to send self notifications and not for sending out messages to third parties. I am hosting a similar solution (https://github.com/inUtil-info/whin-use-cases) but is the same situation. To prevent span, you are not allowed to send messages to anyone but you.