问题
I have a bot on Wit.ai which I would like to make calls to a PHP API. Is there any way to go about this? I've seen how to do it for JavaScript and Python but I can't seem to find a way to do this for PHP.
回答1:
Apparently, the way to perform custom operations or make method calls is based on the response entities. You can make request to wit.ai, which send a response with certain entities based on the intelligence learned from the request. When you get the response use it to perform custom operations on your server side based on the entities in the response.
回答2:
There is no API for PHP but you can use the HTTP API instead to make REST calls. I did the same for Java. The /converse endpoint shows how to proceed with HTTP calls.
回答3:
you can try curl to use HTTP API, but it always gives the token error, I couldn't fix that part.
$ch = curl_init();
$postFields = [
'v' => '20180207',
'q' => 'Hello'
];
$headers = [
'Authorization:' => 'Bearer $TOKEN'
];
curl_setopt($ch, CURLOPT_URL, 'https://api.wit.ai/message');
curl_setopt($ch, CURLOPT_HEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
echo $server_output;
来源:https://stackoverflow.com/questions/44588584/how-do-i-execute-custom-methods-in-wit-ai-from-a-php-api