我想使用 Microsoft Bot Framework (C#) 构建简单的 Telegram bot 我现在要做的是创建一个列表,该列表可由群聊中的每个人填写。我想要的结果:
user a: /add hello
user b: /add world
user a: /show
bot: hello world
user b: /show
bot: hello world
但我现在拥有的是:
user a: /add hello
user b: /add world
user a: /show
bot: hello
user b: /show
bot: world
[Serializable]
public class RootDialog : IDialog<object>
{
private List<string> list = new List<string>();
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
switch (Parser.GetCommand(activity))
{
case "/add":
AddNewThingToList(activity);
break;
case "/show":
ShowList(context);
break;
}
context.Wait(MessageReceivedAsync);
}
private void AddNewThingToList(Activity activity)
{
list.Add(Parser.GetAfterCommandText(activity));
}
private void ShowList(IDialogContext context)
{
var response = new StringBuilder();
for (var i = 0; i < list.Count; i++)
{
response.Append($"{i}. {list[i]}{Environment.NewLine}");
}
context.PostAsync(response.ToString());
}
}
创建公共列表的最简单方法是什么?
相关分类