_binary From 6c24258604e06638ec3d96e3e0190de4cd138999 Mon Sep 17 00:00:00 2001
From: Harika Nukala <harika.nukala@sap.com>
Date: Tue, 9 May 2017 14:33:59 -0700
Subject: [PATCH] example bots added

---
 src/examples/StockBot.php   | 19 ++++++++-----------
 src/examples/WeatherBot.php |  9 +++++----
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/examples/StockBot.php b/src/examples/StockBot.php
index eae0dfd..d20ff5f 100644
--- a/src/examples/StockBot.php
+++ b/src/examples/StockBot.php
@@ -69,7 +69,7 @@ class StockBot
      * a timestamp as well as the hash of this timestamp with the bot_token
      * and post data and that these match the expected values
      */
-    const ACCESS_TOKEN = "bot_token";
+    const ACCESS_TOKEN = "1234";
     /**
      * Number of seconds that the passed timestamp can differ from the current
      * time on the WeatherBot machine.
@@ -82,15 +82,10 @@ class StockBot
     function processRequest()
     {
         $result = "There was a configuration issue with your query.";
-        // $name = "tesla";
-        // $symbol = $this->getSymbol($name);
-        // $result = $this->getStockPrice('("'.$symbol.'")');
         if ($this->checkBotToken() && !empty($_REQUEST['post']) &&
-            !empty($_REQUEST['bot_name'])) {
-            $name = filter_var($_REQUEST['post'], \FILTER_SANITIZE_STRING);
-            $name = trim(mb_strtolower($name));
-            $symbol = $this->getSymbol($name);
-            $result = $this->getStockPrice('("'.$symbol.'")');
+            !empty($_REQUEST['bot_name']) && !empty($_REQUEST['a'])) {
+            $entities=unserialize($_REQUEST['entities']);
+            $result = $this->$_REQUEST['a']($entities[0]);
             if (empty($result)) {
                 $result = "I failed to find the stock price for that symbol.\n".
                     "I respond to queries in the format:\n" .
@@ -114,7 +109,7 @@ class StockBot
                 abs(time() - $token_parts[1]) < self::TIME_WINDOW) {
                 // second check avoids timing attacks, works for > php 5.6
                 if ((!function_exists('hash_equals') &&
-                    $hash == $token_parts[0]) ||
+                        $hash == $token_parts[0]) ||
                     hash_equals($hash, $token_parts[0])) {
                     return true;
                 }
@@ -128,8 +123,10 @@ class StockBot
      * @param string $symbol the ticker to get stock price for
      * @return string stock price information
      */
-    function getStockPrice($symbol)
+    function getStockPrice($name)
     {
+        $symbol = $this->getSymbol($name);
+        $symbol = '("'.$symbol.'")';
         $yql_query = "select * from yahoo.finance.quotes where symbol in $symbol";
         $url = self::STOCK_URL . "?q=" .
             urlencode($yql_query) . "&env=store://datatables.org/alltableswithkeys&format=json";
diff --git a/src/examples/WeatherBot.php b/src/examples/WeatherBot.php
index e5337a3..36a8cd8 100644
--- a/src/examples/WeatherBot.php
+++ b/src/examples/WeatherBot.php
@@ -79,10 +79,11 @@ class WeatherBot
     {
         $result = "There was a configuration issue with your query.";
         if ($this->checkBotToken() && !empty($_REQUEST['post']) &&
-            !empty($_REQUEST['bot_name'])) {
-            $location = filter_var($_REQUEST['post'], \FILTER_SANITIZE_STRING);
-            $location = trim(mb_strtolower($location));
-            $result = $this->getWeather($location);
+            !empty($_REQUEST['bot_name']) && !empty($_REQUEST['a'])) {
+//            $location = filter_var($_REQUEST['post'], \FILTER_SANITIZE_STRING);
+//            $location = trim(mb_strtolower($location));
+            $entities=unserialize($_REQUEST['entities']);
+            $result = $this->$_REQUEST['a']($entities[0]);
             if (empty($result)) {
                 $result = "I failed to find the weather for that location.\n".
                     "I respond to queries in the format:\n" .
-- 
2.10.1 (Apple Git-78)

