Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            OkResult = this.Ok();

            if (update.CallbackQuery == null && update.InlineQuery == null)
            {
                BotCore = new ProductAddBot(update);
                Result  = await BotCore.Response();
            }

            if (update.InlineQuery != null)
            {
                InlineFind find = new InlineFind(update.InlineQuery);
                await find.Response();

                return(Ok());
            }


            if (update != null && update.CallbackQuery != null && update.CallbackQuery.Data != null && update.InlineQuery == null)
            {
                ModuleName = JsonConvert.DeserializeObject <BotCommand>(update.CallbackQuery.Data).M;
            }

            if (update.InlineQuery == null)
            {
                if (Result == null && ModuleName != null && ModuleName == ReportsBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new ReportsBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == MoreSettingsBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new MoreSettingsBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == HelpDeskProccessingBot.ModuleName || Result == null && ModuleName == null && update.InlineQuery == null)
                {
                    BotCore = new HelpDeskProccessingBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == NotificationBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new NotificationBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == OrderProccesingBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new OrderProccesingBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == CategoryBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new CategoryBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == ProductBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new ProductBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == BasketBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new BasketBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == AddressBot.ModuleName || Result == null && ModuleName == null ||
                    Result == null && update.Message != null && update.Message.Location != null)
                {
                    BotCore = new AddressBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == OrderBot.ModuleName || Result == null && ModuleName == null ||
                    Result == null && update.PreCheckoutQuery != null)
                {
                    BotCore = new OrderBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == OperatorBot.ModuleName || Result == null && ModuleName == null ||
                    Result == null && update.PreCheckoutQuery != null)
                {
                    BotCore = new OperatorBot(update);
                    Result  = await BotCore.Response();
                }

                if (update.Message != null && Result == null)
                {
                    BotCore = new FollowerBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == OrderPositionBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new OrderPositionBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == AdminBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new AdminBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == ProductEditBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new ProductEditBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == CategoryEditBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new CategoryEditBot(update);
                    Result  = await BotCore.Response();
                }

                if (Result == null && ModuleName != null && ModuleName == MainMenuBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new MainMenuBot(update);
                    Result  = await BotCore.Response();
                }


                if (Result == null && ModuleName != null && ModuleName == HelpDeskBot.ModuleName || Result == null && ModuleName == null)
                {
                    BotCore = new HelpDeskBot(update);
                    Result  = await BotCore.Response();
                }
            }

            //делаем так что бы наше приложние всегда отвечало телеграму ОК.
            //В противном случаем телеграм так и будет слать нам это сообщения в ожиданиее ответа ОК
            if (Result == null || Result != null)
            {
                Result = Ok();
            }

            if (update.Message != null && update.Message.Chat != null)
            {
                try
                {
                    BusinessLayer.FollowerFunction.InsertFollower(Convert.ToInt32(update.Message.Chat.Id),
                                                                  update.Message.Chat.FirstName, update.Message.Chat.LastName, update.Message.Chat.Username);
                }

                catch
                {
                }
            }

            if (update.CallbackQuery != null && update.CallbackQuery.Message != null && update.CallbackQuery.Message.Chat != null)
            {
                try
                {
                    BusinessLayer.FollowerFunction.InsertFollower(Convert.ToInt32(update.CallbackQuery.Message.Chat.Id),
                                                                  update.CallbackQuery.Message.Chat.FirstName, update.CallbackQuery.Message.Chat.LastName, update.CallbackQuery.Message.Chat.Username);
                }
                catch
                {
                }
            }

            AddUpdateMsgToDb(update);

            return(Result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            OkResult       = this.Ok();
            NotFoundResult = this.NotFound();

            if (update != null && update.CallbackQuery != null && update.CallbackQuery.Data != null)
            {
                ModuleName = JsonConvert.DeserializeObject <Bot.BotCommand>(update.CallbackQuery.Data).M;
            }

            if (Result == null && ModuleName != null && ModuleName == HelpDeskProccessingBot.ModuleName || Result == null && ModuleName == null)
            {
                HelpDeskProccessingBot = new HelpDeskProccessingBot(update);
                Result = await HelpDeskProccessingBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == OrderProccesingBot.ModuleName || Result == null && ModuleName == null)
            {
                OrderProccesingBot = new OrderProccesingBot(update);
                Result             = await OrderProccesingBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == CategoryBot.ModuleName || Result == null && ModuleName == null)
            {
                Category = new CategoryBot(update);
                Result   = await Category.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == ProductBot.ModuleName || Result == null && ModuleName == null)
            {
                Product = new ProductBot(update);
                Result  = await Product.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == BasketBot.ModuleName || Result == null && ModuleName == null)
            {
                Basket = new BasketBot(update);
                Result = await Basket.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == AddressBot.ModuleName || Result == null && ModuleName == null)
            {
                Address = new AddressBot(update);
                Result  = await Address.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == OrderBot.ModuleName || Result == null && ModuleName == null)
            {
                OrderBot = new OrderBot(update);
                Result   = await OrderBot.Response();
            }

            if (update.Message != null && Result == null)
            {
                FollowerBot = new FollowerBot(update);
                Result      = await FollowerBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == OrderPositionBot.ModuleName || Result == null && ModuleName == null)
            {
                PositionBot = new OrderPositionBot(update);
                Result      = await PositionBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == AdminBot.ModuleName || Result == null && ModuleName == null)
            {
                AdminBot = new AdminBot(update);
                Result   = await AdminBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == ProductEditBot.ModuleName || Result == null && ModuleName == null)
            {
                ProductEditBot = new ProductEditBot(update);
                Result         = await ProductEditBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == CategoryEditBot.ModuleName || Result == null && ModuleName == null)
            {
                CategoryEditBot = new CategoryEditBot(update);
                Result          = await CategoryEditBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == MainMenuBot.ModuleName || Result == null && ModuleName == null)
            {
                MainMenuBot = new MainMenuBot(update);
                Result      = await MainMenuBot.Response();
            }

            if (Result == null && ModuleName == null)
            {
                ImportCSVBot = new ImportCSVBot(update);
                Result       = await ImportCSVBot.Response();
            }

            if (Result == null && ModuleName != null && ModuleName == HelpDeskBot.ModuleName || Result == null && ModuleName == null)
            {
                HelpDeskBot = new HelpDeskBot(update);
                Result      = await HelpDeskBot.Response();
            }

            await AddUpdateMsgToDb(update);

            if (update.Message != null)
            {
                await  UpdateFollowerInfo(update.Message.Chat);
            }

            if (update.CallbackQuery != null && update.CallbackQuery.Message != null)
            {
                await UpdateFollowerInfo(update.CallbackQuery.Message.Chat);
            }


            if (Result == null || Result != null)
            {
                Result = Ok();
            }


            return(Result);
        }