澄清GenerateMessages()方法的用法
问题描述:
使用Prompter方法在FormFlow中发送自定义卡片。查看代码看到有一个GenerateMessages()方法,对于下面的代码总是返回false。有人可以澄清为什么/何时使用这种方法?澄清GenerateMessages()方法的用法
.Prompter(async (context, prompt, state, field) => {
var preamble = context.MakeMessage();
var promptMessage = context.MakeMessage();
if (prompt.GenerateMessages(preamble, promptMessage))
{
await context.PostAsync(preamble);
}
else
{
promptMessage.Text = prompt.Prompt;
var attachment = Helper.GetAttachment();
promptMessage.Attachments.Add(attachment);
await context.PostAsync(promptMessage);
}
答
为.GenerateMessages的代码可以在这里找到:https://github.com/Microsoft/BotBuilder/blob/497252e8d9949be20baa2cebaa6ce56de04461cf/CSharp/Library/Microsoft.Bot.Builder/FormFlow/IPrompt.cs#L248
除非有看来,返回False:
- 按钮或在图像说明AND
- 提示中的一个或多个Environment.NewLine字符
我还没有亲自使用过它,但是看起来这种方法在使用FormFlow定义多行提示消息时很有用。由于所有通道都不支持降价,因此此方法提供了一些解决方法:启用多线消息。