public override async Task SendSimpleMessageAsync(string id, string text, KeyboardTypes keyboardType) { if (keyboardType == KeyboardTypes.None) { await client.SendTextMessageAsync(id, text); } else { var keyboard = TelegramKeyboardBuilder.GetKeyboard(keyboardType); await client.SendTextMessageAsync(id, text, replyMarkup : keyboard); } myStopwatch.Stop(); Console.Out.WriteLine("myStopwatch = {0}", myStopwatch.ElapsedMilliseconds);//остановить }
public override async Task SendMusicMessageAsync(string id, string text, MusicTrack track, KeyboardTypes keyboardType) { var musicVersion = track.MusicVersions.SingleOrDefault(t => t.Extension == "ogg"); if (musicVersion == null) { throw new ArgumentNullException($"MusicVersion of track {track.Id} is null"); } var keyboard = TelegramKeyboardBuilder.GetKeyboard(keyboardType); const int numberOfRetries = 3; const int delayOnRetry = 1000; for (var i = 0; i < numberOfRetries; i++) { try { var stream = new FileStream(musicVersion.TrackPath, FileMode.Open); var inputFile = new InputOnlineFile(stream); await client.SendVoiceAsync(id, inputFile, caption : text, replyMarkup : keyboard); stream.Close(); break; } catch { if (i <= numberOfRetries) { Console.Out.WriteLine("track is busy = {0}", track.Id); Task.Delay(delayOnRetry); } else { throw new Exception("Music file is invalid"); } } } myStopwatch.Stop(); Console.Out.WriteLine("myStopwatch = {0}", myStopwatch.ElapsedMilliseconds);//остановить }