public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Product = Catalog.GetProductName(update.CallbackData.Split()[1]);
            NextStep     = new SpecifyAdressStep(ChatId, BotClient, Data);

            await EditMessageAsync(Message, update.CallbackMessageId);
        }
Exemplo n.º 2
0
        public async Task Execute(BotUpdate update, IBotClient client)
        {
            if (CallbackActions.Count > 0)
            {
                Func <BotUpdate, IBotClient, Task> action = null;

                var callbackWords = update.CallbackData != null?update.CallbackData.Split() : null;

                if (callbackWords != null && callbackWords[0] == CommandName)
                {
                    action = CallbackActions.SingleOrDefault(a => !string.IsNullOrEmpty(a.Key) && a.Key == callbackWords[1]).Value;
                    if (action != null)
                    {
                        await action.Invoke(update, client);
                    }
                }

                if (action == null)
                {
                    await DefaultAction(update, client);
                }
            }

            await MainAction(update, client);
        }
 private Task BackAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         SelectedCategoryName = Catalog.GetCategoryNameByProductId(CategoryId);
     }));
 }
Exemplo n.º 4
0
 private Task BackAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         NextStep = new ShowCatalogueProductsStep(SelectedCategoryId, ChatId, client);
     }));
 }
Exemplo n.º 5
0
        public override BotUpdate GetUpdate(JsonElement jsonElement)
        {
            Update update = JsonConvert.DeserializeObject <Update>(jsonElement.ToString());

            BotUpdate botUpdate = new BotUpdate();
            Message   message   = null;

            if (update.Message != null)
            {
                message             = update.Message;
                botUpdate.MessageId = update.Message.MessageId;

                botUpdate.CallbackData      = null;
                botUpdate.CallbackMessageId = 0;
            }
            else
            {
                message = update.CallbackQuery.Message;

                botUpdate.CallbackData      = update.CallbackQuery.Data;
                botUpdate.CallbackMessageId = update.CallbackQuery.Message.MessageId;
            }

            botUpdate.MessageText = message.Text;
            botUpdate.ChatId      = message.Chat.Id;

            return(botUpdate);
        }
Exemplo n.º 6
0
        private async Task BackAction(BotUpdate update, IBotClient client)
        {
            var next = new InitialCatalogueStep(ChatId, client);
            await next.Execute(update, client);

            NextStep = next.NextStep;
        }
 public override Task DefaultAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         SelectedCategoryName = Catalog.GetCategoryName(update.CallbackData.Split()[1]);
     }));
 }
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.PhoneNumber = update.MessageText;
            NextStep         = new ConfirmOrderStep(ChatId, BotClient, Data);

            await SendMessageAsync(Message);
        }
Exemplo n.º 9
0
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            NextStep = new SpecifyOrderProductsStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetCategoriesButtonRow(CommandName));

            await SendMessageAsync(Message, keyboardMarkup : keyboard);
        }
Exemplo n.º 10
0
 private Task OrderAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         Data.SetFullName(update.FullName);
         update.CallbackData = SelectedCategoryId;
         NextStep = new SpecifyPhoneStep(ChatId, client, Data);
     }));
 }
Exemplo n.º 11
0
        public override async Task DefaultAction(BotUpdate update, IBotClient client)
        {
            Data.Product = Catalog.GetProductName(update.CallbackData.Split()[1]);
            var backButton = new KeyboardMarkup(KeyboardTools.GetOrderAndBackButtons(Data.Product, CommandName));

            NextStep = new ReturnOrOrderStep(Data, update.CallbackData, ChatId, client);

            await EditMessageAsync($"{Message} {Data.Product}", update.CallbackMessageId, backButton);
        }
Exemplo n.º 12
0
        public void Update([FromBody] JsonElement input)
        {
            BotUpdate update = ControllerBot.GetUpdate(input);

            if (!ControllerBot.FindCommandAndExecute(update))
            {
                ControllerBot.ExecuteCommandStepForUpdate(update);
            }
        }
Exemplo n.º 13
0
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Category = Catalog.GetCategoryName(update.CallbackData.Split()[1]);
            NextStep      = new SpecifyPhoneStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetProductsButtonRow(Data.Category, CommandName));

            await EditMessageAsync(Message, update.CallbackMessageId, keyboard);
        }
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Adress = update.MessageText;
            NextStep    = new FinishOrderStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetConfirmAndCancelButtons(CommandName));

            await SendMessageAsync(Message);
            await SendMessageAsync(IsItCorrectMessage, keyboardMarkup : keyboard);
        }
