Ejemplo n.º 1
0
 public void PrerenderDefaultOutput(
     long chatId,
     TelegramBotClientFacade telegramBotClientFacade)
 {
     telegramBotClientFacade
     .SendTextMessageToChat(chatId, GetRooms());
 }
Ejemplo n.º 2
0
 public void PublishEvent(TelegramBotClientFacade telegramBotClientFacade)
 {
     foreach (var item in _subscribers)
     {
         item.Update(telegramBotClientFacade);
     }
 }
Ejemplo n.º 3
0
 public void ProcessInput(long chatId,
                          string input,
                          TelegramBotClientFacade telegramBotClientFacade)
 {
     _currentState
     .ProcessInput(chatId, input, telegramBotClientFacade, this);
 }
Ejemplo n.º 4
0
        public override void ProcessRequest(
            TelegramBotClientFacade client,
            MessageEventArgs args)
        {
            var chatId = args.Message.Chat.Id;
            var state  = _stateRepository.Get(chatId);

            state.ProcessInput(chatId, args.Message.Text, client);
        }
Ejemplo n.º 5
0
        public override void Update(TelegramBotClientFacade facade)
        {
            var message =
                "Уважаемый клиент! Рады сообщить, что в нашем медцентре" +
                " начинается неделя скидок - приведи друга и " +
                "забери его почку бесплатно!";

            facade.SendTextMessageToChat(ChatId, message);
        }
Ejemplo n.º 6
0
        public void PrerenderDefaultOutput(long chatId,
                                           TelegramBotClientFacade telegramBotClientFacade)
        {
            var instance = SpecialDiscountEventPublisher.Instance;

            instance.AddSubscriber(new SpecialDiscountEventSubscriber(chatId));

            telegramBotClientFacade.SendTextMessageToChat(chatId,
                                                          "Вы успешно подписались на новости нашего медцентра!");
        }
Ejemplo n.º 7
0
        public void ProcessInput(
            long chatId,
            string input,
            TelegramBotClientFacade telegramBotClientFacade,
            CurrentStateHolder stateHolder)
        {
            var nextState = new OnStartSelectState();

            nextState.ProcessInput(chatId, input, telegramBotClientFacade, stateHolder);

            stateHolder.SetNextState(nextState);
        }
Ejemplo n.º 8
0
        public void ProcessInput(
            long chatId,
            string input,
            TelegramBotClientFacade telegramBotClientFacade,
            CurrentStateHolder stateHolder)
        {
            telegramBotClientFacade.SendMapMessageToChat(chatId);

            var initialState = new OnStartSelectState();

            initialState.PrerenderDefaultOutput(chatId, telegramBotClientFacade);
            stateHolder.SetNextState(initialState);
        }
Ejemplo n.º 9
0
        public ProcessingMiddleware(
            TelegramBotClientFacade client,
            IEnumerable <MiddlewareComponentBase> middlewareComponents)
        {
            _client = client ??
                      throw new ArgumentNullException(nameof(client));

            _middlewareComponents = middlewareComponents ??
                                    throw new ArgumentNullException(nameof(middlewareComponents));

            _logger = new LoggerConfiguration()
                      .WriteTo.Console()
                      .CreateLogger();
        }
Ejemplo n.º 10
0
        public void ProcessInput(long chatId,
                                 string input,
                                 TelegramBotClientFacade telegramBotClientFacade,
                                 CurrentStateHolder stateHolder)
        {
            var doctorName = input;
            var schedule   = GetSchedule(doctorName);

            telegramBotClientFacade.SendTextMessageToChat(chatId, schedule);

            var nextState = new OnStartSelectState();

            nextState.PrerenderDefaultOutput(chatId, telegramBotClientFacade);
            stateHolder.SetNextState(nextState);
        }
Ejemplo n.º 11
0
        public override void ProcessRequest(
            TelegramBotClientFacade client,
            MessageEventArgs messageEventArgs)
        {
            var logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            var chatId   = messageEventArgs.Message.Chat.Id;
            var userName = messageEventArgs.Message.Chat.Username;

            var lotItem = $"Поступило сообщение от пользователя {userName} в чате {chatId}";

            logger.Information(lotItem);
        }
