2017-01-05 3 views
0

リストの値を返してボットエミュレータで表示する必要があります。リストの値をボットダイアログに表示する方法は?

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; 
    } 

上記のリストには、チーム名のリストを返します。エミュレータではチームのリストを要求し、ボットはすべてのチーム名を返すことができるはずです。

DialogClass.cs:

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); 
    } 

は、どのように私は次の行に表示されたチーム名のリストを得ることができますか?

await context.PostAsync($"There are {champ.GetTeams()}");

答えて

1

私はあなたのための可能な応答のうちの2つを書くことができます

まず次のリンク文字列のリストを作成します。

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); 
}); 
関連する問題