Пример #1
0
        public async void UpdateAsync(Message msg, TelegramBotClient bot, long chatId, Context db)
        {
            switch (msg.Type)
            {
            case MessageType.Text when msg.Text.Equals("/order", StringComparison.OrdinalIgnoreCase):
            {
                await bot.SendTextMessageAsync(
                    chatId : msg.Chat.Id,
                    text : "`Здравствуйте, откуда вас забрать? \n" +
                    "Для определения вашего местонахождения " +
                    "в настройках телефона включите` *геолокацию* \n" +
                    "и нажмите на кнопку Местоположение.",
                    replyMarkup : new ReplyKeyboardMarkup(new[]
                    {
                        KeyboardButton.WithRequestLocation("Местоположение"),
                        new KeyboardButton("Отмена"),
                    }, true, true),
                    parseMode : ParseMode.Markdown);

                var user = db.Users.FirstOrDefault(x => x.ChatId == msg.Chat.Id);
                if (user != null)
                {
                    user.State = StateChatEnum.StartText;
                }
                db.SaveChanges();
                break;
            }

            case MessageType.Text:
            {
                await bot.SendTextMessageAsync(
                    chatId : msg.Chat.Id,
                    text : "Для заказа такси введите команду \n /order");

                break;
            }
            }
        }
Пример #2
0
        public Fsm(long chatId, Message msg, TelegramBotClient bot, Context db)
        {
            User state;

            lock (Locker)
            {
                state = db.Users.FirstOrDefault(x => x.ChatId == chatId);
            }

            if (state == null)
            {
                User user = new User
                {
                    ChatId = chatId,
                    State  = StateChatEnum.StartMain
                };
                db.Users.Add(user);
                db.SaveChanges();
            }

            if (state != null)
            {
                IUpdateState updateState;

                switch (state.State)
                {
                case StateChatEnum.StartMain:
                    var uid = db.Users.FirstOrDefault(x => x.ChatId == chatId);
                    if (uid == null)
                    {
                        User user = new User
                        {
                            ChatId = chatId,
                            State  = StateChatEnum.StartText
                        };

                        db.Users.Add(user);
                        db.SaveChanges();
                    }

                    updateState = new StartMain();
                    break;

                case StateChatEnum.EndAddress:
                    updateState = new EndAddress();
                    break;

                case StateChatEnum.StartText:
                    updateState = new StartText();
                    break;

                case StateChatEnum.SendingTime:
                    updateState = new SendingTime();
                    break;

                case StateChatEnum.SendingNumberPhone:
                    updateState = new SendingNumberPhone();
                    break;

                case StateChatEnum.PaymentMethod:
                    updateState = new PaymentMethod();
                    break;

                case StateChatEnum.CarSearch:
                    updateState = new CarSearch();
                    break;

                //case StateChatEnum.CarSearch:
                //	updateState = new CarSearch();
                //	break;

                default:
                    throw new AggregateException();
                }

                updateState.UpdateAsync(msg, bot, chatId, db);
            }
        }