Cortana技能中没有使用FormFlow提示
我正在通过使用FormFlow构建机器人来构建Coratana技能。 我使用LUIS检测我的意图和实体,并将实体传递给我的FormFlow对话框。 如果未填写一个或多个FormFlow字段,FormFlow对话框将提示用户填写缺少的信息,但不会说出此提示,仅显示在cortana屏幕上。 FormFlow有没有办法说出提示?
在下面显示的屏幕截图中,提示“你需要机场class车吗?” 只是显示而不是说:
我的formFlow定义如下所示:
[Serializable] public class HotelsQuery { [Prompt("Please enter your {&}")] [Optional] public string Destination { get; set; } [Prompt("Near which Airport")] [Optional] public string AirportCode { get; set; } [Prompt("Do you need airport shuttle?")] public string DoYouNeedAirportShutle { get; set; } }
我认为FormFlow
目前不支持FormFlow
。
您可以做什么,作为一种解决方法是添加IMessageActivityMapper
,它基本上可以促进文本自动说话。
namespace Code { using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Builder.Dialogs.Internals; using Microsoft.Bot.Connector; /// /// Activity mapper that automatically populates activity.speak for speech enabled channels. /// public sealed class TextToSpeakActivityMapper : IMessageActivityMapper { public IMessageActivity Map(IMessageActivity message) { // only set the speak if it is not set by the developer. var channelCapability = new ChannelCapability(Address.FromActivity(message)); if (channelCapability.SupportsSpeak() && string.IsNullOrEmpty(message.Speak)) { message.Speak = message.Text; } return message; } } }
然后要使用它,您需要在Global.asax.cs
文件中注册它:
var builder = new ContainerBuilder(); builder .RegisterType() .AsImplementedInterfaces() .SingleInstance(); builder.Update(Conversation.Container);
答案formsEzequiel Jadib帮助我解决了我的用例需要的东西。 如果文本是一个问题,我只是添加了一些额外的行来将InputHint
字段设置为ExpectingInput
。 通过这种配置,Cortana会自动收听我的回答,而我不必自己激活麦克风。
public IMessageActivity Map(IMessageActivity message) { // only set the speak if it is not set by the developer. var channelCapability = new ChannelCapability(Address.FromActivity(message)); if (channelCapability.SupportsSpeak() && string.IsNullOrEmpty(message.Speak)) { message.Speak = message.Text; // set InputHint to ExpectingInput if text is a question var isQuestion = message.Text?.EndsWith("?"); if (isQuestion.GetValueOrDefault()) { message.InputHint = InputHints.ExpectingInput; } } return message; }