Exemple #1
0
 public static function getLiveScore($requester, $request)
 {
     $requestParams = explode(",", $request);
     $scoreAvailable = false;
     $team1 = $requestParams[0];
     $team2 = $requestParams[1];
     $matchList = file_get_contents(self::$cricInfoURL);
     $message = "Sorry, this match information is not available.";
     if ($matchList) {
         $json = json_decode($matchList, true);
         foreach ($json as $value) {
             echo $value['t1'] . '/n';
             echo $value['t2'] . '/n/n';
             if ((stripos($value['t1'], $team1) > -1 || stripos($value['t1'], $team2) > -1) && (stripos($value['t2'], $team1) > -1 || stripos($value['t2'], $team2) > -1)) {
                 $matchScoreURL = self::$cricInfoURL . '?id=' . $value['id'];
                 $matchScore = file_get_contents($matchScoreURL);
                 $matchScore = json_decode($matchScore, true);
                 $score = $matchScore['0']['de'];
                 $scoreAvailable = true;
                 MessaggingController::sendMessage($requester, $score);
             }
         }
     } else {
         $message = "Service temporarily not available, please try after some time";
     }
     if (!$scoreAvailable) {
         MessaggingController::sendMessage($requester, $message);
     }
     PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
 }
Exemple #2
0
    public static function getWeatherInformation($requester, $body)
    {
        $locationURL = self::$url . '/locations/v1/In/search?q=' . $body . '&apikey=' . self::$apiKey;
        echo $locationURL;
        $location = file_get_contents($locationURL);
        $locationJson = json_decode($location, true);
        if ($locationJson) {
            var_dump($locationJson);
            //$locationJson;
            $locationKey = $locationJson['0']['Key'];
            $forecastURL = self::$url . '/forecasts/v1/daily/5day/' . $locationKey . '?apikey=' . self::$apiKey;
            $forecast = file_get_contents($forecastURL);
            $forecastJson = json_decode($forecast, true);
            $forecastMessage = "Next 5 days Weather Forcast for " . $body . ' is 
' . $forecastJson['Headline']['Text'];
            MessaggingController::sendMessage($requester, $forecastMessage);
            $dailyForecast = "Daily Forecast\n";
            foreach ($forecastJson['DailyForecasts'] as $value) {
                $minCelsius = round(($value['Temperature']['Minimum']['Value'] - 32) / 1.8);
                $maxCelsius = round(($value['Temperature']['Maximum']['Value'] - 32) / 1.8);
                $dailyForecast = $dailyForecast . date('jS F', $value['EpochDate']) . ": " . $minCelsius . "C " . $maxCelsius . "C " . $value['Day']['IconPhrase'] . "\n";
            }
            MessaggingController::sendMessage($requester, $dailyForecast);
        }
        PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
    }
 public function configureWhatsAppService()
 {
     self::$w = new WhatsProt($this->username, $this->nickname, $this->debug);
     self::$w = new WhatsProt($this->username, $this->nickname, $this->debug);
     echo "[] logging in as '{$nickname}' ({$username})\n";
     self::$w->eventManager()->bind('onPresenceAvailable', array($this, 'onPresenceAvailable'));
     self::$w->eventManager()->bind("onPresenceUnavailable", array($this, "onPresenceUnavailable"));
     self::$w->connect();
     // Nos conectamos a la red de WhatsApp
     self::$w->loginWithPassword($this->password);
     // Iniciamos sesion con nuestra contraseña
     echo "[*]Conectado a WhatsApp\n\n";
     self::$w->sendGetServerProperties();
     // Obtenemos las propiedades del servidor
     self::$w->sendClientConfig();
     // Enviamos nuestra configuración al servidor
     $sync = array($target);
     self::$w->sendSync($sync);
     // Sincronizamos el contacto
     self::$w->pollMessage();
     // Volvemos a poner en cola mensajes
     self::$w->sendPresenceSubscription($target);
     // Nos suscribimos a la presencia del usuario
     $pn = new ProcessNode(self::$w, $target);
     self::$w->setNewMessageBind($pn);
     self::$w->eventManager()->bind("onGetMessage", array($this, "onMessage"));
 }
