C# 如何在bot对话框中获取列表值?
我需要返回列表值并在bot emulator中显示它们C# 如何在bot对话框中获取列表值?,c#,botframework,C#,Botframework,我需要返回列表值并在bot emulator中显示它们 private static Dictionary<string, int> Teams; 私有静态字典团队; 上面的列表中添加了所有团队名称列表 代码: public int GetTeamCount() { return Teams.Count; } public List<string> GetTeams() { var sorted = Tea
private static Dictionary<string, int> Teams;
私有静态字典团队;
上面的列表中添加了所有团队名称列表
代码:
public int GetTeamCount()
{
return Teams.Count;
}
public List<string> GetTeams()
{
var sorted = Teams.OrderBy(p => p.Value);
List<string> orderedTeams = new List<string>();
foreach (var e in sorted)
{
orderedTeams.Add(e.Key);
}
return orderedTeams;
}
private async Task ActivityReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
Championships champ = new Championships();
if (activity.Text.Contains("how many teams"))
{
await context.PostAsync($"There are {champ.GetTeamCount()} teams.");
}
else if (activity.Text.Contains("list of team names"))
{
await context.PostAsync($"There are {champ.GetTeams()}");
}
else
{
await context.PostAsync("My responses are limited. Please ask the right questions. ");
}
context.Wait(ActivityReceivedAsync);
}
public int GetTeamCount()
{
返回队伍。计数;
}
公共列表GetTeams()
{
var sorted=Teams.OrderBy(p=>p.Value);
List orderedTeams=新列表();
foreach(排序中的变量e)
{
orderedTeams.Add(e.Key);
}
退货订单团队;
}
上面的列表将返回团队名称列表。在emulator中,当他们请求团队列表时,bot应该能够返回所有团队名称
DialogClass.cs:
public int GetTeamCount()
{
return Teams.Count;
}
public List<string> GetTeams()
{
var sorted = Teams.OrderBy(p => p.Value);
List<string> orderedTeams = new List<string>();
foreach (var e in sorted)
{
orderedTeams.Add(e.Key);
}
return orderedTeams;
}
private async Task ActivityReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
Championships champ = new Championships();
if (activity.Text.Contains("how many teams"))
{
await context.PostAsync($"There are {champ.GetTeamCount()} teams.");
}
else if (activity.Text.Contains("list of team names"))
{
await context.PostAsync($"There are {champ.GetTeams()}");
}
else
{
await context.PostAsync("My responses are limited. Please ask the right questions. ");
}
context.Wait(ActivityReceivedAsync);
}
private async Task ActivityReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
var活动=等待作为活动的结果;
冠军=新冠军();
if(activity.Text.Contains(“多少个团队”))
{
wait context.PostAsync($“有{champ.GetTeamCount()}个团队。”);
}
else if(activity.Text.Contains(“团队名称列表”))
{
wait context.PostAsync($“有{champ.GetTeams()}”);
}
其他的
{
等待上下文。PostAsync(“我的回答有限。请提出正确的问题”);
}
Wait(ActivityReceivedAsync);
}
如何获得显示在下一行中的团队名称列表
wait context.PostAsync($“有{champ.GetTeams()}”)代码>我可以为您写两个可能的回复:
第一:创建字符串链接列表,链接如下:
var teamNames = "";
champ.GetTeams().Foreach(x => teamNames += x + ",");
teamNames.TrimEnd(',');
await context.PostAsync($"There are {teamNames}");
第二:为每个团队名称发送消息:
await context.PostAsync("There are:");
champ.GetTeams().Foreach(aync(x) => {
await context.PostAsync(x);
});