Update readme, remove unnecessary projets.

This commit is contained in:
Oceania2018 2018-05-07 06:54:39 -05:00
parent fc51b23bcf
commit 41fd2a8bc4
19 changed files with 58 additions and 482 deletions

View file

@ -1,38 +0,0 @@
using BotSharp.Core.Agents;
using BotSharp.Core.Engines;
using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BotSharp.Core.RestApi
{
public class AgentController : EssentialController
{
[HttpGet("id")]
public Agent Get([FromRoute] String id)
{
var console = new RasaAi(dc, null);
return console.LoadAgent();
}
/// <summary>
/// New agent with basic configuration
/// </summary>
/// <param name="agent"></param>
/// <returns></returns>
[HttpPost]
public String Create([FromBody] Agent agent)
{
var rasa = new RasaAi(dc, null);
dc.DbTran(() => {
rasa.SaveAgent(agent);
});
return agent.Id;
}
}
}

View file

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.0\BotSharp.RestApi.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
</Project>

View file

@ -1,17 +0,0 @@
using BotSharp.Core.Entities;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.RestApi
{
public class EntityController : EssentialController
{
[HttpPost]
public string CreateEntity([FromBody] Entity entity)
{
return entity.Id;
}
}
}

View file

@ -1,25 +0,0 @@
using EntityFrameworkCore.BootKit;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.AspNetCore.Builder
{
public static class EntityDbContextBuilderExtensions
{
/// <summary>
/// Use CustomEntityFoundation
/// </summary>
/// <param name="app"></param>
/// <param name="configuration"></param>
/// <param name="contentRootPath"></param>
/// <param name="assembles"></param>
public static void UseEntityDbContext(this IApplicationBuilder app, IConfiguration configuration, String contentRootPath, String[] assembles)
{
Database.Configuration = configuration;
Database.Assemblies = assembles;
Database.ContentRootPath = contentRootPath;
}
}
}

View file

@ -1,16 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.RestApi
{
public class EntityItemController : EssentialController
{
[HttpPost]
public IActionResult CreateEntity()
{
return Ok();
}
}
}

View file

@ -1,31 +0,0 @@
using BotSharp.Core.Agents;
using BotSharp.Core.Entities;
using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.RestApi
{
public class EntityTypeController : EssentialController
{
[HttpPost]
public string CreateType([FromBody] Entity entityType)
{
var agent = dc.Table<Agent>().Find(entityType.AgentId);
dc.DbTran(() => agent.CreateEntityType(dc, entityType));
return entityType.Id;
}
[HttpDelete("{agentId}/{entityTypeId}")]
public IActionResult DeleteType([FromRoute] String agentId, [FromRoute] String entityTypeId)
{
var agent = dc.Table<Agent>().Find(agentId);
dc.DbTran(() => agent.DeleteEntityType(dc, entityTypeId));
return Ok();
}
}
}

View file

@ -1,43 +0,0 @@
using BotSharp.Core.Engines;
using DotNetToolkit;
using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
namespace BotSharp.Core.RestApi
{
//[Authorize]
[Produces("application/json")]
[Route("bot/[controller]")]
public class EssentialController : ControllerBase
{
protected Database dc { get; set; }
public EssentialController()
{
dc = new DefaultDataContextLoader().GetDefaultDc();
}
[HttpPatch("{table}/{id}")]
public IActionResult Patch([FromRoute] String table, [FromRoute] String id, [FromBody] JObject jObject)
{
var patch = new DbPatchModel
{
Table = table,
Id = id,
Values = jObject.ToDictionary()
};
dc.Patch<IDbRecord>(patch);
return Ok();
}
}
}

View file

@ -1,20 +0,0 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
using BotSharp.Core.Loader;
namespace Microsoft.AspNetCore.Builder
{
public static class InitLoaderBuilderExtensions
{
/// <summary>
/// Initialize Loader
/// </summary>
/// <param name="app"></param>
public static void UseInitLoader(this IApplicationBuilder app)
{
new InitializationLoader().Load();
}
}
}

View file

@ -1,61 +0,0 @@
{
"name": "Weather Bot",
"entity_types": [
{
"name": "date",
"values": [ "today", "tomorrow", "yesterday", "now" ]
}
],
"entity_synonyms": [
],
"intents": [
{
"name": "greet",
"expressions": [
{ "text": "Hi" },
{ "text": "Hey" },
{ "text": "Hello" },
{ "text": "How are you?" },
{ "text": "What's up?" },
{ "text": "How is going?" }
]
},
{
"name": "weather",
"expressions": [
{
"text": "What is the weather like today in Chicago?",
"entities": [
{
"start": 25,
"value": "today",
"entity": "date"
}
]
},
{
"text": "Will it be rain tomorrow in Beijing?",
"entities": [
{
"start": 16,
"value": "tomorrow",
"entity": "date"
},
{
"start": 28,
"value": "Beijing",
"entity": "location"
}
]
},
{ "text": "It's windy outside?" },
{ "text": "It's very code there?" },
{ "text": "It's gonna be snow?" }
]
}
]
}

