简体   繁体   中英

Bot Framework- Why Choice hold CardAction, and what is the role of each?

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?

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:

在此处输入图片说明

When clicked:

在此处输入图片说明

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 Choice s 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM