public void DeleteMessage(long chatId, int messageId) { ITelegramBotClient telegramBotClient = ModulesManager.GetTelegramBotClient(); ISessionManager sessionManager = ModulesManager.GetSessionManager(); sessionManager.GetChatSession(chatId).MessageDeleted(messageId); telegramBotClient.DeleteMessageAsync(chatId, messageId); }
public void ChangeChatState(long chatId, ChatSessionState newState) { ISessionManager sessionManager = ModulesManager.GetSessionManager(); IChatSession chatSession = sessionManager.GetChatSession(chatId); if (chatSession != null) { chatSession.State = newState; chatStateHandlerFactory.GetChatStateHandler(chatSession.State).StartStateMessage(chatId); } }
public async Task SendTextMessageAsync(long chatId, string messageText, IReplyMarkup replyMarkup) { if (string.IsNullOrEmpty(messageText)) { return; } ITelegramBotClient telegramBotClient = ModulesManager.GetTelegramBotClient(); ISessionManager sessionManager = ModulesManager.GetSessionManager(); Telegram.Bot.Types.Message message = await telegramBotClient.SendTextMessageAsync( chatId: chatId, text: messageText, replyMarkup: replyMarkup ); sessionManager.BotSentMessage(chatId, message.MessageId); }
public async Task SendPhotoMessageAsync(long chatId, byte[] imageBytes, IReplyMarkup replyMarkup) { if (imageBytes == null || imageBytes.Length == 0) { return; } ITelegramBotClient telegramBotClient = ModulesManager.GetTelegramBotClient(); ISessionManager sessionManager = ModulesManager.GetSessionManager(); using (Stream stream = new MemoryStream(imageBytes)) { Telegram.Bot.Types.Message message = await telegramBotClient.SendPhotoAsync( chatId, new InputOnlineFile(stream), replyMarkup: replyMarkup ); sessionManager.BotSentMessage(chatId, message.MessageId); } }
public void HandleUserMessage(ITelegramUserMessage message) { if (message.IsEmpty()) { return; } ISessionManager sessionManager = ModulesManager.GetSessionManager(); IChatSession chatSession = sessionManager.GetChatSession(message.ChatId); if (chatSession == null) { sessionManager.CreateChatSession(message.ChatId); chatSession = sessionManager.GetChatSession(message.ChatId); } sessionManager.UserSentMessage(message.ChatId, message.MessageId); chatStateHandlerFactory.GetChatStateHandler(chatSession.State).HandleUserMessage(message, this); }
private void ExitCommand(long chatId, IChatStateHandlerContext context) { ISessionManager sessionManager = ModulesManager.GetSessionManager(); sessionManager.KillChatSession(chatId); }