Ejemplo n.º 12
0
        public override void ProcessRequest(
            TelegramBotClientFacade client,
            MessageEventArgs args)
        {
            var key = GetCurrentKey(args.Message.Chat.Id, DateTime.Now);

            _rateLimiterRepository.Increase(key);

            var currentCounter = _rateLimiterRepository.Get(key);

            if (currentCounter > _messageLimitPerMinute)
            {
                throw new InvalidOperationException("You have reached the limit of messages. Wait...");
            }

            RefreshOldRecords();
        }
Ejemplo n.º 13
0
        public void RunWorker(TelegramBotClientFacade telegramBotClientFacade)
        {
            _workerThread = Task.Run(() =>
            {
                while (true)
                {
                    var eventsToRun = GetEventsToPublishNow();

                    foreach (var item in eventsToRun)
                    {
                        Console.WriteLine($"READY TO PUBLISH : {item.GetType().Name}");
                        item.PublishEvent(telegramBotClientFacade);
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            });
        }
Ejemplo n.º 14
0
        public void ProcessInput(
            long chatId,
            string input,
            TelegramBotClientFacade telegramBotClientFacade,
            CurrentStateHolder stateHolder)
        {
            var selectedButton = GetButtons()
                                 .FirstOrDefault(p => input
                                                 .Equals(p, StringComparison.InvariantCultureIgnoreCase));

            if (selectedButton == null)
            {
                telegramBotClientFacade
                .SendButtonMessageToChat(chatId, GetButtons());
            }
            else
            {
                var nextState = ButtonToNextStateMapper(selectedButton);
                nextState.PrerenderDefaultOutput(chatId, telegramBotClientFacade);
                stateHolder.SetNextState(nextState);
            }
        }
Ejemplo n.º 15
0
        public void ProcessInput(
            long chatId,
            string input,
            TelegramBotClientFacade telegramBotClientFacade,
            CurrentStateHolder stateHolder)
        {
            var selectedCity = GetCities()
                               .FirstOrDefault(p => p.Equals(input, StringComparison.InvariantCultureIgnoreCase));

            if (selectedCity == null)
            {
                telegramBotClientFacade
                .SendTextMessageToChat(chatId, "Пожалуйста, повторите попытку");

                telegramBotClientFacade
                .SendButtonMessageToChat(chatId, GetCities());
            }
            else
            {
                var nextState = GetSelectAddressState(selectedCity);
                nextState.PrerenderDefaultOutput(chatId, telegramBotClientFacade);
                stateHolder.SetNextState(nextState);
            }
        }
 public ProcessingMiddlewareBuilder AddTelegramClient(
     ITelegramBotClient telegramBotClient)
 {
     _client = new TelegramBotClientFacade(telegramBotClient);
     return(this);
 }
Ejemplo n.º 17
0
 public abstract void Update(TelegramBotClientFacade facade);
Ejemplo n.º 18
0
 public abstract void ProcessRequest(
     TelegramBotClientFacade client,
     MessageEventArgs message);
Ejemplo n.º 19
0
 public void PrerenderDefaultOutput(
     long chatId,
     TelegramBotClientFacade telegramBotClientFacade)
 {
     telegramBotClientFacade.SendButtonMessageToChat(chatId, GetAddressesByCity(_selectedCity));
 }
 public ProcessingMiddlewareBuilder AddTelegramClient(
     TelegramBotClientFacade telegramBotClientFacade)
 {
     _client = telegramBotClientFacade;
     return(this);
 }
Ejemplo n.º 21
0
 public void ProcessInput(long chatId,
                          string input,
                          TelegramBotClientFacade telegramBotClientFacade, CurrentStateHolder stateHolder)
 {
     stateHolder.SetNextState(new OnStartSelectState());
 }
Ejemplo n.º 22
0
 public void PrerenderDefaultOutput(
     long chatId,
     TelegramBotClientFacade telegramBotClientFacade)
 {
     telegramBotClientFacade.SendButtonMessageToChat(chatId, GetCities());
 }