如何使用ListStyle.heroCard将自定义数据添加到ChoicePrompt
我有一个ChoicePrompt
,其样式为ListStyle.heroCard
,如下所示:
import {ChoicePrompt, ListStyle} from 'botbuilder-dialogs';
import {PromptValidator} from 'botbuilder-dialogs/src/prompts/prompt';
import {FoundChoice} from 'botbuilder-dialogs/src/choices/findChoices';
export class HeroCardChoicePrompt extends ChoicePrompt{
constructor(dialogId: string, validator?: PromptValidator<FoundChoice>, defaultLocale?: string){
super(dialogId, validator, defaultLocale)
this.style = ListStyle.heroCard
}
}
然后我添加了这个选择对象:
choices.push({
action: {
text: 'Lolipop',
displayText: 'Lolipop',
channelData: 'Lolipop',
type: 'postBack',
title: 'Lolipop',
value: 'Lolipop',
},
value: 'Can you please help me to manage...',
synonyms: []
},)
当用户单击选项时,如何在代码中获取数据'Lolipop'
?
[当我在漫游器模拟器中检查客户端接收到的JSON对象时,根本看不到数据'Lolipop'
。
使用ListStyle.heroCard
使提示符使用ChoiceFactory.heroCard
生成卡。您可以在source code中看到ChoiceFactory.heroCard
不在选择中使用动作,而是仅创建imBack
动作:
const buttons: CardAction[] = choices.map(choice => ({ title: choice.value, type: ActionTypes.ImBack, value: choice.value } as CardAction));
如果要在提示中提供自定义操作,则需要创建自己的英雄卡,并将其作为提示选项的prompt
字段提供,并使用ListStyle.none
。目前尚不清楚您为什么要这样做,因为ChoiceFactory
生成的操作将与选择提示中的可用选项匹配,因此不需要该活动具有隐藏值。