Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $jsonRequest = file_get_contents('php://input');
- $data = json_decode($jsonRequest, true);
- file_put_contents('alexaInput.json', json_encode($data, JSON_PRETTY_PRINT));
- if (empty($data) || (!isset($data))) {
- die('Bad Request');
- }
- $intentType = !empty($data['request']['type']);
- $intent = !empty($data['request']['intent']['name']) ? $data['request']['intent']['name'] : 'default';
- $intentData = !empty($data['request']['intent']['slots']) ? $data['request']['intent']['slots'] : 'default';
- $sessionId = !empty($data['session']['sessionId']) ? $data['session']['sessionId'] : 'default';
- file_put_contents('alexaInput.json', 'TIPOLOGIA INTENT : ' . $intentType, FILE_APPEND);
- if ($intentType == 'LaunchRequest'){
- $responseArray = [
- 'version' => '1.0',
- 'response' => [
- 'outputSpeech' => [
- 'type' => 'PlainText',
- 'text' => 'Ciao, stai entrando o uscendo?',
- 'ssml' => null
- ],
- 'reprompt' => [
- 'outputSpeech' => [
- 'type' => 'PlainText',
- 'text' => 'Tempo di risposta esaurito',
- 'ssml' => null
- ]
- ],
- 'shouldEndSession' => false
- ]
- ];
- } elseif ($intentType == 'IntentRequest'){
- switch($intent) {
- case 'AzioneIntent':
- $azione = !empty($intentData['name']['value']) ? $intentData['name']['value'] : '';
- if (!empty($azione)) {
- $responseArray = [
- 'version' => '1.0',
- 'response' => [
- 'outputSpeech' => [
- 'type' => 'PlainText',
- 'text' => 'Ok, mi hai inviato : ' . $azione,
- 'ssml' => null
- ],
- 'shouldEndSession' => false
- ]
- ];
- }
- break;
- case 'IDIntent':
- $id = !empty($intentData['name']['value']) ? $intentData['name']['value'] : '';
- if (!empty($id)){
- $responseArray = [
- 'version' => '1.0',
- 'response' => [
- 'outputSpeech' => [
- 'type' => 'PlainText',
- 'text' => 'Ok, mi hai inviato il seguente identificativo : ' . $id,
- 'ssml' => null
- ],
- 'shouldEndSession' => false
- ]
- ];
- }
- break;
- }
- }
- /*
- $responseArray = [
- 'version' => '1.0',
- 'response' => [
- 'outputSpeech' => [
- 'type' => 'PlainText',
- 'text' => 'Ciao, inviami il tuo identificativo',
- 'ssml' => null
- ],
- 'shouldEndSession' => false
- ]
- ];
- */
- header ('Content-Type: application/json');
- file_put_contents('alexaOutput.json', json_encode($responseArray, JSON_PRETTY_PRINT));
- echo json_encode($responseArray);
- die();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement