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

折月煮酒 提交于 2019-12-14 04:02:34

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/55207624/bot-framework-why-choice-hold-cardaction-and-what-is-the-role-of-each

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!