public override async Task Execute(Message message, TelegramBotClient client) { try { var chatId = message.Chat.Id; var messageId = message.MessageId; int step = 0; using (BOTdbEntities db = new BOTdbEntities()) { var chat = db.Chats.Find(chatId); if (chat != null) { step = chat.AlgorithmStep; await client.SendTextMessageAsync(chatId : chatId, text : chat.ChatId.ToString()); } else { db.Chats.Add(new Chats { ChatId = chatId }); db.SaveChanges(); } } var startMenu = new InlineKeyboardMarkup( new[] { new[] { new InlineKeyboardButton { Text = "DSR", CallbackData = "dsr" } }, new[] { new InlineKeyboardButton { Text = "Кореляція", CallbackData = "correlation" } }, new[] { new InlineKeyboardButton { Text = "Регресія", CallbackData = "regression" } }, new[] { new InlineKeyboardButton { Text = "Instagram автора", Url = "https://www.instagram.com/lvasuk/" } } }); await client.SendTextMessageAsync( chatId : chatId, text : "Розв'язати", parseMode : Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup : startMenu ); } catch (Exception ex) { Exception exc = ex; string s = new System.Text.StringBuilder().AppendLine(ex.Message).AppendLine(exc.Source).AppendLine(exc.StackTrace).ToString(); await client.SendTextMessageAsync(chatId : message.Chat.Id, text : s); } }
public async Task <OkResult> Post([FromBody] Update update) { if (update == null) { return(Ok()); } var botClient = await Bot.GetBotClientAsync(); var commands = Bot.Commands; var message = update.Message; if (message != null && message?.Text != null) { long chatId = message.Chat.Id; int step = 0; try { string text = message.Text; if (text[0] == '/') { await Bot.Commands[text].Execute(message, botClient); } else { using (BOTdbEntities db = new BOTdbEntities()) { var chat = db.Chats.Find(chatId); if (chat != null) { step = chat.AlgorithmStep; } else { db.Chats.Add(new Chats { ChatId = chatId }); } } } } catch (KeyNotFoundException) { await botClient.SendTextMessageAsync(chatId : message.Chat.Id, text : "Command not found", replyToMessageId : message.MessageId); } } var callback = update.CallbackQuery; if (callback != null) { var chatId = callback.Message.Chat.Id; try { await Bot.Strategics[callback.Data].Action(callback, botClient); } catch (KeyNotFoundException) { await botClient.AnswerCallbackQueryAsync(callbackQueryId : callback.Id, text : "Error: callback don`t handled;", showAlert : true); } } return(Ok()); }