예제 #1
0
        public override async Task DefaultAction(MessageEventArgs request)
        {
            var command = request.GetClearedTextMessage();
            var userId  = request.GetUserId();

            switch (command)
            {
            case GetCommands.Last: {
                var userService = GetUserService();
                var userData    = await userService.GetLast(userId);

                if (userData is null)
                {
                    context.Sender.Send("No data saved");
                }
                else
                {
                    context.Sender.Send(userData);
                }
                break;
            }

            case GetCommands.Keys: {
                break;
            }

            default:
                break;
            }
            await context.TransitionToAsync(typeof(MemberState), request.Message.From.Id);
        }
예제 #2
0
        public override async Task DefaultAction(MessageEventArgs request)
        {
            await Task.Yield();

            switch (request?.Message?.Type)
            {
            case Telegram.Bot.Types.Enums.MessageType.Text: {
                var isMessageNotEmpty = ValidateMessage(request.Message.Text);
                if (!isMessageNotEmpty)
                {
                    SendMessageIsEmpty();
                    break;
                }
                var userService = GetUserService();
                var key         = await userService.SaveUserData(request.GetUserId(), request.Message.Text);

                /// 3) delete source message
                /// 4) return key?
                break;
            }

            case Telegram.Bot.Types.Enums.MessageType.Unknown:
            case Telegram.Bot.Types.Enums.MessageType.Photo:
            case Telegram.Bot.Types.Enums.MessageType.Audio:
            case Telegram.Bot.Types.Enums.MessageType.Video:
            case Telegram.Bot.Types.Enums.MessageType.Voice:
            case Telegram.Bot.Types.Enums.MessageType.Document:
            case Telegram.Bot.Types.Enums.MessageType.Location:
            case Telegram.Bot.Types.Enums.MessageType.Contact:
                SendNotSupportetMessage();
                break;

            default:
                throw new Exception($"Unknown message type {request?.Message?.Type}");
            }
            context.Sender.Send("Save success");
            await context.TransitionToAsync(typeof(MemberState), request.GetUserId());
        }
예제 #3
0
        /// <summary>
        /// Try restore the previous state of the user
        /// If the state is not saved, create the state in accordance with the rules.
        /// </summary>
        public async Task <BotContext> CreateContext(MessageEventArgs request)
        {
            (State state, BotContext context)current;
            var userId          = request.GetUserId();
            var storedUserState = await userService.GetUserState(userId);

            if (storedUserState != null)
            {
                current = CreateStoredStateContext(request, userId, storedUserState);
            }
            else
            {
                current = await CreateMemberContext(request, userId);
            }

            if (current.IsNotInit())
            {
                current = CreateDefaultContext(request);
            }

            await current.context.MakeTransitionTo(current.state);

            return(current.context);
        }
예제 #4
0
        public override async Task No(MessageEventArgs request)
        {
            await context.TransitionToAsync(typeof(MemberState), request.GetUserId());

            await commands.Save(request);
        }
예제 #5
0
 public override async Task Yes(MessageEventArgs request)
 {
     context.Sender.Send("Send a message to save. A message sent after this will be saved.");
     await context.TransitionToAsync(typeof(SaveState), request.GetUserId());
 }