无法在botframework SDK v3上发送重试消息

时间:2019-01-20 14:36:13

标签: botframework

我一直在使用Direct Line在Bot Framework V3上构建解决方案。 该漫游器工作正常,但是当用户首次提出问题时,它会在聊天窗口中引发“无法发送重试”消息,然后回复该用户。 我的应用程序使用LUIS和QnA Maker。 当请求QnA Maker答案时,总是会发生此问题。 我最好的猜测是QnaMakers会触发超时,直到答案已缓存在内存中。 根对话框代码段:

   [LuisIntent("QnAMaker")]
    public async Task QnAMaker(IDialogContext context, LuisResult result)
    {
            await context.Forward(new QnaMakerDialog(), AfterQnADialog, context.Activity, CancellationToken.None);                

    }

QnaMaker代码段:

 [Serializable]
    public class QnaMakerDialog : QnAMakerDialog
    {
        public QnaMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(BellaMain.GlobalVariable.QnAAuthKey, BellaMain.GlobalVariable.QnAKnowledgebaseId, "Couldn't find your answer. Can you re-phrase it please?", 0.5, 1, BellaMain.GlobalVariable.QnAEndpointHostName)))
        {
        }

        protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
        {
            var messageString = result.Answers.First().Answer;         
            await context.PostAsync(messageString);
            context.Wait(MessageReceivedAsync);
        }
}

消息控制器代码:

public class MessagesController : ApiController
{
    /// <summary>
    /// POST: api/Messages
    /// Receive a message from a user and reply to it
    /// </summary>


    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        //Global Variables Load
        BellaMain BellaMain = new BellaMain();
        try
        {
            BellaMain.AppStartup();
        }
        catch
        {
            activity.Text = "DB access error";
        }
        BellaMain.GlobalVariable.SetGlobalCustomerID(BellaMain.GlobalVariable.CustomerID);
        // LUIS Credentials Set            
        var luisAttributes = new LuisModelAttribute(BellaMain.GlobalVariable.LuisModelID, BellaMain.GlobalVariable.LuisSubscriptionKey, LuisApiVersion.V2, BellaMain.GlobalVariable.LuisDomainName);
        var luisService = new LuisService(luisAttributes);
        var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
        var activityFromID = "";

        switch (activity.Type)
        {
            case ActivityTypes.Message:
                //** Display a "is typing kind" animation before the bot reply
                var isTypingReply = activity.CreateReply(String.Empty);
                isTypingReply.Type = ActivityTypes.Typing;
                ConnectorClient isTypingConnector = new ConnectorClient(new Uri(activity.ServiceUrl));
                await isTypingConnector.Conversations.ReplyToActivityAsync(isTypingReply);
                await Conversation.SendAsync(activity, () => new Dialogs.RootDialog(luisService).DefaultIfException());                                                  
                break;
            case ActivityTypes.Event:
                var eventActivity = activity.AsEventActivity();
                if (eventActivity.Name == "requestWelcomeDialog")
                {
                    var reply = activity.CreateReply();
                    if (BellaMain.GlobalVariable.BellaWelcomeGreetings != "")
                    {
                        reply.Text = BellaMain.GlobalVariable.BellaWelcomeGreetings;
                        await connector.Conversations.ReplyToActivityAsync(reply);
                        BellaMain.BotWait("while");
                    }
                    // Launches the User Data Collection Form If the Case
                    if (BellaMain.GlobalVariable.FlagCollectUserDataOnConversationStart)
                    {
                        await Conversation.SendAsync(activity, () => new Dialogs.CustomUserDataCollectFormDialogDispacher().DefaultIfException());
                    }
                    //Launches Bella Help If the Case
                    if (BellaMain.GlobalVariable.FlagBellaHelpOnConversationStart)
                    {
                        await Conversation.SendAsync(activity, () => new Dialogs.CustomBellaHelpDispacher().DefaultIfException());
                    }
                }
                break;
        }
        return Request.CreateResponse(HttpStatusCode.OK);
    }       
}

如何避免出现此消息?提前谢谢

1 个答案:

答案 0 :(得分:0)

添加呼叫

MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);

在使用ConnectorClient之前。这样可以确保传出邮件的网址被认为是受信任的。

相关问题