我已经以这种方式在BOT框架中实现了代码,当我单击某个特定选项时,我想查看说明而不是id。该怎么做?
PromptDialog.Choice(
context: context,
resume: getSpeciaLities,
options: customerdata.Select(p => p.Id).ToArray(),
prompt: "Hi. Please Select client name",
retry: "Selected plan not avilabel . Please try again.",
promptStyle: PromptStyle.Auto,
descriptions: customerdata.Select(p => p.ClientName).ToArray()
);
谢谢 Utpal Maity
答案 0 :(得分:1)
当我单击特定选项时,我想查看说明而不是ID
如果您希望在用户单击特定选项时在聊天窗口中显示ClientName
而不是Id
,则可以直接将customerdata
的所有ClientName提供为 PromptDialog.Choice 的选项。
如果您要基于所选选项Id
进行其他操作/业务逻辑,则可以根据所选的特定ClientName从customerdata
进行检索。
var customerdata = GetCustomerdata();
PromptDialog.Choice(
context: context,
resume: ChoiceReceivedAsync,
options: customerdata.Select(p => p.ClientName).ToArray(),
prompt: "Hi. Please Select Client Nanme:",
retry: "Selected plan not avilabel . Please try again.",
promptStyle: PromptStyle.Auto,
descriptions: customerdata.Select(p => p.ClientName).ToArray()
);
在ChoiceReceivedAsync方法中:
private async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<string> result)
{
string response = await result;
var customerdata = GetCustomerdata();
//retrieve the id of selected option
var id = customerdata.Where(p => p.ClientName == response).Select(r => r.Id).FirstOrDefault();
//your business logic here
await context.PostAsync($"Id is {id} and ClientName is {response}");
}
测试结果: