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);
        }
Esempio 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);
     }));
 }
Esempio n. 4
0
 private Task BackAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         NextStep = new ShowCatalogueProductsStep(SelectedCategoryId, ChatId, client);
     }));
 }
        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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
     }));
 }
Esempio 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);
        }
Esempio n. 12
0
        public void Update([FromBody] JsonElement input)
        {
            BotUpdate update = ControllerBot.GetUpdate(input);

            if (!ControllerBot.FindCommandAndExecute(update))
            {
                ControllerBot.ExecuteCommandStepForUpdate(update);
            }
        }
Esempio 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);
        }
Esempio 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)));
        }
Esempio n. 17
0
 public static void TriggerNewUpdateEvent(bool IsBot)
 {
     if (IsBot)
     {
         BotUpdate?.Invoke();
     }
     else
     {
         HandlerUpdate?.Invoke();
     }
 }
Esempio 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);
        }
Esempio 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, "Что-то пошло не так! Попробуйте ещё раз.");
            }
        }
Esempio n. 22
0
 public override async Task DefaultAction(BotUpdate update, IBotClient client)
 {
     await SendMessageAsync(Message, keyboardMarkup : KeyboardMarkup);
 }
Esempio n. 23
0
 private async Task BackAction(BotUpdate update, IBotClient client)
 {
     await EditMessageAsync(Message, update.CallbackMessageId, KeyboardMarkup);
 }
 public override async void Execute(BotUpdate update, IBotClient client)
 {
     await client.SendTextMessageAsync(update.ChatId, "Hello!", replyToMessageId : update.MessageId);
 }
Esempio n. 25
0
 public abstract void Execute(BotUpdate update, IBotClient client);
Esempio n. 26
0
 public override Task DefaultAction(BotUpdate update, IBotClient client) => null;
Esempio n. 27
0
        public override async Task MainAction(BotUpdate update, IBotClient client)
        {
            await NextStep.Execute(update, client);

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