首页 > 解决方案 > 如何将自定义有效负载添加到 PromptDialog.Choice

问题描述

我正在尝试将自定义数据负载添加到 PromptDialog.Choice / 或 PromptDialog.Text 以向我的机器人客户端指示特殊活动。

我知道有一个字段可以为 IMessageActivity 指定 InputHint。有没有办法将 inputhint/ 或自定义标签添加到 PromptDialog 流?

标签: botframework

解决方案


你最好的选择是使用这样的东西:

var options = new PromptOptions()
{
    Prompt = MessageFactory.Text("Pick Me!"),
    Choices = new List<Choice>()
};
var channelData = new Dictionary<string, string>();
channelData["testKey"] = "testValue";
options.Choices.Add(new Choice()
{
    // Value must be set. There's a PR in place to fix this, but for now just leave blank
    Value = "",
    Action = new CardAction()
    {
        // PostBack will prevent the user from seeing "Actual Value" after they select it
        Type = ActionTypes.PostBack,
        Title = "DISPLAYED TEXT",
        Value = "ACTUAL VALUE",
    }
});
return await stepContext.PromptAsync(nameof(ChoicePrompt), options);

我在代码中留下的注释应该足够解释了。

另一种解决方案可能是显示一组包含 的卡片ChannelData,然后显示一个空白文本提示以等待用户的响应。对于如何做到这一点,我有一个非常深入的答案。您只需要添加一个ChannelData属性,以便您可以捕获您的“特殊活动”代码。


推荐阅读