public override void ProcessCommand(TelegramCommand command) { if (command.CommandType == TelegramCommandType.ButtonPressed) { if ((command as TelegramButtonPressedCommand).CallbackData == Callback) { if (ActiveMessage.MessageId > 0) { Increment++; ActiveMessage = new TelegramTextMessageWithKeyboardEdited(ActiveMessage.MessageId, ActiveMessage, string.Format(MessageTemplate, Increment)); PostMessage(ActiveMessage); } } } else if (command.CommandType == TelegramCommandType.Geo) { PostMessage(ActiveMessage.GetMessageToHide()); double Latitude = (command as TelegramGeoCommand).Latitude; double Longitude = (command as TelegramGeoCommand).Longitude; TelegramTextMessage m = new TelegramTextMessage(UserId, string.Format("{0} {1}", Latitude, Longitude)); PostMessage(m); } else { Machine.Bot.terminate = true; } }
public TelegramTextMessageWithKeyboardEdited(int originalMessageId, TelegramTextMessageWithKeyboard originalMessage, bool disableWebPagePreview = false, bool clearKeyboard = false) : base(originalMessage.ChatId, originalMessage.Text, originalMessage.ParseMode, disableWebPagePreview) { OriginalMessageId = originalMessageId; if (!clearKeyboard) { Keyboard = originalMessage.Keyboard; } SetText(originalMessage.Text); }
public override void Init() { Type(); ActiveMessage = new TelegramTextMessageWithKeyboard(UserId, Message, MessageParseMode, DisableWebPreview); foreach (var pair in ButtonList) { ActiveMessage.AddCallbackButton(pair.Key, pair.Value); } PostMessage(ActiveMessage); }
public override void Init() { Type(); ActiveMessage = new TelegramTextMessageWithKeyboard(UserId, Message, MessageParseMode, DisableWebPreview); foreach (var pair in ButtonList) { ActiveMessage.AddCallbackButton(GetUncheckedString(pair.Key), pair.Value); } ActiveMessage.AddCallbackButton(MainButton, MainButtonCommand, true); PostMessage(ActiveMessage); }
public override void Init() { ActiveMessage = new TelegramTextMessageWithKeyboard(UserId, string.Format(MessageTemplate, Increment)); ActiveMessage.AddCallbackButton("Button", Callback); 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(); }