PHP - 从 Dialogflow Parse 接收 JSON 到 URL
PHP - Receive JSON from Dialogflow Parse to URL
正在尝试创建一个 php 脚本,该脚本将从 Dialogflow webhook 接收 JSON。
然后需要解析数据,
<?php
$input = json_decode(file_get_contents('php://input'), true);
$messageId = $input["resolvedQuery"];
$text = print_r($input,true);
file_put_contents('output.txt', var_export($text, TRUE));
$url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=APAue83jLrt7xFeQoGjgKq&message=" . $messageId;
$data = array("result" => "resolvedQuery");
$ch = curl_init($url);
$data_string = json_encode($messageId);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("resolvedQuery"=>$data_string));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type:application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
?>
我需要的数据来自 resolvedQuery 但我没有得到任何输出。
有人能给我指出正确的方向吗
所以根据我的理解,你需要在你的 webhook 中从 api.ai resolvedQuery。您需要做的就是更改:
$messageId = $input["resolvedQuery"];
至
$messageId = $input['result']['resolvedQuery'];
检查并告诉我它是否有效。我在 php 中集成了 Skype、fb 和 google,所以如果您需要任何帮助,请随时询问。
正在尝试创建一个 php 脚本,该脚本将从 Dialogflow webhook 接收 JSON。
然后需要解析数据,
<?php
$input = json_decode(file_get_contents('php://input'), true);
$messageId = $input["resolvedQuery"];
$text = print_r($input,true);
file_put_contents('output.txt', var_export($text, TRUE));
$url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=APAue83jLrt7xFeQoGjgKq&message=" . $messageId;
$data = array("result" => "resolvedQuery");
$ch = curl_init($url);
$data_string = json_encode($messageId);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("resolvedQuery"=>$data_string));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type:application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
?>
我需要的数据来自 resolvedQuery 但我没有得到任何输出。
有人能给我指出正确的方向吗
所以根据我的理解,你需要在你的 webhook 中从 api.ai resolvedQuery。您需要做的就是更改:
$messageId = $input["resolvedQuery"];
至
$messageId = $input['result']['resolvedQuery'];
检查并告诉我它是否有效。我在 php 中集成了 Skype、fb 和 google,所以如果您需要任何帮助,请随时询问。