Search code examples
c#botframeworktextinputadaptive-cardsweb-chat

How to get the value on the change of AdaptiveCard controls in ChatBot?


I am using the AdaptiveCard input control in my microsoft ChatBot. Can any one give me hints how to get the change property or event of the TextInput or ChoiceSet of Adaptive Control. For example on the selection of ChoiceSet i want to populate some value in the TextInput Control?

               //new TextBlock() { Text = "Country" },
               new ChoiceSet()
               {
                   Id = "Country",
                   Speak = "<s>Please enter your country.</s>",
                   IsMultiSelect = false,
                   Style = ChoiceInputStyle.Compact,
                   Separation= SeparationStyle.Default,
                   Choices = choices,
                   Value = "country"
                 },
               new TextInput()
               {
                   Id = "Mobile",
                   Speak = "<s>Please enter your mobile with country code.</s>",
                   Placeholder = "+(country code)(Your Phone Number)",
                   Style = TextInputStyle.Tel,
                   IsRequired = true
               },

Solution

  • Web Chat doesn't offer this sort of functionality. I can think of a few workarounds.

    Option 1: Use multiple cards

    You could send one card that lets the user select a country, and then once that selection is sent to the bot, on the next turn the bot could send another card with a text input with the country code filled in.

    Option 2: Indicate the country code in the choice set

    You could have the user enter the country code manually. You'd just need to make sure your bot tells them that they need to do this, and you could indicate what country code is associated with each choice, possibly in the choice set itself.

    Option 3: Automatically prepend the country code on the bot side

    While Web Chat v4 is very customizable, your bot is even more customizable because you can write whatever code you want. Specialized functionality like this is best handled in the bot itself because you only have so much control over client applications. If you make it clear that the user doesn't need to include a country code, your bot can just add the country code to the phone number based on the selected country. You can even make the bot smart enough to detect if a country code is already there before it adds one.