Example #1
0
        public void DeleteMessage(long chatId, int messageId)
        {
            ITelegramBotClient telegramBotClient = ModulesManager.GetTelegramBotClient();
            ISessionManager    sessionManager    = ModulesManager.GetSessionManager();

            sessionManager.GetChatSession(chatId).MessageDeleted(messageId);
            telegramBotClient.DeleteMessageAsync(chatId, messageId);
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
        }
Example #6
0
        private void ExitCommand(long chatId, IChatStateHandlerContext context)
        {
            ISessionManager sessionManager = ModulesManager.GetSessionManager();

            sessionManager.KillChatSession(chatId);
        }