我是IBM Watson助手的新手。我开发了ASP.net Web API来调用对IBM Watson Assistant的请求。根对话框节点工作正常。但是未输入子对话框节点。我试图发送带有下一个请求的先前响应内容。但这行不通。
以下代码显示了我如何尝试通过新请求发送内容。但是服务器返回状态码400错误的请求。
[HttpPost]
[Route("api/ChatbotApi/ResponseMessage")]
public async Task<String[]> ResponseMessage([FromBody]JObject data)
{
string context = data["context"].ToString();
string input = data["text"].ToString();
string request = null;
string responseOut = null;
string contextOut = null;
JObject jo = null;
JObject jResult = null;
String[] responce = new String[2];
if (string.IsNullOrEmpty(context))
{
request = "{\"input\": {\"text\": \"" + input + "\"}, \"alternate_intents\": true}";
}
else
{
request = "{\"input\": {\"text\": \"" + input + "\"}, \"alternate_intents\": true}, \"context\": \"" + context + "\"";
}
using (var handler = new HttpClientHandler
{
Credentials = networkCredential
})
using (var client = new HttpClient(handler))
{
var cont = new HttpRequestMessage();
cont.Content = new StringContent(request.ToString(), Encoding.UTF8, "application/json");
var result = await client.PostAsync(serverLink, cont.Content);
string respose = await result.Content.ReadAsStringAsync();
string responseBody = JsonConvert.DeserializeObject(respose).ToString();
jo = JObject.Parse(responseBody);
responseOut = jo["output"]["text"][0].ToString();
contextOut = jo["context"].ToString();
responce[0] = responseOut;
responce[1] = contextOut ;
}
return responce;
}
我现在需要如何设置下一个请求的上一个响应的内容。