diff --git a/BotSharp.Core/Abstractions/IInitializationLoader.cs b/BotSharp.Core/Abstractions/IInitializationLoader.cs index befa988a..e3d1638e 100644 --- a/BotSharp.Core/Abstractions/IInitializationLoader.cs +++ b/BotSharp.Core/Abstractions/IInitializationLoader.cs @@ -1,5 +1,6 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Text; @@ -9,6 +10,6 @@ namespace BotSharp.Core.Abstractions public interface IInitializationLoader { int Priority { get; } - void Initialize(IConfiguration config, IHostingEnvironment env); + void Initialize(IConfiguration config, IWebHostEnvironment env); } } diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 51c6aae6..240c430d 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -1,4 +1,4 @@ -using BotSharp.Platform.Models; +using BotSharp.Platform.Models; using BotSharp.Platform.Models.AiRequest; using BotSharp.Platform.Models.AiResponse; using BotSharp.Platform.Models.Entities; @@ -27,7 +27,7 @@ namespace BotSharp.Core.Engines Dc = new DefaultDataContextLoader().GetDefaultDc(); } - public async Task TextRequest(AiRequest request) + public Task TextRequest(AiRequest request) { var preditor = new BotPredictor(); var doc = preditor.Predict(Agent, new AiRequest @@ -44,8 +44,7 @@ namespace BotSharp.Core.Engines doc.Sentences[0].Entities = new List(); } doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value); - - return new AiResponse + return Task.FromResult(new AiResponse { /*Lang = request.Language, Timestamp = DateTime.UtcNow, @@ -66,7 +65,7 @@ namespace BotSharp.Core.Engines IntentName = doc.Sentences[0].Intent?.Label } }*/ - }; + }); } /*public TrainingCorpus GetIntentExpressions(AgentBase agent) diff --git a/BotSharp.Core/Engines/DbInitializer.cs b/BotSharp.Core/Engines/DbInitializer.cs index d9d5c066..3a955d25 100644 --- a/BotSharp.Core/Engines/DbInitializer.cs +++ b/BotSharp.Core/Engines/DbInitializer.cs @@ -1,4 +1,4 @@ -using BotSharp.Core.Abstractions; +using BotSharp.Core.Abstractions; using DotNetToolkit; using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Hosting; @@ -14,7 +14,7 @@ namespace BotSharp.Core.Engines { public int Priority => 1; - public void Initialize(IConfiguration config, IHostingEnvironment env) + public void Initialize(IConfiguration config, IWebHostEnvironment env) { var dc = new DefaultDataContextLoader().GetDefaultDc(); diff --git a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj index 54df0564..e5f20416 100644 --- a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj +++ b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj @@ -4,6 +4,11 @@ $(DefaultTargetFramework) true 0.2.2 + true + $(NoWarn);1591 + + + Haiping Chen BotSharp platform emulator which is compatible with Google Dialogflow. https://github.com/Oceania2018/botsharp-dialogflow diff --git a/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs b/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs index c5623a7e..e36f95a5 100644 --- a/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs +++ b/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs @@ -1,4 +1,4 @@ -using BotSharp.Platform.Dialogflow.Models; +using BotSharp.Platform.Dialogflow.Models; using BotSharp.Platform.Dialogflow.ViewModels; using BotSharp.Platform.Models.Agents; using Microsoft.AspNetCore.Http; @@ -31,7 +31,7 @@ namespace BotSharp.Platform.Dialogflow.Controllers /// /// Import a agent from a uploaded zip file /// - /// + /// Upload Zip File, meta.json is the extra data for customized function. /// [HttpPost("import")] [ProducesResponseType(typeof(ImportedAgentViewModel), 200)] diff --git a/BotSharp.WebHost/Settings/logging.json b/BotSharp.WebHost/Settings/logging.json index 26bb0ac7..537f535e 100644 --- a/BotSharp.WebHost/Settings/logging.json +++ b/BotSharp.WebHost/Settings/logging.json @@ -1,15 +1,19 @@ -{ +{ "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } - } + //"IncludeScopes": false, + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + }//, + //"Debug": { + // "LogLevel": { + // "Default": "Warning" + // } + //}, + //"Console": { + // "LogLevel": { + // "Default": "Warning" + // } + //} } } diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index c05f8078..128678b4 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -11,6 +11,7 @@ using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerUI; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Drawing; using System.IO; using System.Linq; @@ -59,14 +60,20 @@ namespace BotSharp.WebHost services.AddSwaggerGen(c => { - var scheme = new OpenApiSecurityScheme() + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() { In = ParameterLocation.Header, Description = "Please insert JWT with Bearer schema. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", - Type = SecuritySchemeType.ApiKey - }; - c.AddSecurityDefinition("Bearer", scheme); + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer" + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { new OpenApiSecurityScheme(){ + Reference = new OpenApiReference{Type = ReferenceType.SecurityScheme ,Id = "Bearer"} + }, new List(0) } + }); var info = Configuration.GetSection("Swagger").Get(); c.SwaggerDoc(info.Version, info); @@ -76,9 +83,14 @@ namespace BotSharp.WebHost { c.IncludeXmlComments(filePath); } - - //c.OperationFilter(); + var xmlPath = Path.Combine(AppContext.BaseDirectory, "BotSharp.Platform.Dialogflow.xml"); + if (File.Exists(xmlPath)) + { + c.IncludeXmlComments(xmlPath); + } + + c.OperationFilter(); }).AddSwaggerGenNewtonsoftSupport(); // register platform dependency diff --git a/BotSharp.WebHost/SwaggerFileUploadOperation.cs b/BotSharp.WebHost/SwaggerFileUploadOperation.cs index 9e71e80a..0d71c963 100644 --- a/BotSharp.WebHost/SwaggerFileUploadOperation.cs +++ b/BotSharp.WebHost/SwaggerFileUploadOperation.cs @@ -8,26 +8,20 @@ using System.Text; namespace BotSharp.WebHost { - //public class SwaggerFileUploadOperation : IOperationFilter - //{ + public class SwaggerFileUploadOperation : IOperationFilter + { - // public void Apply(OpenApiOperation operation, OperationFilterContext context) - // { - // if (operation.OperationId == "Import") - // { - // operation.Parameters.Clear(); + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if(context.MethodInfo.Name == "Import") + { + if(operation.RequestBody.Content.FirstOrDefault().Value?.Schema?.Properties.ContainsKey("uploadedFile") == true) + { + var p = operation.RequestBody.Content.FirstOrDefault(); + p.Value.Schema.Properties["uploadedFile"].Description = "Upload Zip File, meta.json is the extra data for customized function."; + } + } - // operation.Parameters.Add(new OpenApiParameter - // { - // Name = "uploadedFile", - // In = "formData", - // Description = "Upload Zip File, meta.json is the extra data for customized function.", - // Required = true, - // Type = "file" - // }); - // operation.Consumes.Add("multipart/form-data"); - // operation. - // } - // } - //} + } + } }