【问题标题】:Dialog Continuation Issue on Bot Framework V4Bot Framework V4 上的对话继续问题
【发布时间】:2020-04-15 06:33:17
【问题描述】:

我想在我的机器人中显示欢迎消息后立即启动用户对话 - 无需任何初始用户交互。
代码 sn-p 来完成:

public RootDialogBot(BotServices services, BotAccessors accessors, ILoggerFactory loggerFactory)
        {
            if (loggerFactory == null)
            {
                throw new System.ArgumentNullException(nameof(loggerFactory));
            }

            _logger = loggerFactory.CreateLogger<RootDialogBot>();            
            _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors));
            _botServices = services ?? throw new System.ArgumentNullException(nameof(services));

            _studentProfileAccessor = _accessors.UserState.CreateProperty<StudentProfile>("studentProfile");

            if (!_botServices.QnAServices.ContainsKey("QnAMaker"))
            {
                throw new System.ArgumentException($"Invalid configuration. Please check your '.bot' file for a QnA service named QnAMaker'.");
            }
            if (!_botServices.LuisServices.ContainsKey("LUIS"))
            {
                throw new System.ArgumentException($"Invalid configuration. Please check your '.bot' file for a Luis service named LUIS'.");
            }                     
                .Add(new Activity2MainDialog(_accessors.UserState, Activity2MainDialog))
                .Add(new Activity2LedFailToWorkDialog(_accessors.UserState, Activity2LedFailToWorkDialog));            
        }
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
...
if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
            {                
                if (turnContext.Activity.MembersAdded != null)
                {
                    // Save the new turn count into the conversation state.
                    await _accessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
                    await _accessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
                    var message = "Welcome!";
                    await SendWelcomeMessageAsync(turnContext, dc, message,cancellationToken);  //Welcome message
                }
            } 
...
}
private static async Task SendWelcomeMessageAsync(ITurnContext turnContext, DialogContext dc,string message, CancellationToken cancellationToken)
        {
            foreach (var member in turnContext.Activity.MembersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    await turnContext.SendActivityAsync(message, cancellationToken: cancellationToken);
                    await dc.BeginDialogAsync(Activity2MainDialog, "activity2MainDialog", cancellationToken);
                }
            }
        }


对话框 (Activity2MainDialog) 工作正常,直到它到达 return await stepContext.ContinueDialogAsync(cancellationToken); 调用。
然后它停止了。
我相信这与对话状态有关,但我仍然找不到解决方案。
return await stepContext.ContinueDialogAsync(cancellationToken); 调用的代码 sn-p

public class Activity2MainDialog : ComponentDialog
    {
        private static BellaMain BellaMain = new BellaMain();
        private static FTDMain FTDMain = new FTDMain();
        private readonly IStatePropertyAccessor<StudentProfile> _studentProfileAccessor;        
    ...
        public Activity2MainDialog(UserState userState, string dialogMainId)
                : base(dialogMainId)
        {
            InitialDialogId = Id;
            _studentProfileAccessor = userState.CreateProperty<StudentProfile>("studentProfile");

            WaterfallStep[] waterfallSteps = new WaterfallStep[]
            {
                MsgWelcomeStepAsync
        ...                
            };

            // Add named dialogs to the DialogSet. These names are saved in the dialog state.
            AddDialog(new WaterfallDialog(dialogMainId, waterfallSteps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
        }
        private async Task<DialogTurnResult> MsgWelcomeStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
        await stepContext.Context.SendActivityAsync("**Oi**", "Oi", cancellationToken: cancellationToken);
            return await stepContext.ContinueDialogAsync(cancellationToken);
        }
        private async Task<DialogTurnResult> QuestGoAheadStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            message = "Vamos nessa?";
            await stepContext.Context.SendActivityAsync(message , message , cancellationToken: cancellationToken);
            retryPromptMessage = message;
            return await stepContext.PromptAsync(nameof(ChoicePrompt),
                        new PromptOptions
                        {
                            Prompt = null,
                            RetryPrompt = MessageFactory.Text(retryPromptMessage, retryPromptSpeakMessage), InputHints.ExpectingInput),            
                            Choices = new[]
                            {
                                    new Choice {Value = "Sim", Synonyms = new List<string> {"yes","yeah","esta","ta","esta","ok","vamos","curti","curtir","claro","tá","sei","top"}},
                                    new Choice {Value = "Não", Synonyms = new List<string> {"no"}}
                            }.ToList(),
                            Style = ListStyle.Auto                            
                        });
        }

关于如何解决它的想法?谢谢

【问题讨论】:

  • 请提供包含return await stepContext.ContinueDialogAsync(cancellationToken); 调用的代码示例。当它“停止”时会发生什么?有错误吗?用户体验如何?
  • 谢谢。它只是停下来。不显示错误消息。当代码运行机器人模拟器时,我们可以看到消息滚出,但消息窗口上没有显示任何内容。但是,当程序停止时,它们会立即显示。请看一下屏幕截图。 1drv.ms/u/s!AnpERZZbH7httIorea3zL9qWk954hQ?e=wsrzvV 返回的附加代码 await stepContext.ContinueDialogAsync(cancellationToken) 现在已添加到问题声明中。您可以在1drv.ms/t/s!AnpERZZbH7httIosV2-i6yWeng9bSg 获得更全面的代码

标签: botframework


【解决方案1】:

我相当确定问题出在ContinueDialog 电话上。您需要以以下方式结束该步骤:

return await stepContext.NextAsync(null, cancellationToken);

更多示例代码见CoreBot

如果这没有解决您的问题,请告诉我,我会调整答案。

【讨论】:

  • 你是对的。它现在正在工作!非常感谢您的帮助。
猜你喜欢
  • 2019-07-27
  • 2022-11-14
  • 1970-01-01
  • 2021-01-27
  • 1970-01-01
  • 2019-07-20
  • 2020-07-01
  • 1970-01-01
  • 2022-12-21
相关资源
最近更新 更多