public override sealed void ProcessCommand(TelegramCommand command) { if (command.CommandType == TelegramCommandType.ButtonPressed) { var c = command as TelegramButtonPressedCommand; if (c.CallbackData == MainButtonCommand) { Done(CheckedOptions); return; } ActiveMessage = new TelegramTextMessageWithKeyboardEdited(LastMessageId, ActiveMessage, clearKeyboard: true); if (CheckedOptions.Contains(c.CallbackData)) { CheckedOptions.Remove(c.CallbackData); } else { CheckedOptions.Add(c.CallbackData); } foreach (var pair in ButtonList) { if (CheckedOptions.Contains(pair.Value)) { ActiveMessage.AddCallbackButton(GetCheckedString(pair.Key), pair.Value); } else { ActiveMessage.AddCallbackButton(GetUncheckedString(pair.Key), pair.Value); } } GenerateMainButtonCommand(); ActiveMessage.AddCallbackButton(MainButton, MainButtonCommand, true); PostMessage(ActiveMessage); } }
private void TimeToSend(object sender, ElapsedEventArgs e) { SendTimer.Stop(); if (Queue.Count > 0) { TelegramMessage message; message = Queue.First.Value; Queue.RemoveFirst(); if (LoggingEnabled) { try { Console.WriteLine(DateTime.UtcNow); Console.WriteLine(message.ToString()); } catch (Exception err) { BotUtils.LogException(err); } } switch (message.MessageType) { case TelegramMessageType.Empty: break; case TelegramMessageType.Text: { TelegramTextMessage msg = message as TelegramTextMessage; int result; try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, msg.ParseMode, disableWebPagePreview: msg.DisableWebPagePreview).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, ParseMode.Markdown).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception internalError) { BotUtils.LogException(internalError); } } } break; case TelegramMessageType.TextWithKeyboard: { TelegramTextMessageWithKeyboard msg = message as TelegramTextMessageWithKeyboard; int result; try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, msg.ParseMode, replyMarkup: msg.ReplyMarkup, disableWebPagePreview: msg.DisableWebPagePreview).Result.MessageId; msg.SetMessageId(result); bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, ParseMode.Markdown, replyMarkup: msg.ReplyMarkup, disableWebPagePreview: msg.DisableWebPagePreview).Result.MessageId; msg.SetMessageId(result); bot.SetLastMessageId(msg.ChatId, result); } catch (Exception internalError) { BotUtils.LogException(internalError); } } } break; case TelegramMessageType.TextWithKeyboardHide: { TelegramTextMessageWithKeyboardHide msg = message as TelegramTextMessageWithKeyboardHide; int result; try { result = bot.EditMessageReplyMarkupAsync(msg.ChatId, msg.OriginalMessageId).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); } } break; case TelegramMessageType.TextWithLink: { TelegramTextMessageWithLink msg = message as TelegramTextMessageWithLink; int result; try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, msg.ParseMode, replyMarkup: msg.ReplyMarkup).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); try { result = bot.SendTextMessageAsync(msg.ChatId, msg.Text, ParseMode.Markdown, replyMarkup: msg.ReplyMarkup).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception internalError) { BotUtils.LogException(internalError); } } } break; case TelegramMessageType.Payment: { TelegramPaymentMessage msg = message as TelegramPaymentMessage; if (!string.IsNullOrEmpty(bot.PaymentsKey)) { try { int result = bot.SendInvoiceAsync(msg.ChatId, msg.Title, msg.Description, msg.InvoiceId, bot.PaymentsKey, "RUB", msg.Prices).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); } } } break; case TelegramMessageType.Typing: { try { bot.SendChatActionAsync(message.ChatId, ChatAction.Typing); } catch (Exception error) { BotUtils.LogException(error); } } break; case TelegramMessageType.File: { TelegramFileMessage msg = message as TelegramFileMessage; try { int result = bot.SendDocumentAsync(message.ChatId, new InputOnlineFile(new MemoryStream(msg.Data), msg.FileName), msg.Caption).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); } } break; case TelegramMessageType.Picture: { TelegramPictureMessage msg = message as TelegramPictureMessage; try { int result = bot.SendPhotoAsync(message.ChatId, new InputOnlineFile(new MemoryStream(msg.Data)), msg.Caption).Result.MessageId; bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); } } break; case TelegramMessageType.TextWithKeyboardEdited: { TelegramTextMessageWithKeyboardEdited msg = message as TelegramTextMessageWithKeyboardEdited; try { int result = bot.EditMessageTextAsync(msg.ChatId, msg.OriginalMessageId, msg.Text, msg.ParseMode, disableWebPagePreview: msg.DisableWebPagePreview, replyMarkup: msg.Keyboard).Result.MessageId; msg.SetMessageId(result); bot.SetLastMessageId(msg.ChatId, result); } catch (Exception error) { BotUtils.LogException(error); } } break; } } SendTimer.Start(); }