我正在创建一个facebook机器人我使用了chatfuel来创建该机器人,我使用Json API将用户的所有回复发送到我的服务器,因为“我想将从用户消息中检索的数据传递给我的Json API,以便从/向我的数据库中获取/添加数据。例如:
用户回复:
我叫彼得
我想将"Peter“发送到我的api,并使用get或post请求将其添加到我的数据库中。
我在这里被告知使用wit.ai:
https://community.chatfuel.com/t/send-variables-from-the-users-message-to-the-json-api/4406
我想链接我的php服务器,这是连接到我的数据库与wit.ai创建我的机器人的人工智能。
我需要详细的步骤来遵循或一个简单的模板。
任何简单的信息都会有很大帮助。
谢谢
发布于 2017-02-20 18:27:20
看起来您想要使用Wit.ai进行实体提取。该实体是联系人的姓名。在您的示例中,这将是Peter。
Wit有一个可以使用的HTTP API。
https://wit.ai/docs/http/20160526
首先,在Wit中创建一个应用程序。然后让PHP应用程序将消息传递给Wit API。
curl \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
'https://api.wit.ai/message?v=20170220&q=My%25name%25is%25Peter'你可以从应用程序设置中获取'BEARER_TOKEN‘。
API将返回带有实体和置信度分数的JSON输出。
{
"msg_id" : "c811ca24-4322-4a6e-b251-192ee59a8b83",
"_text" : "My%name%is%Peter",
"entities" : {
"contact" : [ {
"confidence" : 0.8265228299921754,
"type" : "value",
"value" : "Peter",
"suggested" : true
} ]
}然后,您应该能够从JSON输出中获取实体并将其添加到数据库中。
发布于 2017-02-22 22:51:35
根据上面Bcf Ant的评论,下面是如何在PHP中进行调用。将您要解析的字符串放入$input_utterance中,并将XXXXXXXXXXX替换为您的令牌ID:
$witRoot = "https://api.wit.ai/message?";
$witVersion = "20170221";
$witURL = $witRoot . "v=" . $witVersion . "&q=" . $input_utterance;
$ch = curl_init();
$header = array();
$header[] = "Authorization: Bearer XXXXXXXXXX”;
curl_setopt($ch, CURLOPT_URL, $witURL);
curl_setopt($ch, CURLOPT_POST, 1); //sets method to POST (1 = TRUE)
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); //sets the header value above - required for wit.ai authentication
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //inhibits the immediate display of the returned data
$server_output = curl_exec ($ch); //call the URL and store the data in $server_output
curl_close ($ch); //close the connectionhttps://stackoverflow.com/questions/42318510
复制相似问题