Cortana技能中没有使用FormFlow提示

时间:2017-06-09 18:29:33

标签: c# botframework formflow cortana-skills-kit

我正在通过使用FormFlow构建机器人来构建Coratana技能。我使用LUIS检测我的意图和实体,并将实体传递给我的FormFlow对话框。如果未填写一个或多个FormFlow字段,FormFlow对话框将提示用户填写缺少的信息,但不会说出此提示,仅显示在cortana屏幕上。 FormFlow有没有办法说出提示?

在下面显示的屏幕截图中,提示“你需要机场班车吗?”只是显示而没有说出来:

enter image description here

我的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; }
}

2 个答案:

答案 0 :(得分:6)

我认为FormFlow目前不支持Speak。

您可以做什么,作为一种解决方法是添加IMessageActivityMapper,基本上可以促使文字自动发言。

namespace Code
{
    using Microsoft.Bot.Builder.Dialogs;
    using Microsoft.Bot.Builder.Dialogs.Internals;
    using Microsoft.Bot.Connector;

    /// <summary>
    /// Activity mapper that automatically populates activity.speak for speech enabled channels.
    /// </summary>
    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<TextToSpeakActivityMapper>()
   .AsImplementedInterfaces()
   .SingleInstance();

 builder.Update(Conversation.Container);

答案 1 :(得分:2)

Ezequiel 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;
}