Bot Framework Direct Line仅适用于调试器

我有一个使用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

这是在调试器外部运行时的响应:

Only Activity 0 returned

回答(1)

2 years ago

通过使用一个小延迟和一个循环来修复它,这个循环将继续发出GET请求直到Bot响应 .