Last active
August 21, 2018 22:09
-
-
Save douglascabral/4e7c8efe80480461d41a0ab507b8c76a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
$body = file_get_contents("php://input"); | |
$bodyjson = json_decode($body); | |
$number1 = $bodyjson->queryResult->parameters->number1; | |
$number2 = $bodyjson->queryResult->parameters->number2; | |
$action = $bodyjson->queryResult->action; | |
$result = 0; | |
switch ($action) { | |
case 'somar': | |
$result = $number1 + $number2; | |
break; | |
case 'subtrair': | |
$result = $number1 - $number2; | |
break; | |
case 'dividir': | |
$result = $number1 / $number2; | |
break; | |
case 'multiplicar': | |
$result = $number1 * $number2; | |
break; | |
} | |
$response = [ | |
'fulfillmentText' => $result | |
]; | |
$json = json_encode($response); | |
echo $json; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment