Skip to content

Instantly share code, notes, and snippets.

@douglascabral
Last active August 21, 2018 22:09
Show Gist options
  • Save douglascabral/4e7c8efe80480461d41a0ab507b8c76a to your computer and use it in GitHub Desktop.
Save douglascabral/4e7c8efe80480461d41a0ab507b8c76a to your computer and use it in GitHub Desktop.
<?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