Exemple #4
0
 public static function getProductInformation($requester, $body)
 {
     $body = str_replace(' ', '', $body);
     $url = self::$flipkartSearchURL . $body . '&resultCount=1';
     $searchJson = self::getURLContent($url, self::$fKAffiliateId, self::$fKAffiliateToken);
     echo $searchJson;
     $json = json_decode($searchJson, true);
     $productObj = $json['productInfoList'][0]['productBaseInfo']['productAttributes'];
     echo $json['productInfoList'][0]['productBaseInfo']['productAttributes']['title'];
     $newLine = '\\n';
     $fkMRP = "MRP: " . $productObj['maximumRetailPrice']['amount'];
     $fkSellngPrice = "Selling Price: " . $productObj['sellingPrice']['amount'];
     $fkProductLink = $productObj['productUrl'];
     $fkTittle = $productObj['title'];
     $fkPriceProduct = "{$fkTittle}\n{$fkMRP}\n{$fkSellngPrice}\n{$fkProductLink}";
     MessaggingController::sendMessage($requester, $fkPriceProduct);
     PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
 }
Exemple #5
0
 public static function getMovieReview($requester, $movieTitle)
 {
     echo "\n\n\n\n\n";
     var_dump($movieTitle);
     echo "\n\n\n\n\n";
     $movieTitle = str_replace(' ', '+', $movieTitle);
     $url = self::$omdbURL . $movieTitle . '&y=&plot=short&r=json';
     $movieReview = file_get_contents($url);
     if ($movieReview) {
         $json = json_decode($movieReview, true);
         if ($json['Response'] == 'false') {
             MessaggingController::sendMessage($requester, $json['Error']);
         } else {
             $response = "Tittle: " . $json['Title'] . "\n" . "imdb Rating: " . $json['imdbRating'] . "\n" . "Year: " . $json['Year'] . "\n" . "Released: " . $json['Released'] . "\n" . "Actors: " . $json['Actors'] . "\n" . "Plot: " . $json['Plot'] . "\n";
             MessaggingController::sendMessage($requester, $response);
         }
     } else {
         MessaggingController::sendMessage($requester, GenieConstants::$SERVICE_UNAVAILABLE);
     }
     PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
 }
Exemple #6
0
 public static function getLiveRunningStatus($requester, $request, $isDetailedStatusRequired = false)
 {
     $requestParams = explode(",", $request);
     $trainNumber = $requestParams[0];
     $doj = $requestParams[1];
     $date = DateTime::createFromFormat('d/m/Y', $doj);
     $doj = date_format($date, 'Ymd');
     $url = self::$liveStatusURL . $trainNumber . '/doj/' . $doj . '/apikey/' . self::$railwayApikey . '/';
     echo "************\n\n\n\n" . $url;
     $liveStatus = file_get_contents($url);
     $json = json_decode($liveStatus, true);
     if ($json['total'] == 0) {
         echo $json;
         $invalidDataMsg = "Invalid train number or journey date";
         MessaggingController::sendMessage($requester, $invalidDataMsg);
     } else {
         if ($liveStatus) {
             //                if(!$isDetailedStatusRequired)
             //                {
             //                    $response = $json['position'];
             //                    MessaggingController::sendMessage($requester, $response);
             //                }
             //                else
             //                {
             $response = "Current Status \n";
             for ($count = 0; $count < $json['total']; $count++) {
                 if ($json['route'][$count + 1]['status'] == '-') {
                     $response .= "Station: " . $json['route'][$count]['station'] . "\nScheduled Dep: " . $json['route'][$count]['schdep'] . "\nActual Dep: " . $json['route'][$count]['actdep'] . "\nStatus: " . $json['route'][$count]['status'];
                     break;
                 }
             }
             //                $response+=$json['position'];
             MessaggingController::sendMessage($requester, $response);
             //}
         } else {
             MessaggingController::sendMessage($requester, GenieConstants::$SERVICE_UNAVAILABLE);
         }
     }
     PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
 }