Exemplo n.º 15
0
        public override async void Execute(BotUpdate update, IBotClient client)
        {
            var chatId = update.ChatId;

            await client.SendTextMessageAsync(chatId,
                                              "Используйте следующие команды чтобы:\n" +
                                              "/help - помощь\n" +
                                              "/order - оформить заказ\n" +
                                              "/catalogue - получить каталог товаров\n");
        }
        public override bool MustBeExecutedForUpdate(BotUpdate update)
        {
            var message      = update.MessageText;
            var callbackData = update.CallbackData;

            return(ContainsCommandName(message) ||
                   (!string.IsNullOrEmpty(message) && StepPool.Any(s => s.ChatId == update.ChatId && s.CommandName == Name)) ||
                   (!string.IsNullOrEmpty(callbackData) && ContainsCommandName(callbackData) &&
                    StepPool.Any(s => s.ChatId == update.ChatId && s.CommandName == Name)));
        }
Exemplo n.º 17
0
 public static void TriggerNewUpdateEvent(bool IsBot)
 {
     if (IsBot)
     {
         BotUpdate?.Invoke();
     }
     else
     {
         HandlerUpdate?.Invoke();
     }
 }
Exemplo n.º 18
0
 public void ExecuteCommandStepForUpdate(BotUpdate update)
 {
     foreach (var c in Commands)
     {
         if (c.MustBeExecutedForUpdate(update))
         {
             c.Execute(update, Client);
             break;
         }
     }
 }
        public override async Task MainAction(BotUpdate update, IBotClient client)
        {
            var keyboard = new KeyboardMarkup(new KeyboardButtonInfo[][]
            {
                KeyboardTools.GetProductsButtonRow(SelectedCategoryName, CommandName),
                new KeyboardButtonInfo[] { KeyboardTools.GetBackButton(CommandName) }
            });

            NextStep = new DescribeProductStep(ChatId, client, SelectedCategoryName);

            await EditMessageAsync(string.Format(Message, SelectedCategoryName), update.CallbackMessageId, keyboard);
        }
Exemplo n.º 20
0
        public bool FindCommandAndExecute(BotUpdate update)
        {
            var command = FindCommandByNameInMessage(update.MessageText);

            if (command != null)
            {
                command.Execute(update, Client);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override async void Execute(BotUpdate update, IBotClient client)
        {
            var message      = update.MessageText;
            var callbackData = update.CallbackData;

            IStep step = null;

            if (ContainsCommandName(message))
            {
                StepPool.Where(s => s.ChatId == update.ChatId && s.CommandName == Name)
                .ToList().ForEach(s => StepPool.Remove(s));
                //StepPool.Where(s => s.ChatId == update.ChatId).ToList().ForEach(s => StepPool.Remove(s));

                step = GetInitialStep(update, client);
            }
            else if (!string.IsNullOrEmpty(callbackData) && ContainsCommandName(callbackData) &&
                     StepPool.Any(s => s.ChatId == update.ChatId && s.CommandName == Name))
            {
                step = StepPool.SingleOrDefault(s => s.ChatId == update.ChatId && s.CommandName == Name);
                StepPool.Remove(step);
            }
            else if (!string.IsNullOrEmpty(message) && StepPool.Any(s => s.ChatId == update.ChatId && s.CommandName == Name))
            {
                step = StepPool.SingleOrDefault(s => s.ChatId == update.ChatId && s.CommandName == Name);
                StepPool.Remove(step);
            }

            try
            {
                await step.Execute(update, client);

                if (step.NextStep != null)
                {
                    StepPool.Add(step.NextStep);
                }
            }
            catch
            {
                await client.SendTextMessageAsync(update.ChatId, "Что-то пошло не так! Попробуйте ещё раз.");
            }
        }
Exemplo n.º 22
0
 public override async Task DefaultAction(BotUpdate update, IBotClient client)
 {
     await SendMessageAsync(Message, keyboardMarkup : KeyboardMarkup);
 }
Exemplo n.º 23
0
 private async Task BackAction(BotUpdate update, IBotClient client)
 {
     await EditMessageAsync(Message, update.CallbackMessageId, KeyboardMarkup);
 }
Exemplo n.º 24
0
 public override async void Execute(BotUpdate update, IBotClient client)
 {
     await client.SendTextMessageAsync(update.ChatId, "Hello!", replyToMessageId : update.MessageId);
 }
Exemplo n.º 25
0
 public abstract void Execute(BotUpdate update, IBotClient client);
Exemplo n.º 26
0
 public override Task DefaultAction(BotUpdate update, IBotClient client) => null;
Exemplo n.º 27
0
        public override async Task MainAction(BotUpdate update, IBotClient client)
        {
            await NextStep.Execute(update, client);

            NextStep = NextStep.NextStep;
        }
Exemplo n.º 28
0
 public virtual bool MustBeExecutedForUpdate(BotUpdate update)
 {
     return((update.MessageText != null) ? ContainsCommandName(update.MessageText) : false);
 }
Exemplo n.º 29
0
 private async Task CancelledAction(BotUpdate update, IBotClient client)
 {
     await EditMessageAsync(CancellationMessage, update.CallbackMessageId);
 }
Exemplo n.º 30
0
 private async Task ConfirmedAction(BotUpdate update, IBotClient client)
 {
     await EditMessageAsync(Message, update.CallbackMessageId);
 }