Custom message for enum options in formflow - C# Bot Framework

允我心安 提交于 2019-12-11 05:10:51

问题


I am working with MS bot framework and I can't find way to custom message for enum options in form flow. I have tried with prompt attribute but it doesn't work.

What I want is: bot will show options for user like:

1) Yes, I want to be a DayNinja!

2) No, I don't want to unlock flow to achieve my goals.

3) Later, I'll start with the basics

Now, All I get are: "Yes", "No", "Later"

Any help will be appreciated Thank you!


回答1:


You are using the wrong attribute. Instead of using the Prompt attribute, you need to use the Describe one.

public enum OpeningHubOptions
{
    [Describe("Yes, I want to be a DayNinja")]
    Yes = 1,

    [Describe("No, I don't want to unlock flow to achieve my goals.")]
    No = 2,

    [Describe("Later, I''ll start with the basics")]
    Later = 3
}



回答2:


What Ezequiel posted did not work with me, because whenever you clicked on the menu item, the Describe value was posted instead. This resulted in the bot not being happy as the value was not part of the variable options.

I resolved this by replacing Describe with Display followed by including System.ComponentModel.DataAnnotations. More information:- How to set space on Enum.

For example:

using System.ComponentModel.DataAnnotations;    
public enum OpeningHubOptions
    {
        [Display(Name = "Yes, I want to be a DayNinja")]
        Yes = 1,

        [Display(Name = "No, I don't want to unlock flow to achieve my goals.")]
        No = 2,

        [Display(Name = "Later, I''ll start with the basics")]
        Later = 3
    }


来源:https://stackoverflow.com/questions/44756649/custom-message-for-enum-options-in-formflow-c-sharp-bot-framework

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