I am using DIalogflow (api.ai) to create chat interfaces. I created a webhook from Dialogflow to a simple app containing a php script deployed on Heroku.
Therefore, I placed in the webhook form of Dialogflow the url of my Heroku app which resembles to this: https://my_heroku_app_name.herokuapp.com.
My ultimate goal is to fetch some data from a database (through the php script) and then feed Dialogflow with them. For now, I am only trying to connect the Heroku app (php script) with Dialogflow through a webhook.
The php script of the Heroku app is the following:
<?php
$method = $_SERVER['REQUEST_METHOD'];
if($method == 'GET'){
    $requestBody = file_get_contents('php://input');
    $json = json_decode($requestBody);
    $text = $json->metadata->intentName->text;
    switch ($text) {
        case 'Name':
            $speech = "This question is too personal";
            break;    
        default:
            $speech = "Sorry, I didnt get that.";
            break;
    }
    $response = new \stdClass();
    $response->speech = $speech;
    $response->displayText = $speech;
    $response->source = "webhook";
    echo json_encode($response);
}
else
{
    echo "Method not allowed";
}
?>
Keep in mind the following:
- $methodis- GETfor some reason instead of- POSTas it is supposed to be from Dialogflow.
- if you try to echo any of the variables $requestBody,$jsonor$textthen nothing is printed.
- I have tested that the ifbranch is executed and that thedefaultbranch is executed atswitch.
Why my PHP script cannot "see" the webhook from DIaloflow and fetch the data from it so as to respond appropriately?
P.S. My question is not a duplicate of Valid JSON output but still getting error. The former is about the input of the php script whereas the latter is about the output of the php script. These two things do not necessarily constitute identical problems.
 
    