Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send message from webserver to mobile chat app (like WhatsApp, Viber or Kik) on my smartphone?

I would like to send notifications from my webserver to my smartphone, preferably through one of the popular mobile chat apps like WhatsApp, Viber or Kik.

Is there any known documentation or API or something, that describes how to send a message to these clients, for example using PHP?

Note that I only need to be able to send notifications to my own smartphone, so requiring specific info to identify my particular client (like cellphone number or something) is fine.

like image 256
William Clark Avatar asked Oct 03 '22 10:10

William Clark


1 Answers

There are many web services that allows you to send and receive SMS/notifications. PHP itself doesn't support this on it's own. You can use a service like Twilio to do this. You can send messages to your own smartphone, or even a friend's.

An example:

<?php

   require "Services/Twilio.php";

    // Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
    $AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";

    // Step 3: instantiate a new Twilio Rest Client
    $client = new Services_Twilio($AccountSid, $AuthToken);

    // Step 4: make an array of people we know, to send them a message. 
    // Feel free to change/add your own phone number and name here.
    $people = array(
        "+14158675309" => "Curious George",
        "+14158675310" => "Boots",
        "+14158675311" => "Virgil",
    );

    // Step 5: Loop over all our friends. $number is a phone number above, and 
    // $name is the name next to it
    foreach ($people as $number => $name) {

        $sms = $client->account->sms_messages->create(

        // Step 6: Change the 'From' number below to be a valid Twilio number 
        // that you've purchased, or the (deprecated) Sandbox number
            "YYY-YYY-YYYY", 

            // the number we are sending to - Any phone number
            $number,

            // the sms body
            "Hey $name, Monkey Party at 6PM. Bring Bananas!"
        );

        // Display a confirmation message on the screen
        echo "Sent message to $name";
    }

See the documentation here.

Hope this helps!

like image 94
Amal Murali Avatar answered Oct 19 '22 19:10

Amal Murali