static function init() { self::$postWeatherInfo = 'You can also send "#weather <city-name>" to get latest weather information in single message'; self::$postMovieServiceMessage = 'You can also send "#movie <movie-name>" to get movie information in single message'; self::$postCricketServiceMessage = 'You can send "#cricket <team1,team2>" to get latest match score information'; self::$postFeedbackMessage = 'You message is recorded. Thanks for submitting your feedback'; self::$postShoppingSearch = 'You can also send #shopping <product-name> to get updated product information.'; self::$postPNRMessage = 'For quick PNR information you can also send "#pnr <pnr-number>"'; self::$RAILWAY_MENU_CONTEXT = ['1' => new contextMenu('1', 'PNR', NULL, 'askForPnrStatus', 'getPnrStatus', self::$postPNRMessage, "#pnr"), '2' => new contextMenu('2', 'LIVE STATUS', NULL, 'askForLiveRunningStatus', 'getLiveRunningStatus', NULL, '#livestatus')]; self::$serviceAgentList = [new serviceAgent('Neerav Mehta', '919728923923', '9', '20')]; self::$GENIE = "GENIE"; self::$WEATHER_MENU_CONTEXT = ['1' => new contextMenu('1', 'WEATHER INFORMATION', NULL, 'askForWeatherLocation', 'getWeatherInformation', self::$postWeatherInfo, "#weather"), '2' => new contextMenu('2', 'QUIT', NULL, 'exitMenu', 'exitMenu', self::$postWeatherInfo, "#weather")]; self::$GENDER_SUB_MENU_STRING = 'gender'; self::$AGE_SUB_MENU_STRING = 'age'; self::$CITY_SUB_MENU_STRING = 'location'; self::$EMAIL_SUB_MENU_STRING = 'email'; self::$postRegistrationServiceMessage = "Thank you for the information."; self::$anyThingElse = "Is there anything else I can assist you with?\n 1 for Yes\n 2 for No"; self::$THANKYOU_SERVICE_MESSAGE = "Thank you for using our services."; self::$REGISTRATION_MENU_CONTEXT = ['1' => new contextMenu('1', self::$GENDER_SUB_MENU_STRING, NULL, 'processGenderInformation'), '2' => new contextMenu('2', self::$AGE_SUB_MENU_STRING, NULL, 'processAgeInformation'), '3' => new contextMenu('3', self::$CITY_SUB_MENU_STRING, NULL, 'processCityInformation'), '4' => new contextMenu('4', self::$EMAIL_SUB_MENU_STRING, NULL, 'processEmailInformation', self::$postRegistrationServiceMessage)]; self::$SERVICE_REQUEST_COMPLETE = "SERVICE_REQUEST_COMPLETE"; self::$PARENT_MENU_CONTEXT = []; self::$SHOPPING_MENU_CONTEXT = ['1' => new contextMenu('1', 'SEARCH PRODUCT', NULL, 'getProductInformation', 'getProductInformation', self::$postShoppingSearch, '#shopping'), '2' => new contextMenu('2', 'LATEST OFFERS', NULL, 'getLatestOffers', 'getLatestOffers', '#offers')]; self::$CRICKET_MENU_CONTEXT = ['1' => new contextMenu('1', 'CRICKET SCORE', NULL, 'askForLiveScore', 'getLiveScore', self::$postCricketServiceMessage, "#cricket"), '2' => new contextMenu('2', 'QUIT', NULL, 'exitMenu', 'exitMenu', self::$postCricketServiceMessage, "#cricket")]; self::$VAS_MENU_CONTEXT = ['1' => new contextMenu('1', 'MOVIE INFORMATION', NULL, 'askForMovieInformation', 'getMovieReview', self::$postMovieServiceMessage, '#movie'), '2' => new contextMenu('2', 'CRICKET INFORMATION', NULL, 'askForMatchInformation', 'getLiveScore', self::$postCricketServiceMessage, '#cricket')]; self::$MOVIE_MENU_CONTEXT = ['1' => new contextMenu('1', 'MOVIE INFORMATION', NULL, 'getMovieReview', 'getMovieReview', self::$postMovieServiceMessage, '#movie')]; self::$FEEDBACK_MENU_CONTEXT = ['1' => new contextMenu('1', 'FEEDBACK', NULL, 'submitFeedback', 'submitFeedback', self::$postFeedbackMessage, '#feedback'), '2' => new contextMenu('2', 'CRICKET INFORMATION', NULL, 'askForMatchInformation', 'getLiveScore', self::$postCricketServiceMessage, '#cricket')]; self::$MAIN_MENU_CONTEXT = ['0' => new contextMenu('0', 'Parent', self::$PARENT_MENU_CONTEXT, NULL), '1' => new contextMenu('1', 'Weather', self::$WEATHER_MENU_CONTEXT, NULL), '2' => new contextMenu('2', 'Movie', self::$MOVIE_MENU_CONTEXT, null), '3' => new contextMenu('3', 'Cricket', self::$CRICKET_MENU_CONTEXT, null), '4' => new contextMenu('4', 'Railway', self::$RAILWAY_MENU_CONTEXT, null), '5' => new contextMenu('5', 'Shopping', self::$SHOPPING_MENU_CONTEXT, null), '6' => new contextMenu('6', 'Feedback', self::$FEEDBACK_MENU_CONTEXT, null), '8' => new contextMenu('8', 'UserManagement', self::$REGISTRATION_MENU_CONTEXT, null)]; self::$INTRODUCTION = "I am Genie, your whatsapp based personal assistant.\n\n How can I assist you today?\n 1 for Weather Information \n\n 2 for Movie Information \n\n 3 for Cricket Scores \n\n 4 for Railway Enquiry \n\n 5 for Shopping Assistance \n\n 6 for Feedback"; self::$MAIN_MENU_STRING = "What can I do for you?\n 1 for Weather Information \n\n 2 for Movie Information \n\n 3 for Cricket Scores \n\n 4 for Railway Enquiry \n\n 5 for Shopping Assistance \n\n 6 for Feedback"; self::$HELP = "Send #help to connect to the service agent"; self::$WELCOME_MESSAGE = ", It seems we are meeting for the first time.\n" . "To assist you better I will ask you a few questions. To start with,"; self::$SERVICE_UNAVAILABLE = "Service temporarily not available, please try after some time"; self::$INVALID_TRAIN_NUMBER = "Invalid train number or journey date"; self::$MATCH_UNAVAILABLE = "Sorry, this match information is not available."; self::$INVALID_INFORMATION = "Invalid information, please check again"; self::$INVALID_SERVICE = "There is no such service, Please enter a valid service name"; self::$ERROR_MESSAGE = "Sorry, I could not understand, Please try again"; self::$THANKYOU_MESSAGE = "Thank you for the information."; self::$userFields = array('gender', 'age', 'location', 'email'); self::$genderQuestion = "May I know your gender please?\n1 for Male\n2 for Female"; self::$ageQuestion = 'Tell me which age group do you belong to: 1 for <18 yrs 2 for 18-25 yrs 3 for 26-39 yrs 4 for 40-60 yrs 5 for >60 yrs'; self::$cityQuestion = 'Alright, May I know which city you belong to?'; self::$emailQuestion = 'One last question! Tell me your email address.'; self::$fieldQuestions = array(self::$genderQuestion, self::$ageQuestion, self::$cityQuestion, self::$emailQuestion); self::$genderRegex = '/[1-2]/'; self::$ageRegex = '/[1-5]/'; self::$cityRegex = '/^[a-zA-Z ]*$/'; self::$emailRegex = "/^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)\$/"; self::$regex = array(self::$genderRegex, self::$ageRegex, self::$cityRegex, self::$emailRegex); }
public static function getLiveScore($requester, $request) { $requestParams = explode(",", $request); $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']; MessaggingController::sendMessage($requester, $score); $message = "Do you want to know the score of any other match?\n\n 1 For Yes\n\n 2 for No"; setMessageContext(GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$CRICKET_MENU_CONTEXT, 'subMenu'), NULL, $requester['phone']); } } } else { $message = "Service temporarily not available, please try after some time"; } MessaggingController::sendMessage($requester, $message); }
public static function initializeService($requester) { $welcomeMessage = self::$ShoppingWelcomeMessage; MessaggingController::sendMessage($requester, $welcomeMessage); $mainMenuRedirectString = self::$mainMenuRedirectString; MessaggingController::sendMessage($requester, $mainMenuRedirectString); $menu = self::$askForProductInformation; MessaggingController::sendMessage($requester, $menu); updateMessageContext(GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$SHOPPING_MENU_CONTEXT, 'subMenu'), '1', $requester['phone']); }
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']); }
public static function initializeService($requester) { MessaggingController::sendMessage($requester, self::$askForMovieName); updateMessageContext(GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$MOVIE_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); }
public static function processEmailInformation($receiver, $response) { $regex = GenieConstants::$emailRegex; if (preg_match($regex, $response) == 0) { $errorMessage = GenieConstants::$ERROR_MESSAGE; MessaggingController::sendMessage($receiver, $errorMessage); self::askForEmailInformation($receiver, $response); return; } else { updateContact(GenieConstants::$EMAIL_SUB_MENU_STRING, $response, $receiver['phone']); $menu_Context = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$PARENT_MENU_CONTEXT, 'subMenu'); $subMenu_Context = NULL; updateMessageContext($menu_Context, $subMenu_Context, $receiver['phone']); MessaggingController::sendMessage($receiver, GenieConstants::$INTRODUCTION); // PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE,$receiver); } }