如何使用 sendtextmessageasync 方法?
How to use sendtextmessageasync method?
我想使用 sendtextmessageasync
方法,但我无法用适当的值填充第一个和最后一个重载。
private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
Telegram.Bot.Types.KeyboardButton button1 = new Telegram.Bot.Types.KeyboardButton("a");
Telegram.Bot.Types.KeyboardButton button2 = new Telegram.Bot.Types.KeyboardButton("b");
Telegram.Bot.Types.KeyboardButton button3 = new Telegram.Bot.Types.KeyboardButton("c");
Telegram.Bot.Types.KeyboardButton button4 = new Telegram.Bot.Types.KeyboardButton("d");
Telegram.Bot.Types.KeyboardButton[] row1 = { button1, button2 };
Telegram.Bot.Types.KeyboardButton[] row2 = { button3, button4 };
Telegram.Bot.Types.KeyboardButton[][] keyboard = { row1, row2 };
Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(keyboard);
bot.SendTextMessageAsync(e.Message.Chat.Id, "Hi", , false, false, 0, markup, );
Console.WriteLine("A new message has been recieved");
}
我认为这 github issue 应该会给你一个正确的开始。
var reply = "<b>Hello</b>\n"
+ "<a href=\"https://www.google.de\">This is a link</a>\n"
+ "<code>and a little bit code</code>";
await Bot.SendTextMessageAsync(message.Chat.Id, reply, parseMode: ParseMode.Html);
如果当前方法和所有调用方法都有 async 关键字,并且 return Task
或 Task<T>
其中 T 是正在 return 编辑类型。 var result = await SendTextMessageAsync()
否则,您可以使用 SendTextMessageAsync.ConfigureAwait(false).GetAwaiter().GetResult()
,但这并不理想,因为它可能会导致死锁,除非调用路径中的所有调用都使用 ConfigureAwait(false)
。此命令表示结果可以在任何线程上返回。
可以在此处找到更多信息:http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
我想使用 sendtextmessageasync
方法,但我无法用适当的值填充第一个和最后一个重载。
private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
Telegram.Bot.Types.KeyboardButton button1 = new Telegram.Bot.Types.KeyboardButton("a");
Telegram.Bot.Types.KeyboardButton button2 = new Telegram.Bot.Types.KeyboardButton("b");
Telegram.Bot.Types.KeyboardButton button3 = new Telegram.Bot.Types.KeyboardButton("c");
Telegram.Bot.Types.KeyboardButton button4 = new Telegram.Bot.Types.KeyboardButton("d");
Telegram.Bot.Types.KeyboardButton[] row1 = { button1, button2 };
Telegram.Bot.Types.KeyboardButton[] row2 = { button3, button4 };
Telegram.Bot.Types.KeyboardButton[][] keyboard = { row1, row2 };
Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(keyboard);
bot.SendTextMessageAsync(e.Message.Chat.Id, "Hi", , false, false, 0, markup, );
Console.WriteLine("A new message has been recieved");
}
我认为这 github issue 应该会给你一个正确的开始。
var reply = "<b>Hello</b>\n"
+ "<a href=\"https://www.google.de\">This is a link</a>\n"
+ "<code>and a little bit code</code>";
await Bot.SendTextMessageAsync(message.Chat.Id, reply, parseMode: ParseMode.Html);
如果当前方法和所有调用方法都有 async 关键字,并且 return Task
或 Task<T>
其中 T 是正在 return 编辑类型。 var result = await SendTextMessageAsync()
否则,您可以使用 SendTextMessageAsync.ConfigureAwait(false).GetAwaiter().GetResult()
,但这并不理想,因为它可能会导致死锁,除非调用路径中的所有调用都使用 ConfigureAwait(false)
。此命令表示结果可以在任何线程上返回。
可以在此处找到更多信息:http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html