How do I execute custom methods in Wit.ai from a PHP API?

会有一股神秘感。 提交于 2020-02-05 03:53:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!