Categories
PHP Programming

WhatsApp Messaging from Web

If you need to send WhatsApp message to your friend from Web, you need to find unofficial API as WhatsApp till date do not provide them, and do not allow bulk messaging as well. But in one of my project, I need to send message on whatsapp, for those who subscribe on website to recieve those about our service updates. So, I use WhatsApi (https://github.com/venomous0x/WhatsAPI New URL is https://github.com/WHAnonymous/Chat-API ), simply because it was most recommended API I found. I didn’t even try any other API code, as it works like charm for me. It has AjaxDemo folder in there, with 3 files. Anyone can easily learn the coding from it. So, I don’t go in much of coding part in this article. But here is basic steps with some code. To start with,

  • You will need a Mobile number that will be used to send messages. Make sure that you can recieve SMS on this mobile phone to verify the Whatsapp account.
  • Once you have your phone ready, download WART (https://github.com/shirioko/WART) which provide a simple EXE, to enter your phone and get a Password for API. Remember Whatsapp send password once every 30 minute, so if you want to get new password you have to wait 30 minutes. This step is no longer required as API has registration function available. Please refer API documentation for it.
  • Now, that you have WhatsAPP mobile phone and password, simply try this code.

 

require_once 'whatsprot.class.php';
$username = "11111111111"; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = "somepasswordstring";

$w = new WhatsProt($username, 0, "WhatsApp Messaging", true); //Name your application by replacing "WhatsApp Messaging"
$w->connect();
$w->loginWithPassword($password);

$target = '912222222222'; //Target Phone,reciever phone
$message = 'Your message comes here';

$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message

Yes, it was that simple. You can send Image and Video as well, but I am not going to explain them here, though to send Media you need to call ‘$w->pollMessages()’ otherwise your message won’t be sent. Note: all Phone must prefix the country code or it won’t send messages. To send media, you can either give Physical path or a URL to media resource.   EDIT: The API is now moved to new location: https://github.com/mgp25/Chat-API

By Sumit Gupta

Sumit Gupta, born on 7th Feb 1981 in NCR, India. He lives a quiet life until he turn to a developer. Once he is in his professional life people start recognizing him for his work. Sumit Gupta is always keen to learn more and share his knowledge to anyone who deserve it. His goal of life is to code at least one 3D action game by itself or with his company Vikasumit [http://www.vikasumit.com].

80 replies on “WhatsApp Messaging from Web”

hi Sumit
please tell me where i have to write this code,,,

because i am using your code in asp.net and make some html page please guide me how can i achive it ….
i got index page and after click send button it shows me my message on my screen with green back ground …but paroblem is how i register my mobile number and use that

require_once ‘whatsprot.class.php’;
$username = “11111111111”; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = “somepasswordstring”;

$w = new WhatsProt($username, 0, “WhatsApp Messaging”, true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);

$target = ‘912222222222’; //Target Phone,reciever phone
$message = ‘Your message comes here’;

$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message

Comments are closed.