Exemple #7
0
 public static function initializeService($requester)
 {
     self::getServiceAgent(Genie);
     MessaggingController::sendMessage($requester, self::$FEEDBACK_MESSAGE);
     updateMessageContext(GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$FEEDBACK_MENU_CONTEXT, 'subMenu'), '1', $requester['phone']);
 }
 static function handleMessageReceived($mynumber, $from, $id, $type, $time, $name, $body)
 {
     $number = ExtractNumber($from);
     $contact = getUserInfo($number);
     if (!$contact) {
         addContact($number, $name);
         $contact = getUserInfo($number);
         $main_menu = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$REGISTRATION_MENU_CONTEXT, 'subMenu');
         setMessageContext($main_menu, NULL, $contact['phone']);
     }
     //Handle ShortCut in request
     $requestArray = $data = preg_split('/\\s+/', $body);
     if ($requestArray[0][0] == '#') {
         self::handleShortCuts($contact, $requestArray);
         return;
     }
     $context = getMessageContext($number);
     $callBackFunction = 'initializeService';
     if ($context['main_menu'] == -1) {
         self::handleGeneralConversation($body, $context, $contact);
         return;
     }
     if ($context['main_menu'] == 0) {
         if (GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, $body, 'id') != NULL) {
             updateMessageContext($body, NULL, $contact['phone']);
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$body]->menuItem, $callBackFunction, $contact);
         } else {
             MessaggingController::sendMessage($contact, GenieConstants::$INVALID_SERVICE);
             MessaggingController::sendMessage($contact, GenieConstants::$MAIN_MENU_STRING);
         }
         return;
     }
     if ($context['main_menu'] != 0 && $context['main_menu'] != 8 && $context['sub_menu'] == NULL) {
         $subMenuKey = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu, $body, 'id');
         $SubMenuDict = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu;
         if ($subMenuKey != NULL) {
             updateMessageContext($context['main_menu'], $body, $contact['phone']);
             $callBackFunction = $SubMenuDict[$subMenuKey]->callBackMethod;
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact);
         } else {
             MessaggingController::sendMessage($contact, GenieConstants::$INVALID_SERVICE);
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact);
         }
         return;
     } else {
         if ($context['main_menu'] != 0 && $context['main_menu'] != 8 && $context['sub_menu'] != NULL) {
             $SubMenuDict = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu;
             $callBackFunction = $SubMenuDict[$context['sub_menu']]->requestServer;
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact, $body);
             return;
         } else {
             if ($context['sub_menu'] != NULL) {
                 $callBackFunction = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu[$context['sub_menu']]->callBackMethod;
             } else {
                 if (GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->callBackMethod != NULL) {
                     $callBackFunction = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->callBackMethod;
                 }
             }
         }
     }
     PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact, $body);
 }
Exemple #9
0
 *************************************/
//require_once 'Chat-API/src/whatsprot.class.php';
//require_once 'Bot-API/spontena/pbphp/PBClient.php';
//
//require "Bot-API/vendor/autoload.php";
//include 'Services/railways.php';
//include 'dbManager.php';
//include 'Services/movieReviews.php';
//include 'Services/cricketScore.php';
//include 'userRegistration.php';
//include 'GenieConstants.php';
include 'MessaggingController.php';
use spontena\pbphp\PBClient;
# Configuration
//Change the time zone if you are in a different country
date_default_timezone_set('Europe/Madrid');
echo "####################################\n";
echo "#                                  #\n";
echo "#           WA CLI CLIENT          #\n";
echo "#                                  #\n";
echo "####################################\n\n";
echo "====================================\n";
//$baseURL = 'https://aiaas.pandorabots.com';
//$app_id = '1409612034562';
//$botname = 'dexter';
//$user_key = '0dfb3beeb74a59726d0c9ca6a1414e41';
//$pbc = new PBClient($baseURL,$app_id,$user_key);
//$boturl = 'http://www.botlibre.com/rest/botlibre/form-chat?instance=1121773&user=neerav.mehta@hotmail.com&password=Jgd@2421&message=';
$msgController = new MessaggingController();
$msgController->configureWhatsAppService();
$msgController->startPollingMessage();
 public static function askForEmailInformation($receiver, $response)
 {
     $fieldQuestions = GenieConstants::$emailQuestion;
     MessaggingController::sendMessage($receiver, $fieldQuestions);
 }