View file

@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="App_Data\bot-rasa.db" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="2.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="2.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
</Project>

View file

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace BotSharp.WebStarter
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
var settings = Directory.GetFiles("./Settings/", "*.json");
settings.ToList().ForEach(setting =>
{
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
});
})
.UseUrls("http://localhost:9900")
.UseStartup<Startup>()
.Build();
}
}

View file

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}

View file

@ -1,11 +0,0 @@
{
"TokenAuthentication": {
"SecretKey": "QEMYOjgkNEq/krV1Ouzz8w==",
"Subject": "OpenBotKit",
"Issuer": "Haiping Chen",
"Audience": "Haiping Chen",
"TokenPath": "/token",
"CookieName": "token",
"LoginPath": "/login"
}
}

View file

@ -1,10 +0,0 @@
{
"AWS": {
"AWSRegionEndPoint": "us-east-1",
"AWSSecretKey": "",
"AWSAccessKey": "",
"AWSEncoding": "utf-8",
"SESVerifiedEmail": "",
"AWSBucketPrefix": ""
}
}

View file

@ -1,5 +0,0 @@
{
"Rasa": {
"Host": "http://bot.local:5000"
}
}

View file

@ -1,10 +0,0 @@
{
"Database": {
"Default": "SqlServer",
"ConnectionStrings": {
"InMemory": "DataSource=:memory:",
"Sqlite": "Data Source=|DataDirectory|BotSharp.db;",
"SqlServer": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BotSharp;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
}
}

View file

@ -1,12 +0,0 @@
{
"Swagger": {
"Version": "v1",
"Title": "Open Chatbot Kit",
"Description": "OpenBotKit API",
"TermsOfService": "MIT",
"Contact": {
"Name": "Haiping Chen",
"Email": "haiping008@gmail.com"
}
}
}

View file

@ -1,88 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BotSharp.Core.Engines;
using DotNetToolkit.JwtHelper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.Swagger;
namespace BotSharp.WebStarter
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddJwtAuth(Configuration);
services.AddMvc();
// Add framework services.
services.AddMvc(options =>
{
options.RespectBrowserAcceptHeader = true;
}).AddJsonOptions(options =>
{
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
//options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
services.AddSwaggerGen(c =>
{
c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" });
var info = Configuration.GetSection("Swagger").Get<Swashbuckle.AspNetCore.Swagger.Info>();
c.SwaggerDoc(info.Version, info);
var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "BotSharp.RestApi.xml");
c.IncludeXmlComments(filePath);
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Post, SubmitMethod.Put, SubmitMethod.Patch, SubmitMethod.Delete);
c.ShowExtensions();
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1");
c.RoutePrefix = "api";
});
app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
app.UseAuthentication();
app.UseMvc();
app.UseEntityDbContext(Configuration, env.ContentRootPath, new String[] { "BotSharp.Core" });
app.UseInitLoader();
}
}
}

58
README.md Normal file
View file

@ -0,0 +1,58 @@
# BotSharp
.Net implementation of open chatbot platform like google Dialogflow. Modulized design supports different NLU engine as backend.
### Features
* Multiple agents management
* Context In/ Out with lifespan to make conversion flow be controllable.
* Rasa NLU as is one of NLU engine
* Import agent from Dialogflow directly
### How to use
````cs
[TestMethod]
public void RestoreAgentTest()
{
var rasa = new RasaAi(dc);
var importer = new AgentImporterInDialogflow();
string dataDir = $"{Database.ContentRootPath}\\App_Data\\DbInitializer\\Agents\\";
var agent = rasa.RestoreAgent(importer, BOT_NAME, dataDir);
agent.Id = BOT_ID;
agent.ClientAccessToken = BOT_CLIENT_TOKEN;
agent.DeveloperAccessToken = BOT_DEVELOPER_TOKEN;
agent.UserId = Guid.NewGuid().ToString();
int row = dc.DbTran(() => rasa.SaveAgent(agent));
}
[TestMethod]
public void TrainAgentTest()
{
var config = new AIConfiguration(BOT_CLIENT_TOKEN, SupportedLanguage.English);
config.SessionId = Guid.NewGuid().ToString();
var rasa = new RasaAi(dc, config);
rasa.agent = rasa.LoadAgent();
string msg = rasa.Train(dc);
Assert.IsTrue(!String.IsNullOrEmpty(msg));
}
[TestMethod]
public void TextRequest()
{
var config = new AIConfiguration(BOT_CLIENT_TOKEN, SupportedLanguage.English);
config.SessionId = Guid.NewGuid().ToString();
var rasa = new RasaAi(dc, config);
var response = rasa.TextRequest(new AIRequest { Query = new String[] { "Hi" } });
Assert.AreEqual(response.Result.Metadata.IntentName, "Wakeup");
}
````
#### Tip Jar
* **Ethereum**
![Ethereum](https://raw.githubusercontent.com/Haiping-Chen/Etherscan.NetSDK/master/qr_code_eth.jpg)
##### 0x2FdE97210cd14F6020C67BAFA61d4c227FdC268d