如何在Bot Framework C#中在运行时生成瀑布图步骤?

问题描述 投票:1回答:1

我有一个由Bot Framework v4制作的聊天机器人,正在阅读他想向用户询问的机器人响应和问题。

这是一个单独的文件:

BotQuestions.cs

 public class BotQuestions{

    public string Intro = "Welcome to Chat Session! I am Mr. A, your assistant.";

    public string AskFood = "How was your experience with our food?";

    public string Acknowledge = "I am glad that you liked our food!";

    public string Sad = "We apologize that you didn't enjoy our food. We will take care of it next time";
 }

然后我在定义了WaterFall步骤的Bot类中调用此类。

ChatBotDialog.cs

public class ChatBotDialog : CancelAndHelpDialog
{

   public static BotQuestions question = new BotQuestions();

   public ChatBotDialog(UserState userState, ConversationState conversationState) : 

   base(nameof(ChatBotDialog))
   {
       memoryStorage = new MemoryStorage();

       _conversationState = conversationState;

       // the waterfall method to maintain the order of the chat
       var waterfallSteps = new WaterfallStep[]
       {
           IntroStepAsync,
           AskFoodStepAsync,
           AckStepAsync,
           SadAsync
       }; 

    // adding named dialogs to the Dialog Set. These names are saved in dialog set
    AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
    AddDialog(new TextPrompt(nameof(TextPrompt)));


    // run the initial child dialog
    InitialDialogId = nameof(WaterfallDialog);
   }

  private static async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
  {
      Activity reply = stepContext.Context.Activity.CreateReply();
        reply.Type = ActivityTypes.Typing;
        ConnectorClient connector = new ConnectorClient(new Uri(stepContext.Context.Activity.ServiceUrl));
        await connector.Conversations.ReplyToActivityAsync(reply);


        //BotReplyTime();
        var promptOptions = new PromptOptions
        {
            Prompt = MessageFactory.Text(questions.Intro) // here I am accessing the Bot Question class string property and its value.
        };
        return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);

     }


private static async Task<DialogTurnResult> AskFoodStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken){
  // similar logic
 }


private static async Task<DialogTurnResult> AcknowledgeStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken){
  // similar logic
}


private static async Task<DialogTurnResult> SadStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken){
  // similar logic
  }
 }

如您所见,ChatBotDialog具有瀑布步骤,并且每个步骤都调用BotQuestions类以访问字符串值。

现在的情况是>>如果我想在BotQuestions.cs中添加一个新问题,我必须再次生成字符串值,生成相应的瀑布步骤,然后运行看起来非常笨拙的对话框...那么有没有一种方法可以在运行时动态生成瀑布步? (<< [仅在C#中)如果我在BotQuestions.cs之间的任何地方添加新问题,机器人是否有办法检测到更改并相应地进行调整?这可能吗?

我有一个由Bot Framework v4制作的聊天机器人,我正在阅读他想向用户询问的机器人响应和问题。这是一个单独的文件:BotQuestions.cs公共类BotQuestions {...
c# dialog botframework chatbot
1个回答
1
投票
无法动态添加瀑布台阶。
© www.soinside.com 2019 - 2024. All rights reserved.