public function query()
 {
     $data = json_decode(file_get_contents('php://input'), TRUE);
     $text = print_r($data, true);
     $ver = $data['version'];
     $requestType = $data['request'][type];
     // request type just writes the type of request to the file
     // the text variable file_put_contents writes the php array to disk
     // tail this file
     //file_put_contents('fromamazon.txt',$requestType);
     file_put_contents('fromamazon.txt', $text);
     // if for some reason you wanted to show something to web users.
     if (!$ver) {
         //echo("<html>web request detected</html>");
     }
     if ($requestType == 'SessionEndedRequest') {
         endSession('goodbye');
     }
     //$requestType = 'LaunchRequest';
     if ($requestType == 'LaunchRequest') {
         // new session!
         speechOut('What is your question?');
     }
     //$requestType = 'IntentRequest';
     if ($requestType == 'IntentRequest') {
         $answer = $this->processIntent($data);
         // now it's plaintext, lets have alexa say it.
         speechOut($answer);
     }
     // end of intent request
 }
Exemplo n.º 2
0
                        if ($val) {
                            $answer .= $val;
                            $answered = 1;
                        }
                    }
                    if ($i == 3 && $answered == 0) {
                        if ($val) {
                            $answer .= $val;
                            $answered = 1;
                        }
                    }
                    if ($i == 4 && $answered == 0) {
                        if ($val) {
                            $answer .= $val;
                            $answered = 1;
                        }
                    }
                }
                // foreach
            }
        }
    }
    // foreach
    // this gets the extra junk and formatting out of the response
    $answer = strip_tags($answer);
    $answer = preg_replace("/[^A-Za-z0-9 ]/", '', $answer);
    $answer = preg_replace("/[^[:alnum:][:space:]]/ui", '', $answer);
    // now it's plaintext, lets have alexa say it.
    speechOut($answer);
}
// end of intent request