botframework - 如何将自定义有效负载添加到 PromptDialog.Choice
问题描述
我正在尝试将自定义数据负载添加到 PromptDialog.Choice / 或 PromptDialog.Text 以向我的机器人客户端指示特殊活动。
我知道有一个字段可以为 IMessageActivity 指定 InputHint。有没有办法将 inputhint/ 或自定义标签添加到 PromptDialog 流?
解决方案
你最好的选择是使用这样的东西:
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
属性,以便您可以捕获您的“特殊活动”代码。
推荐阅读
- javascript - Angular 8 中库的摇树
- angular - mat-selection-list 与复选框的替代品?
- java - 如何使用 Glide 在 Dialog 中显示图像?
- api - Websockets:数据设计模式
- javascript - 使用 CarouFredSel 的滑块
- gem5 - 多核 SE 模式下每个核的最大指令数
- rust - 在没有 CNN 的情况下调整参数以优化分数
- android - Android:如何衡量textview是否有足够的空间来渲染textview内容
- javascript - React Context API 和 withRouter
- unix - rsync在没有写权限的情况下覆盖文件