Exemplo n.º 1
0
        public MessageEventResult ProcessMessage(MessageEvent messageEvent)
        {
            IStateFactory stateFactory = StateFactory;

            if (!_stateStorage.TryGetValue(messageEvent.Id, out IState currentState))
            {
                currentState = stateFactory.GetInitialState();
                SetState(messageEvent.Id, currentState);
            }
            MessageEventResult result;

            try
            {
                result = currentState.HandleEvent(messageEvent);
                if (!FinalStateReached(messageEvent.Id))
                {
                    IState nextState = stateFactory.GetNextState(currentState);
                    SetState(messageEvent.Id, nextState);
                }
                else
                {
                    SetState(messageEvent.Id, stateFactory.GetInitialState());
                }
            }
            catch (PreviousStateUserAnswerException prevStateAnswerEx)
            {
                result = new MessageEventResult(prevStateAnswerEx.Message);
            }
            return(result);
        }
Exemplo n.º 2
0
 public async Task HandleCallbackQuery(CallbackQuery callbackQuery)
 {
     string             chatId = callbackQuery.Message.Chat.Id.ToString();
     MessageEventResult result = _stateMachine.ProcessMessage(new MessageEvent {
         Id = chatId, Message = callbackQuery.Data
     });
     await _botClient.SendTextMessageAsync(
         chatId,
         result.Text,
         parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown,
         replyMarkup : result.ReplyMarkup
         );
 }