Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot view the output with echo

Array
(
    [id] => 9794ea5d-9dc1-4b15-a798-fd0fa4ff6f4c
    [timestamp] => 2017-07-05T03:47:00.764Z
    [lang] => en
    [result] => Array
        (
            [source] => agent
            [resolvedQuery] => what is annual leave
            [speech] => 
            [action] => test
            [actionIncomplete] => 
            [parameters] => Array
                (
                    [allowance_type] => Array
                        (
                        )

                    [bonus_type] => Array
                        (
                        )

                    [salary_type] => Array
                        (
                        )

                    [leave_type] => Array
                        (
                            [0] => annual leave
                        )

                )

            [contexts] => Array
                (
                    [0] => Array
                        (
                            [name] => to-apply
                            [parameters] => Array
                                (
                                    [allowance_type] => Array
                                        (
                                        )

                                    [leave_type] => Array
                                        (
                                            [0] => annual leave
                                        )

                                    [bonus_type.original] => 
                                    [bonus_type] => Array
                                        (
                                        )

                                    [leave_type.original] => annual leave
                                    [allowance_type.original] => 
                                    [salary_type] => Array
                                        (
                                        )

                                    [salary_type.original] => 
                                )

                            [lifespan] => 5
                        )

                )

            [metadata] => Array
                (
                    [intentId] => e2bda510-2f4d-41b8-a80b-e11f148c804b
                    [webhookUsed] => true
                    [webhookForSlotFillingUsed] => false
                    [intentName] => description-definition-what
                )

            [fulfillment] => Array
                (
                    [speech] => 
                    [messages] => Array
                        (
                            [0] => Array
                                (
                                    [type] => 0
                                    [speech] => 
                                )

                        )

                )

            [score] => 1
        )

    [status] => Array
        (
            [code] => 200
            [errorType] => success
        )

    [sessionId] => 07a5acce-9587-4f06-b715-1c9106732109
)

Hi so i have this code where im trying to create a webhook to call the json file from API.AI. It gets the data and saves in a new file call JSON.php but im trying to echo out the data it is not happening. Is because the page is not auto refresh or?

<?php

$data = json_decode(file_get_contents("php://input"), true);
file_put_contents("JSON.php", print_r($data, true));

echo $data['intentName'];

?>
like image 757
Rajveer Singh Avatar asked Jun 30 '26 13:06

Rajveer Singh


1 Answers

So it should be $data['result']['metadata']['intentName']; instead of $data['intentName']

like image 123
Huy Trịnh Avatar answered Jul 02 '26 02:07

Huy Trịnh