Пример #1
0
        public void Run(BotManager botManager, bool isDebug)
        {
            botManager.ConfigureServices((servicesWrap) =>
            {
                var serv = servicesWrap.Services;
                LoggerStarter.InitLogger(servicesWrap);
                servicesWrap.AddMvc(new MvcOptions()
                {
                    CheckEqualsRouteInfo = true
                });

                serv.AddSingleton <ITelegramBotClient>((sp) =>
                {
                    return(botManager.BotContext.Bot);
                });
                serv.AddScoped <ISomeScopedService, SomeScopedService>();


                //Telegram storage test
                var opt = new TelegramStorageOptions()
                {
                    SaveResourcesChatId = BotTokenResolver.GetSaveResChatId(),
                    SaveOnSet           = true
                };
                serv.AddSingleton(opt);
                serv.AddSingleton <TelegramStorage>();
                serv.AddSingleton <IKeyValueStorage>((sp) =>
                {
                    return(sp.GetRequiredService <TelegramStorage>());
                });
                serv.AddSingleton <TelegramFilesCloud>();
            });

            botManager.ConfigureBuilder((builder) =>
            {
                if (isDebug)
                {
                    builder.UseDevEceptionMessage();
                }

                builder.UseExceptionHandler(async(ctx, ex) =>
                {
                    //Throw exception if false. False mean 'not handled'.
                    return(false);
                });

                builder.UseMvc(mvcBuilder =>
                {
                    mvcBuilder.UseDebugInfo();
                    mvcBuilder.MapRouteAction(async(actionCtx) =>
                    {
                        await actionCtx.UpdateContext.SendTextMessageAsync("Mvc works.");
                    }, template: "/mvc");
                });
            });
            botManager.Start();
        }
        static void Main(string[] args)
        {
            var token      = BotTokenResolver.GetToken();
            var bot        = new TelegramBotClient(token);
            var botManager = new BotManager(bot);

            var botTest = new BotTests_Mvc();

            botTest.Run(botManager, true);


            while (true)
            {
                Console.ReadLine();
            }
        }