1

I use Bot Framework v4, and I try to use ChoicePrompt for the menu.

I'm trying to create a Choice object, and I see that it contains a CardAction object.

Because CardAction has more options, such as a value that is an object type rather than a string type, I want to use it.

But even if I assign a value to the CardAction value field, I get an error because Choice must get a value in its value, which is the value obtained at the end.

So why does the Choice contain a CardAction object? What is everyone's job?

baruchiro
  • 5,088
  • 5
  • 44
  • 66

1 Answers1

2

CardAction Object

There isn't really any documentation on using CardAction with a ChoicePrompt because ChoicePrompts aren't really "meant" to be used this way. It's possible, but not really preferred.

Here's the reference for the CardAction Class:

DisplayText
Gets or sets (Optional) text to display in the chat feed if the button is clicked

Image
Gets or sets image URL which will appear on the button, next to text label

Text
Gets or sets text for this action

Title
Gets or sets text description which appears on the button

Type
Gets or sets the type of action implemented by this button. Possible values include: 'openUrl', 'imBack', 'postBack', 'playAudio', 'playVideo', 'showImage', 'downloadFile', 'signin', 'call', 'payment', 'messageBack'. More on ActionTypes

Note: ChoicePrompt expects a imBack ActivityType, so using other types can have some odd results.

Value
Gets or sets supplementary parameter for action. Content of this property depends on the ActionType

Title vs. Text

Given the CardAction:

new Choice()
    {
        Action = new CardAction()
        {
            Type = "messageBack",
            Value = "ACTION VALUE",
            Title = "TITLE",
            Text = "TEXT",
        },
        Value = "CARD VALUE",
    });

This will produce:

enter image description here

When clicked:

enter image description here

So, Title is the text displayed on the button. Text is the text send back to the bot as a message. If Value is present in the CardAction, it gets sent as the activity's value.

The Bug

I see that you submitted this question to GitHub, as well. I'll just duplicate the response here.

The issue isn't so much that you can't have a null Choice.Value so much as when extracting Choices from the CardAction and trying to determine the max length of the text to display for the Choice, ChoiceFactory was incorrectly looking at Choice.Value while it's null instead of looking at Choice.Action.Title. See PR for the fix, there.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • My question is based on many false assumptions. Probably because the framework is partly documented and written strangely. (My opinion) – baruchiro Mar 18 '19 at 19:29
  • No problem. This is getting off-topic a little, but if you want to use cards in ChoicePrompts, you might want to read [one of my other SO answers](https://stackoverflow.com/a/55066910/10860086) – mdrichardson Mar 18 '19 at 19:52
  • I forgot something. Can you explain the difference between `Text` and `Title`? – baruchiro Mar 19 '19 at 11:34
  • 1
    I've updated my answer with an explanation. See "Title vs. Text" – mdrichardson Mar 19 '19 at 16:11
  • "ChoicePrompt expects a messageBack ActivityType", actually didn't work for me, but with `postBack` works – baruchiro Mar 19 '19 at 18:19
  • Good catch. It should actually be `imBack`. Be aware that `postBack` is not supposed to show in the chat window, so this may be undesired for some. I also had the wrong link in there for `ActionTypes` and have edited it. – mdrichardson Mar 19 '19 at 18:32
  • Yes, I saw the wrong link, but I could not find the right one :) – baruchiro Mar 19 '19 at 18:42