【发布时间】:2020-04-25 10:17:26
【问题描述】:
我有一个由 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 之间的任何位置添加新问题,机器人是否可以检测到更改并相应地进行调整?这可能吗?
【问题讨论】:
-
我在multiple-waterfall-conversation 上发布了一个类似的问题,请告诉我您是如何解决问题的
标签: c# dialog botframework chatbot