コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseAuthentication();
            //  SQLitePCL.raw.SetProvider(new SQLite3Provider_e_sqlite3());
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //  logger.LogError("Test Testovich");
            app.UseHttpsRedirection();

            app.UseRouting();

            //  app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //Bot Configurations
            //  DBHelper.ConnectionString = new string(@"C:\Users\Администратор\source\repos\VeldeBotTelegram\VeldeBotTelegram\bin\Debug\netcoreapp3.1\DataBase.db");
            DBHelper.ConnectionString = new string("./DataBase/DataBase.db");
            //  Question[] first = { new Question(0, "hello", new Answer("!", 1)), new Question(1, "12423", new Answer("2", 0)) };
            //   foreach(Question q in first)
            // DBHelper.AddQuestion(q);
            // DBHelper.GetQuestion(0);

            AppSettings.LoadBotConfig(2);
            BItrix24CRM.LoadBitrixConfig(1);
            Bot.GetBotClientAsync().Wait();
        }
コード例 #2
0
        private async Task ExecuteCommand(Message message, Telegram.Bot.TelegramBotClient botClient, string copymessage)
        {
            var commands = Bot.Commands;

            foreach (var command in commands)
            {
                if (command is TextMessageCommand || command is ImageMessageCommand || command is InlineImageGalleryCommand)
                {
                    await command.Execute(message, botClient, client);

                    client.Stage = command.NextStage(message, client);
                    UpdateClient(client, ref message);

                    await ExecuteCommand(message, botClient, copymessage);
                }
                else if (command is QuestionCommand || command is QuestionKitchenCommand)
                {
                    if (!command.Contains(message))
                    {
                        await command.Execute(message, botClient, client);
                    }
                    if (command.Contains(message))
                    {
                        client.Stage = command.NextStage(message, client);
                        UpdateClient(client, ref message);

                        if (command is QuestionKitchenCommand)
                        {
                            Kitchen kitchen = DBHelper.GetKitchen(client);
                            if (kitchen.Lenght == -1)
                            {
                                kitchen.Lenght = int.Parse(copymessage);
                            }
                            else if (kitchen.TypeFace == "null")
                            {
                                kitchen.TypeFace = copymessage;
                            }
                            else if (kitchen.TypeTable == "null")
                            {
                                kitchen.TypeTable = copymessage;
                            }
                            DBHelper.UpdateKitchen(kitchen);
                            if (kitchen.Lenght != -1 && kitchen.TypeFace != "null" && kitchen.TypeTable != "null")
                            {
                                var    culture     = new System.Globalization.CultureInfo("ru-RU");
                                string messageTEXT = "Базовая стоимость: " + kitchen.GetFullPrice("./DataBase/price.xlsx").ToString("#,#", culture) + "р. минус ваша скидка 10% = " + kitchen.GetSalePrice("./DataBase/price.xlsx", 1.2).ToString("#,#", culture) +
                                                     "р. (Кухня длиной " + kitchen.Lenght + " метра, фасады: "
                                                     + kitchen.TypeFace + ", фурнитура Blum, " +
                                                     "столешница: " + kitchen.TypeTable.ToLower() + ". В цену включены: замеры, создание прототипа, доставка, разгрузка, сборка и клининг.)";
                                string text = "Хорошие новости, при заказе кухни у Стаса, персональный бонус – скидка 10% 🎁";
                                await botClient.SendTextMessageAsync(message.Chat.Id, text, parseMode : Telegram.Bot.Types.Enums.ParseMode.Html);

                                await botClient.SendTextMessageAsync(message.Chat.Id, messageTEXT, parseMode : Telegram.Bot.Types.Enums.ParseMode.Html);

                                DBHelper.AddMessageTEXT(client, messageTEXT);
                                DBHelper.AddMessageTEXT(client, text);
                                DBHelper.EraseKitchen(kitchen);
                            }
                        }

                        await ExecuteCommand(message, botClient, copymessage);
                    }
                }

                else if (command is NameMessageCommand)
                {
                    await command.Execute(message, botClient, client);
                }
                else if (command is PhoneMessageCommand)
                {
                    if (message.Contact != null)
                    {
                        if (client.Name == "-1")
                        {
                            client.Name = message.Contact.FirstName + " " + message.Contact.LastName;
                        }
                        client.PhoneNumber = message.Contact.PhoneNumber;
                        client.Stage       = command.NextStage(message, client);
                        UpdateClient(client, ref message);
                        await BItrix24CRM.Start(client);
                        await ExecuteCommand(message, botClient, copymessage);
                    }

                    else if (message.Text == "Не буду")
                    {
                        client.Stage = command.NextStage(message, client);
                        UpdateClient(client, ref message);

                        await ExecuteCommand(message, botClient, copymessage);
                    }
                    else
                    {
                        // if (client.Name == null)
                        //   client.Name = message.Text;
                        Bot.AddMessage(client, message);
                        await command.Execute(message, botClient, client);
                    }
                }
            }
        }