Ejemplo n.º 1
0
 /// <summary>
 /// Sends an animated emoji with auto retry to work around Telegram API's rate limit.
 /// </summary>
 /// <inheritdoc cref="TelegramBotClientExtensions.SendDiceAsync(ITelegramBotClient, ChatId, Emoji?, bool?, bool?, int?, bool?, IReplyMarkup?, CancellationToken)"/>
 public static async Task <Message> SendDiceWithRetryAsync(
     this ITelegramBotClient botClient,
     ChatId chatId,
     Emoji?emoji = null,
     bool?disableNotification            = null,
     bool?protectContent                 = null,
     int?replyToMessageId                = null,
     bool?allowSendingWithoutReply       = null,
     IReplyMarkup?replyMarkup            = null,
     CancellationToken cancellationToken = default)
 {
     while (true)
     {
         try
         {
             return(await botClient.SendDiceAsync(chatId,
                                                  emoji,
                                                  disableNotification,
                                                  protectContent,
                                                  replyToMessageId,
                                                  allowSendingWithoutReply,
                                                  replyMarkup,
                                                  cancellationToken));
         }
         catch (ApiRequestException ex) when(ex.ErrorCode == 429)
         {
             await Task.Delay(GetRetryWaitTimeMs(ex), cancellationToken);
         }
     }
 }
Ejemplo n.º 2
0
 public Task <Message> SendDiceAsync(long chatId)
 {
     return(_botClient.SendDiceAsync(chatId));
 }