PHP code example of serv5group / whatscloudapi
1. Go to this page and download the library: Download serv5group/whatscloudapi library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
serv5group / whatscloudapi example snippets
javascript
use serv5group\whatscloudapi\WebCloud;
class Examples
{
/*
* Create WhatsCloudApi new instance
* @return WebCloud
*/
public function connect()
{
$connect = WebCloud::accessToken("token")->setInstance("instanceId");
return $connect;
}
/*
* send whatsapp message
* @return Void
*/
public function sendMessage()
{
$response = $this->connect()->to("phone")->message("template")->send();
if( $response->status == 'success' ){
// The message was sent successfuly
}else{
\Log::error($response->message);
}//@endif
}
/*
* send whatsapp bulk message
* @return Void
*/
public function sendBulkMessage()
{
foreach ($contacts as $contact) {
$response = $this->connect()->to("contact")->message("template")->send();
if( $response->status == 'success' ){
// The message was sent successfuly
}else{
\Log::error($response->message);
}//@endif
} //@endforeach
}//@endfunction
/*
* send whatsapp message and media
* @return Void
*/
public function sendMessage()
{
$response = $this->connect()->to("phone") ->message("template")->media("path")->send();
if( $response->status == 'success' ){
// The message was sent successfuly
}else{
\Log::error($response->message);
}//@endif
}
/*
* send whatsapp bulk message and attachments
* @return Void
*/
public function sendBulkMessage()
{
foreach ($contacts as $contact) {
$response = $this->connect()->to("contact")->message("template")->media("path")->send();
if( $response->status == 'success' ){
// The message was sent successfuly
}else{
\Log::error($response->message);
}//@endif
} //@endforeach
}//@endfunction
}