public static async Task Run(object obj) { if (ChatId != 0 & MessageId != 0) { var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.exmo.com/v1/ticker/"); var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); var streamReader = new StreamReader(httpWebResponse.GetResponseStream()); var result = streamReader.ReadToEnd(); RootObject ans = JsonConvert.DeserializeObject <RootObject>(result); string text = "Buy: <b>" + ans.XRP_USD.buy_price + "</b>\n" + "Sell: <b>" + ans.XRP_USD.sell_price + "</b>\n\n" + "BTC: <b>" + ans.BTC_USD.buy_price.Substring(0, 4) + "</b>\n\n" + "<i>" + DateTime.UtcNow.AddHours(3).ToLongTimeString() + "</i>"; try { await Bot.EditMessageTextAsync(ChatId, MessageId, text, Telegram.Bot.Types.Enums.ParseMode.Html); } catch { Thread.Sleep(60000); } } Thread.Sleep(1000); }
public void EditMessagePreview(Int32 blockNumber, long ChatID, int ReplyMessageId = 0) { _bot.EditMessageTextAsync(ChatID, currentState.CurrentPreviewMessageId, currentState.messagBlocks[blockNumber], Telegram.Bot.Types.Enums.ParseMode.Markdown, false, GetPreviewKeyboard(currentState.MessagesInResult, messageBlockSize)); }
/// <summary> /// Получение сообщений и ответ на них /// </summary> public async Task BotWork() { var bot = new Telegram.Bot.TelegramBotClient(_key); await bot.SetWebhookAsync(""); int offset = 0; //инервал между ответами while (!_token.IsCancellationRequested) { var updates = await bot.GetUpdatesAsync(offset); Message message; string responseMessage; foreach (var update in updates) { try { switch (update.Type) { case UpdateType.UnkownUpdate: break; case UpdateType.EditedMessage: break; case UpdateType.MessageUpdate: message = update.Message; switch (message.Type) { case MessageType.TextMessage: responseMessage = _messageControl.MessageCommands(message); if (_isWaitAnswerForRememder.Any(x => x == message.Chat.Id) || _isWaitAnswerForWeather.Any(x => x == message.Chat.Id)) { await bot.SendTextMessageAsync(message.Chat.Id, responseMessage, false, false, 0, CreateInlineKeyboard()); } else { await bot.SendTextMessageAsync(message.Chat.Id, responseMessage, false, false, 0, await CreateKeyboard(message.Chat.Id)); } _logger.Info(message.Chat.FirstName + " " + message.Chat.Id + " - " + message.Text); break; case MessageType.VideoMessage: await bot.SendTextMessageAsync(message.Chat.Id, "Сейчас посмотрю."); break; case MessageType.StickerMessage: await bot.SendTextMessageAsync(message.Chat.Id, $"Очень смешно, {message.Chat.FirstName}."); break; case MessageType.LocationMessage: responseMessage = _messageControl.LocationCommands(message.Location.Latitude, message.Location.Longitude); await bot.SendTextMessageAsync(message.Chat.Id, responseMessage); break; default: await bot.SendTextMessageAsync(message.Chat.Id, "И что мне на это ответить?"); break; } break; case UpdateType.CallbackQueryUpdate: await bot.EditMessageTextAsync(update.CallbackQuery.From.Id, update.CallbackQuery.Message.MessageId, "Возврат обратно."); _isWaitAnswerForRememder.Remove(update.CallbackQuery.From.Id); _isWaitAnswerForWeather.Remove(update.CallbackQuery.From.Id); break; default: break; } offset = update.Id + 1; } catch (Exception ex) { _logger.Error(ex.Message); } } } }