我正在使用Wit.ai编写机器人,但我无法理解上下文。更具体地说,如何/何时设置它。正如我所理解的那样,您可以通过在您认为合适的任何时间点发布到API来设置上下文,例如在执行机智故事中定义的功能时。至少这是我用下面的代码瞄准的方法。可悲的是,它会产生错误,所以我想知道,我是否试图以不正确的方式设置上下文或者我的Guzzle帖子有什么问题?
private function storeUserName($entities) {
$witcall = $this->wit->post($this->wit_base_url.'/converse',
[
'form_params' => [
'username' => $entities->contact[0]->value
],
'query' => [
'v' => '1',
'session_id' => 'vk-'.$this->thread_id
],
'headers' => [
'Authorization' => 'Bearer '.env('WIT_TOKEN', false)
]
]
);
return [
'msg' => 'nice',
'type' => 'msg'
];
}
我的错误:
ClientException in RequestException.php line 111:
Client error: `POST https://api.wit.ai/converse?v=1&session_id=vk-1` resulted in a `400 Bad Request` response:
Unable to parse context in body
答案 0 :(得分:0)
事实证明使用form_params
不正确,已更改为json
,现在效果正常。像这样:
$call = $this->wit->request('POST', 'converse', [
'json' => $this->context,
'query' => [
'v' => '1',
'session_id' => 'vk-'.$this->thread_id
]
]);