我有一个使用QnA Maker和LUIS来回答常见问题和要求的BOT,我正在尝试对另一个BOT实施直接线路。基本上,只要我的BOT不知道答案,它就会将用户消息发送到另一个BOT,以检查它是否知道答案并输出结果。当我使用Debugger逐步检查代码时,Direct Line可以正常工作(GET请求以我发送的消息和来自BOT的答复进行响应)。但是,当我正常运行代码时,响应仅包含我发送的消息,而不包含其他BOT的答复。我在想,当代码在调试器之外运行时,GET请求结束得太快,以至于BOT无法响应,而且我不知道如何解决或扩展该请求。有什么想法吗?
以下是相关代码:
public class EdwardComponent
{
public static async Task<string> TalkToEdward(string userInput, string conversationID, string streamURL)
{
var DirectLineURL = ConfigurationManager.AppSettings["DirectLineURL"];
var BearerToken = ConfigurationManager.AppSettings["BearerToken"];
var DirectLineURLConversationID = ConfigurationManager.AppSettings["DirectLineURLConversationID"];
DirectLineURLConversationID = DirectLineURLConversationID.Replace("abc123", conversationID);
var postclient = new RestClient(DirectLineURLConversationID);
var postrequest = new RestRequest(Method.POST);
postrequest.AddHeader("Authorization", BearerToken);
postrequest.AddHeader("Content-Type", "application/json");
postrequest.RequestFormat = DataFormat.Json;
var idv = new { id = "user1" };
postrequest.AddBody(new { type = "message", from = idv, text = userInput });
var cancellationTokenSource = new CancellationTokenSource();
var postresponse = postclient.ExecuteAsPost(postrequest, "POST");
var getrequest = new RestRequest(Method.GET);
getrequest.AddHeader("Authorization", BearerToken);
var getresponse = await postclient.ExecuteGetTaskAsync(getrequest);
string content = getresponse.Content.ToString();
return content;
}
}
}
这是调试产生的正确的序列化响应:
Activity 0 is the message sent, Activity 1 is the response from BOT
这是在调试器外部运行时的响应:
答案 0 :(得分:0)
使用一个小的延迟和一个循环将其修复,该循环将继续发出GET请求,直到Bot响应为止。