File manager - Edit - /home/autoph/public_html/tasks/api/v1/viber/broadcast.php
Back
<?php /** * Before you run this example: * 1. install monolog/monolog: composer require monolog/monolog * 2. copy config.php.dist to config.php: cp config.php.dist config.php * * @author Novikov Bogdan <hcbogdan@gmail.com> */ require_once("../../../vendor/autoload.php"); use Viber\Bot; use Viber\Api\Sender; // use Monolog\Logger; // use Monolog\Handler\StreamHandler; $apiKey = '4ea7a840c9e7e7da-6455ceb946c2433c-569e8f349ab53511'; // reply name $botSender = new Sender([ 'name' => 'TASKS', 'avatar' => 'https://connect.autohub.ph/dist/img/default.png', ]); try { // create bot instance $bot = new Bot(['token' => $apiKey]); include_once '../../../cfg/db_console.php'; //check if token exist $query = "SELECT * FROM `cnf_api_token_ids` WHERE 1 AND type = 1 AND `status` = 1 AND is_subscribe = 1 LIMIT 100"; $api_token_list_obj = $db->sql_query($query); $api_token_list_arr = array(); foreach($api_token_list_obj as $api_token_list_row){ $api_token_list_arr = array_merge($api_token_list_arr,array($api_token_list_row)); } $token_ids_arr = array(); foreach($api_token_list_arr as $api_token_list_row1){ $token_ids_arr[] = $api_token_list_row1['api_id']; } if(count($token_ids_arr) > 0){ $bot->getClient()->broadcastMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setBroadcastList($token_ids_arr) ->setText('Test Broadcast') ); } // $bot // // first interaction with bot - return "welcome message" // ->onConversation(function ($event) use ($bot, $botSender) { // // $log->info('onConversation handler'); // // $buttons = []; // // $buttons[] = (new \Viber\Api\Keyboard\Button()) // // ->setBgColor('#ffc107') // // ->setTextHAlign('center') // // ->setActionType('reply') // // ->setActionBody('btn-click') // // ->setText('Get Started'); // $receiverId = $event->getUser()->getId(); // $user_id_context = $event->getContext(); // $user_id_context = intval($user_id_context); // include_once '../../../cfg/db_console.php'; // if($utility_class->isNotEmpty($user_id_context)){ // //check if token exist // // $query = "SELECT id FROM `cnf_api_token_ids` WHERE 1 AND `api_id` = '$receiverId' AND `type` = 1 AND `status` = 1 AND is_subscribe = 1 AND `user_id` = $user_id_context LIMIT 1 "; // // $api_token_id = $db->select($query); // // if(!$utility_class->isNotEmpty($api_token_id)){ // // insert viber id // $query = "INSERT INTO `cnf_api_token_ids`(`api_id`, `type`, `date_added`, `user_id`,`status`,`is_subscribe`) VALUES ('$receiverId',1,NOW(),$user_id_context,1,1) // ON DUPLICATE KEY UPDATE // api_id = VALUES (api_id), // type = VALUES (type), // status = VALUES (status), // is_subscribe = VALUES (is_subscribe) // "; // $db->sql_query($query); // // } // } // return (new \Viber\Api\Message\Text()) // ->setSender($botSender) // ->setText("Welcome to AutoHub TASKS."); // // ->setKeyboard( // // (new \Viber\Api\Keyboard()) // // ->setButtons($buttons) // // ); // }) // // when user subscribe to PA // ->onSubscribe(function ($event) use ($bot, $botSender) { // // $log->info('onSubscribe handler'); // $this->getClient()->sendMessage( // (new \Viber\Api\Message\Text()) // ->setSender($botSender) // ->setText('Thanks for subscription!') // ); // }) // ->onText('|btn-click|s', function ($event) use ($bot, $botSender) { // // $log->info('click on button'); // $receiverId = $event->getSender()->getId(); // include_once '../../../cfg/db_console.php'; // //check if token exist // $query = "SELECT id FROM `cnf_api_token_ids` WHERE 1 AND `api_id` = '$receiverId' AND `type` = 1 AND status = 1"; // $api_token_id = $db->select($query); // if(!$utility_class->isNotEmpty($api_token_id)){ // // insert viber id // $query = "INSERT INTO `cnf_api_token_ids`(`api_id`, `type`, `date_added`, `status`) VALUES ('$receiverId',1,NOW(),1)"; // $db->sql_query($query); // } // $bot->getClient()->sendMessage( // (new \Viber\Api\Message\Text()) // ->setSender($botSender) // ->setReceiver($receiverId) // ->setText("Type menu to view all commands.") // ); // }) // ->onText('|sendall .*|si', function ($event) use ($bot, $botSender) { // include_once '../../../cfg/db_console.php'; // // //check if token exist // // $query = "SELECT * FROM `cnf_api_token_ids` WHERE 1 AND type = 1 AND `status` = 1 AND is_subscribe = 1 LIMIT 100"; // // $api_token_list_obj = $db->sql_query($query); // // $api_token_list_arr = array(); // // foreach($api_token_list_obj as $api_token_list_row){ // // $api_token_list_arr = array_merge($api_token_list_arr,array($api_token_list_row)); // // } // //send 1 by 1 // // foreach($api_token_list_arr as $api_token_list_row1){ // // $bot->getClient()->sendMessage( // // (new \Viber\Api\Message\Text()) // // ->setSender($botSender) // // ->setReceiver($api_token_list_row1['api_id']) // // ->setText(str_replace("sendall","",$event->getMessage()->getText())) // // ); // // } // $bot->getClient()->broadcastMessage( // (new \Viber\Api\Message\Text()) // ->setSender($botSender) // ->setBroadcastList(array('BzoOWFX2s4hPSaCBNw+ZQA==','BzoOWFX2s4hPSaCBNw+ZQA==')) // ->setText(str_replace("sendall","",$event->getMessage()->getText())) // ); // }) // ->onText('|myid|si', function ($event) use ($bot, $botSender) { // // match by template, for example "whois Bogdaan" // //echo $event->getSender()->getId();exit; // $bot->getClient()->sendMessage( // (new \Viber\Api\Message\Text()) // ->setSender($botSender) // ->setReceiver($event->getSender()->getId()) // ->setText('ID: '.$event->getSender()->getId()) // ); // }) // ->run(); } catch (Exception $e) { echo $e; }
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings