File manager - Edit - /home/autoph/public_html/tasks/viber.tar
Back
send_video_notification.php 0000644 00000007362 15025012074 0012146 0 ustar 00 <?php // echo $_REQUEST['json'];exit; /** * 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> */ //sample json request // {"target_id":"80","type":1,"target_json":["262","292"]} require_once("../../../vendor/autoload.php"); include_once '../../../cfg/db_console.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 { if(!isset($_REQUEST['json']) || is_null(json_decode($_REQUEST['json']))){ $json_arr['status'] = 0; $json_arr['message'] = "Invalid parameters."; echo json_encode($json_arr); exit; } include_once dirname(__FILE__) . '../../../../app/classes/user_class.php'; $user_class = new User(); $param_json = json_decode($_REQUEST['json'], true); $type = $param_json['type']; $target_id = $param_json['target_id']; $target_position_arr = $param_json['target_json']; //get target id details $video_title = $db->select("SELECT title FROM `videos` WHERE id = $target_id"); $query = "SELECT u.*,ati.api_id FROM `users` u LEFT OUTER JOIN cnf_api_token_ids ati ON u.id = ati.user_id WHERE 1 AND u.position_id IN (".implode(",",$target_position_arr).") AND ati.type = $type AND ati.status = 1;"; // echo $query; $user_obj = $db->sql_query($query); $user_arr = array(); foreach($user_obj as $user_row){ // $user_arr = array_merge($user_arr,array($user_row)); $user_arr[] = $user_row; } foreach($user_arr as $user_row1){ $token = $db->select('SELECT UUID()'); $to_user_id = $user_row1['id']; $from_user_id = $user_row1['id']; $user_class->create_user_login_token($to_user_id,$from_user_id,$target_id,$token,4,$utility_class,$db); $url_params = array( 'token'=>$token, 'type'=>4, // 'category'=>'tickets', // 'action'=>'view', 'id'=>$target_id, // 'notification'=>"[$ticket_id,$to_user_id]", ); $append_link = $global_system_settings['url']."token.php"."?".http_build_query($url_params); $append_link = urlencode($append_link); $append_link = $utility_class -> curl_me( "https://s.autohub.ph/?url=$append_link&format=text", array(), 'GET'); $message_will_be_sent = "\n\nNew Video: ".$video_title."\nClick to view: ".$append_link; // echo $user_row1['api_id'];exit; $bot = new Bot(['token' => $apiKey]); $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setReceiver($user_row1['api_id']) ->setText($message_will_be_sent) ); } } catch (Exception $e) { echo $e; } bot.php 0000644 00000015314 15025012074 0006041 0 ustar 00 <?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]); $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,0) ON DUPLICATE KEY UPDATE api_id = VALUES (api_id), type = VALUES (type) "; $db->sql_query($query); // } } return (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setText("Welcome to AutoHub TASKS.\nClick \"Get Started\" to start.") ->setKeyboard( (new \Viber\Api\Keyboard()) ->setButtons($buttons) ); }) // when user subscribe to PA ->onSubscribe(function ($event) use ($bot, $botSender) { // $log->info('onSubscribe handler'); $receiverId = $event->getSender()->getId(); include_once '../../../cfg/db_console.php'; $query = "UPDATE `cnf_api_token_ids` SET `is_subscribe`=1 WHERE 1 AND api_id = '$receiverId' "; $db->sql_query($query); $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setReceiver($receiverId) // ->setText("Type menu to view all commands.") ->setText('Thanks for subscription!') ); }) ->onUnsubscribe(function ($event) use ($bot, $botSender) { // $log->info('onSubscribe handler'); $receiverId = $event->getSender()->getId(); include_once '../../../cfg/db_console.php'; $query = "UPDATE `cnf_api_token_ids` SET `is_subscribe`= 0 WHERE 1 AND api_id = '$receiverId' "; $db->sql_query($query); $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setReceiver($receiverId) // ->setText("Type menu to view all commands.") ->setText('We will miss you.') ); }) ->onText('|btn-click|s', function ($event) use ($bot, $botSender) { // $log->info('click on button'); $receiverId = $event->getSender()->getId(); include_once '../../../cfg/db_console.php'; $query = "UPDATE `cnf_api_token_ids` SET `is_subscribe`=1,`status`=1 WHERE 1 AND api_id = '$receiverId' "; $db->sql_query($query); $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setReceiver($receiverId) // ->setText("Type menu to view all commands.") ->setText('Thanks for subscription!') ); }) ->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; } a.php 0000644 00000000132 15025012074 0005465 0 ustar 00 <?php // sleep for 10 seconds sleep(5); $myfile = fopen("testfile.txt", "w"); exit; send.php 0000644 00000002522 15025012074 0006203 0 ustar 00 <?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> */ //id must url encoded // {"id":"BzoOWFX2s4hPSaCBNw+ZQA==","msg":"Test"} // print_r($param_json); // exit; 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 { if(!isset($_REQUEST['json']) || is_null(json_decode($_REQUEST['json']))){ $json_arr['status'] = 0; $json_arr['message'] = "Invalid parameters."; echo json_encode($json_arr); exit; } $param_json = json_decode($_REQUEST['json'], true); // create bot instance $bot = new Bot(['token' => $apiKey]); $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) ->setReceiver($param_json['id']) ->setText($param_json['msg']) ); } catch (Exception $e) { echo $e; } broadcast.php 0000644 00000016460 15025012074 0007222 0 ustar 00 <?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; } testfile.txt 0000644 00000000000 15025012074 0007106 0 ustar 00 webhook.php 0000644 00000000717 15025012074 0006714 0 ustar 00 <?php require_once("../../../vendor/autoload.php"); use Viber\Client; $apiKey = '4ea7a840c9e7e7da-6455ceb946c2433c-569e8f349ab53511'; // from "Edit Details" page $webhookUrl = 'https://tasks.autohub.ph/api/v1/viber/bot.php'; // for exmaple https://my.com/bot.php try { $client = new Client([ 'token' => $apiKey ]); $result = $client->setWebhook($webhookUrl); echo "Success!\n"; } catch (Exception $e) { echo "Error: ". $e->getError() ."\n"; } ?>