botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Cortana & .NET SDK] Cortana FormFlow problems

Open fr6087 opened this issue 8 years ago • 6 comments

Bot Info

  • SDK Platform: .NET
  • SDK Version:
  • Active Channels: Cortana, Skype, Direct Line, Web Chat
  • Deployment Environment: Azure Bot Service, local development with Emulator, Cortana

Issue Description

I created a .json file for my FormFlow Dialoge. It contains a .Before Message Property in the first properties object as in the AnnotatedSandwich.json. Cortana does not interpret the Before message correctly. It is displaying the message AFTER asking the first question. And then, Cortana is unable to proceed with the other questions.

Code Example

`"properties": {

"Vorname": {
  "Before": [
    {
      "Message": [
        "Welcome at form section 1"
      ]
    }
  ],
    "Prompt":
    {
      "Patterns": [ "What is your given name?" ]
    },
    "type":
    [
      "string",
      "null"
    ]
},

`

Reproduction Steps

  1. create json file in Bot Temlate as described in AnnotatedSandwich, add a "Before-property"
  2. let the Formbuilder access the JSON file
  3. publish the Bot to Azure
  4. register the Bot for Cortana channel
  5. check that your device's settings are for USA
  6. invoke the Bot as Cortana Skill by invocation

Expected Behavior

I expected the before message to be displayed before the question prompting for the particular property.

Actual Results

After answering "what is your given name" the before message appears and the formflow dialoge stops. The canvas is not refreshed with the next question.

fr6087 avatar Apr 03 '18 09:04 fr6087

I'll look into this and get back to you soon.

EricDahlvang avatar Apr 04 '18 00:04 EricDahlvang

I know, it's not strictly issue related, but suppose I want to access the UserInfo.GivenName property from the Cortana Notebook and integrate that into the prompt "what is your given name?" Like "I got your given name from the notebook as <user's name>. Is that correct?" How would I express that in json code? I know I can attach Validate functions. But they are executed after the prompt. Can I call a function before a prompt?

fr6087 avatar Apr 05 '18 09:04 fr6087

It seems the "Before" is actually being sent, but it is followed immediately by the next message. If "Before" is not read by cortana, it just flashes on the canvas. I found some code here: https://stackoverflow.com/questions/44464575/formflow-prompts-are-not-being-spoken-in-cortana-skills that might help. If you add a IMessageActivityMapper that checks for and empty .Speak, it seems to then read out the Before followed by the next message. Please try this, and let me know if it solves your issue:

            Conversation.UpdateContainer(
                builder =>
                {
                    builder
                       .RegisterType<TextToSpeakActivityMapper>()
                       .AsImplementedInterfaces()
                       .SingleInstance();
                });
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;
    }
}

I haven't tried this, but I think you should be able to get the username via c# script in a Define property.
https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow-json-schema#additional-properties-as-peers-of-the-type-property

EricDahlvang avatar Apr 06 '18 21:04 EricDahlvang

@fr6087 Is the above code a valid workaround for you?

EricDahlvang avatar Apr 11 '18 22:04 EricDahlvang

@EricDahlvang I don't think that is going to solve the problem. I have already added this code snippet from Jadib to my bot earlier. When I run the bot now, it doesn't display the before message. It just runs through the questions. I can't even use FormFlow commands like "quit" to make the bot dialog stop. Oh, and I managed to get an error because I was typing fast and trying to get through all of the questions. "current status is BotTurn, not allowed user input come". Then I tested again with speech input. Cortana spoke back to me, but it also left out the before message. The error could be related to the modified code version that I'm using in the TextToSpeakActivitymapper.cs: message.Speak = message.Text; var isQuestion = message.Text?.EndsWith("?"); if (isQuestion.GetValueOrDefault()) { message.InputHint = InputHints.ExpectingInput; }

fr6087 avatar Apr 16 '18 07:04 fr6087

Using this .json file:

{
  "type": "object",
  "Templates": {
    "NotUnderstood": {
      "Patterns": [ "I do not understand \"{0}\".", "Try again, I don't get \"{0}\"." ]
    },
    "EnumSelectOne": {
      "Patterns": [ "What kind of {&} would you like on your sandwich? {||}" ],
      "ChoiceStyle": "Auto"
    }
  },
  "properties": {
    "Sandwich": {
      "Prompt": { "Patterns": [ "What kind of {&} would you like? {||}" ] },
      "Before": [ { "Message": [ "Welcome to the sandwich order bot!" ] } ],
      "Describe": { "Image": "https://placeholdit.imgix.net/~text?txtsize=16&txt=Sandwich&w=125&h=40&txttrack=0&txtclr=000&txtfont=bold" },
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "BLT",
        "BlackForestHam",
        "BuffaloChicken",
        "ChickenAndBaconRanchMelt"
      ]
    },
    "Length": {
      "Prompt": {
        "Patterns": [ "What size of sandwich do you want? {||}" ]
      },
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "SixInch",
        "FootLong"
      ]
    },
    "Rating": {
      "Describe": "your experience today",
      "type": [
        "number",
        "null"
      ],
      "minimum": 1,
      "maximum": 5,
      "After": [ { "Message": [ "Thanks for ordering your sandwich!" ] } ]
    }
  }
}

With this global.asax.cs:

public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            Conversation.UpdateContainer(
                builder =>
                {
                    builder
                       .RegisterType<TexttoSpeech>()
                       .AsImplementedInterfaces()
                       .SingleInstance();
                });
        }

        public sealed class TexttoSpeech : IMessageActivityMapper
        {
            public IMessageActivity Map(IMessageActivity message)
            {
                var channelCapability = new ChannelCapability(Address.FromActivity(message));

                if (channelCapability.SupportsSpeak() && string.IsNullOrEmpty(message.Speak))
                {
                        message.Speak = message.Text;
                }

                return message;
            }
        }
    }

Results in: cortanabefore

EricDahlvang avatar Apr 17 '18 18:04 EricDahlvang