public void AlertSubscriber(long chatId, string text)
 {
     if (chatId != 0)
     {
         _LogHelper.Log("FDS7DSF8DS7F", $"Subscriber {chatId} is notified of |{text}|", chatId, LogLevel.Information, false);
         //_menuLoader.SendNotification(chatId, text);//.SendText(chatId, text);
         _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Send, text));
     }
 }
        public async Task UpdateHandle(Update update)
        {
            if (update.Type == UpdateType.Message || update.Type == UpdateType.CallbackQuery)
            {
                var chatId = _updateHelper.GetChatId(update);

                if (!_users.UserInfo.ContainsKey(chatId))
                {
                    _users.UserInfo.Add(chatId, new UserInfo()
                    {
                        UserName = _updateHelper.GetUserName(update)
                    });
                    _logHelper.Log("L5NB54645KJJKEW2", $"MENU LOADER TYPE: {_menuLoader.MenuLoaderType}", LogLevel.Information);

                    if (_menuLoader.MenuLoaderType == "SimpleButtonMenuLoader")
                    {
                        await _menuLoader.LoadStateMenu(chatId, UserState.InSimpleMainMenu);
                    }
                    else
                    {
                        await _menuLoader.LoadStateMenu(chatId, UserState.InMainMenu);
                    }
                }
                else
                {
                    if (_menuLoader.MenuLoaderType == "SimpleButtonMenuLoader")
                    {
                        if (update.Type == UpdateType.Message)
                        {
                            _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Remove, update.Message.MessageId.ToString()));
                            try
                            {
                                _room.DequeueId(chatId);
                            }
                            catch (Exception)
                            {
                            }
                            await _menuLoader.LoadStateMenu(chatId, UserState.InSimpleMainMenu);
                        }
                        else
                        {
                            _sessionRouter.RouteUpdate(update);
                        }
                    }
                    else
                    {
                        _sessionRouter.RouteUpdate(update);
                    }
                }
            }
            else
            {
                return;
            }
        }
Exemple #3
0
        private void VisitDurationCustomMenuHandler(Update update)
        {
            long chatId = _updateHelper.GetChatId(update);

            if (update.Message.Text == "/exit")
            {
                _menuLoader.LoadStateMenu(chatId, UserState.InMainMenu);
                return;
            }

            int timeMinutes;

            int.TryParse(update.Message.Text, out timeMinutes);
            if (timeMinutes != 0 && timeMinutes < _config.Value.TimeLimitMinutes)
            {
                //_menuLoader.RemoveNotification(chatId);
                _menuLoader.LoadStateMenu(chatId, UserState.InQueue);
                _room.Enqueue(chatId, timeMinutes);
            }
            else
            {
                if (timeMinutes == 0)
                {
                    //_menuLoader.SendText(chatId, NumberNotParsed);
                    try
                    {
                        _logHelper.Log("JL54H6K45K645", $"NumberNotParsed is being sent to {chatId}", chatId, LogLevel.Warning);
                        //_menuLoader.SendNotification(chatId, NumberNotParsed);
                        _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Send, NumberNotParsed));
                    }
                    catch (Exception ex)
                    {
                        _logHelper.Log("fdsf87ds6f87ds", $"NumberNotParsed notifcation failed. ChatId = {chatId}.\r\nException: {ex.Message}", chatId, LogLevel.Error);
                    }
                }
                else
                {
                    //_menuLoader.SendText(chatId, NumberOverLimit);
                    try
                    {
                        _logHelper.Log("HJGHGHJKFDS778", $"NumberOverLimit is being sent to {chatId}", chatId, LogLevel.Warning);
                        //_menuLoader.SendNotification(chatId, NumberOverLimit);
                        _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Send, NumberOverLimit));
                    }
                    catch (Exception ex)
                    {
                        _logHelper.Log("dsfds2f3k4j432hj", $"NumberOverLimit notification failed. Chatid = {chatId}\r\nException: {ex.Message}", chatId, LogLevel.Error);
                    }
                }
                _menuLoader.LoadStateMenu(chatId, UserState.InVisitDurationCustom);
            }
        }
