Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var routeBuilder = new RouteBuilder(app);

            var handler = new IncomingWebhookHandler(m => MessageHandler.Handle(m))
            {
                CallbackSecret = Configuration["CallbackSecret"]
            };

            BotClient.DefaultAccessToken      = Configuration["AccessToken"];
            ImageSanitizer.GyazoAccessToken   = Configuration["GyazoAccessToken"];
            PriparaCommand.AnimeDBAccessToken = Configuration["AnimeDBAccessToken"];

            routeBuilder.MapGet("", async(c) =>
            {
                c.Response.ContentType = "text/plain; charset=utf-8";

                using (var w = new StreamWriter(c.Response.Body, new UTF8Encoding(false)))
                {
                    await w.WriteLineAsync("kohada").ConfigureAwait(false);
                    w.Flush();
                }
            });
            routeBuilder.MapPost("incoming", handler.HandleAsync);

            app.UseRouter(routeBuilder.Build());
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var routeBuilder = new RouteBuilder(app);

            string prev    = null;
            var    handler = new IncomingWebhookHandler(m => prev = m.RawContent)
            {
                CallbackSecret = Configuration["CallbackSecret"]
            };

            routeBuilder.MapGet("", async(c) =>
            {
                c.Response.ContentType = "text/plain; charset=utf-8";

                using (var w = new StreamWriter(c.Response.Body, new UTF8Encoding(false)))
                {
                    await w.WriteLineAsync("kokoro.io bot example").ConfigureAwait(false);
                    await w.WriteLineAsync().ConfigureAwait(false);

                    if (prev == null)
                    {
                        await w.WriteLineAsync("No request").ConfigureAwait(false);
                    }
                    else
                    {
                        await w.WriteLineAsync(prev).ConfigureAwait(false);
                    }
                    w.Flush();
                }
            });
            routeBuilder.MapPost("incoming", handler.HandleAsync);

            app.UseRouter(routeBuilder.Build());
        }