Exemple #4
0
        private void IncorrectCommandHandler(Update update, UserState userState)
        {
            long chatId = _updateHelper.GetChatId(update);

            //_menuLoader.SendText(chatId, CommandNotRecognized);
            try
            {
                _logHelper.Log("df798sfs98", $"CommandNotRecognized notification sent to {chatId}", chatId, LogLevel.Warning);
                //_menuLoader.SendNotification(chatId, CommandNotRecognized);
                _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Send, CommandNotRecognized));
            }
            catch (Exception ex)
            {
                _logHelper.Log("fdsd3234fds4s", $"Failed to send CommandNotRecognized notification to {chatId}", chatId, LogLevel.Error);
            }

            _logHelper.Log("F98DSJ98HJ9HJG", $"Command was not recognized. User state: {userState.ToString()} User input:|{GetCommand(update)}|", LogLevel.Warning);
        }
        public async Task LoadStateMenu(long chatId, UserState userState, bool removeNotification = true, [CallerMemberName] string caller = null)
        {
            _logHelper.Log("NJ543JKL4J", $"Menu is loaded by : {caller} | Userstate : {userState.ToString()} | chatId : {chatId} | RemoveNotification : {removeNotification.ToString()}", LogLevel.Information);
            _users.UserInfo[chatId].State = userState;



            string menuText = "";
            List <InlineKeyboardButton> buttons = new List <InlineKeyboardButton>();

            if (removeNotification)
            {
                _notificationRouter.RouteNotification(new NotificationItem(chatId, NotificationType.Remove));
            }
            switch (userState)
            {
            case UserState.InMainMenu:

                menuText = LoadMainMenuText();
                buttons  = LoadMainMenuButtons();
                break;

            case UserState.InStatusFree:
                menuText = LoadStatusFreeMenuText();
                buttons  = LoadStatusFreeMenuButtons();
                break;

            case UserState.InStatusOccupied:
                menuText = LoadStatusOccupiedMenuText();
                buttons  = LoadStatusOccupiedMenuButtons();
                break;

            case UserState.InVisitDuration:
                menuText = LoadVisitDurationMenuText();
                buttons  = LoadVisitDurationMenuButtons();
                break;

            case UserState.InVisitDurationCustom:
                menuText = LoadVisitDurationCustomMenuText();
                buttons  = LoadVisitDurationCustomMenuButtons();
                break;

            case UserState.InQueue:
                menuText = LoadQueueMenuText();
                buttons  = LoadQueueMenuButtons();
                break;

            case UserState.InTheRoom:

                menuText = LoadRoomMenuText();
                buttons  = LoadRoomMenuButtons();
                break;

            case UserState.InAddMoreTimeInTheRoom:
                menuText = LoadAddMoreTimeInTheRoomMenuText();
                buttons  = LoadAddMoreTimeInTheRoomMenuButtons();
                break;

            case UserState.InAddMoreTimeInTheQueue:
                menuText = LoadAddMoreTimeInTheQueueMenuText();
                buttons  = LoadAddMoreTimeInTheQueueMenuButtons();
                break;

            case UserState.InBetweenQueueAndRoom:
                menuText = LoadInBetweenQueueAndRoomMenuText();
                buttons  = LoadInBetweenQueueAndRoomMenuButtons();
                break;

            case UserState.InDoorIsLocked:
                menuText = LoadDoorIsLockedMenuText();
                buttons  = LoadDoorIsLockedMenuButtons();
                break;

            default:
                menuText = $"Command not implemented yet. userState = {userState.ToString()}";
                break;
            }

            var markup = GetMarkup(buttons);

            await SendMenu(chatId, menuText, markup);
        }