diff --git a/BotSharp.RestApi/AgentController.cs b/BotSharp.RestApi/AgentController.cs
deleted file mode 100644
index 97de12db..00000000
--- a/BotSharp.RestApi/AgentController.cs
+++ /dev/null
@@ -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();
- }
-
- ///
- /// New agent with basic configuration
- ///
- ///
- ///
- [HttpPost]
- public String Create([FromBody] Agent agent)
- {
- var rasa = new RasaAi(dc, null);
-
- dc.DbTran(() => {
- rasa.SaveAgent(agent);
- });
-
- return agent.Id;
- }
- }
-}
diff --git a/BotSharp.RestApi/BotSharp.RestApi.csproj b/BotSharp.RestApi/BotSharp.RestApi.csproj
deleted file mode 100644
index d8802ebc..00000000
--- a/BotSharp.RestApi/BotSharp.RestApi.csproj
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
- netcoreapp2.0
-
-
-
- bin\Debug\netcoreapp2.0\BotSharp.RestApi.xml
-
-
-
-
-
-
-
-
-
-
-
diff --git a/BotSharp.RestApi/EntityController.cs b/BotSharp.RestApi/EntityController.cs
deleted file mode 100644
index 7632aac8..00000000
--- a/BotSharp.RestApi/EntityController.cs
+++ /dev/null
@@ -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;
- }
- }
-}
diff --git a/BotSharp.RestApi/EntityDbContextBuilderExtensions.cs b/BotSharp.RestApi/EntityDbContextBuilderExtensions.cs
deleted file mode 100644
index 9db6eb0a..00000000
--- a/BotSharp.RestApi/EntityDbContextBuilderExtensions.cs
+++ /dev/null
@@ -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
- {
- ///
- /// Use CustomEntityFoundation
- ///
- ///
- ///
- ///
- ///
- public static void UseEntityDbContext(this IApplicationBuilder app, IConfiguration configuration, String contentRootPath, String[] assembles)
- {
- Database.Configuration = configuration;
- Database.Assemblies = assembles;
- Database.ContentRootPath = contentRootPath;
- }
- }
-}
diff --git a/BotSharp.RestApi/EntityItemController.cs b/BotSharp.RestApi/EntityItemController.cs
deleted file mode 100644
index 60c118e1..00000000
--- a/BotSharp.RestApi/EntityItemController.cs
+++ /dev/null
@@ -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();
- }
- }
-}
diff --git a/BotSharp.RestApi/EntityTypeController.cs b/BotSharp.RestApi/EntityTypeController.cs
deleted file mode 100644
index a140a204..00000000
--- a/BotSharp.RestApi/EntityTypeController.cs
+++ /dev/null
@@ -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().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().Find(agentId);
- dc.DbTran(() => agent.DeleteEntityType(dc, entityTypeId));
-
- return Ok();
- }
- }
-}
diff --git a/BotSharp.RestApi/EssentialController.cs b/BotSharp.RestApi/EssentialController.cs
deleted file mode 100644
index 1c5b5491..00000000
--- a/BotSharp.RestApi/EssentialController.cs
+++ /dev/null
@@ -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(patch);
-
- return Ok();
- }
- }
-}
diff --git a/BotSharp.RestApi/InitLoaderBuilderExtensions.cs b/BotSharp.RestApi/InitLoaderBuilderExtensions.cs
deleted file mode 100644
index 37cb336a..00000000
--- a/BotSharp.RestApi/InitLoaderBuilderExtensions.cs
+++ /dev/null
@@ -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
- {
- ///
- /// Initialize Loader
- ///
- ///
- public static void UseInitLoader(this IApplicationBuilder app)
- {
- new InitializationLoader().Load();
- }
- }
-}
diff --git a/BotSharp.WebStarter/App_Data/DbInitializer/Agents/Rasa/2b6a288e-d891-40c6-96ce-6a0cf324545c.json b/BotSharp.WebStarter/App_Data/DbInitializer/Agents/Rasa/2b6a288e-d891-40c6-96ce-6a0cf324545c.json
deleted file mode 100644
index 4e8a7fbd..00000000
--- a/BotSharp.WebStarter/App_Data/DbInitializer/Agents/Rasa/2b6a288e-d891-40c6-96ce-6a0cf324545c.json
+++ /dev/null
@@ -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?" }
- ]
- }
- ]
-}
\ No newline at end of file
diff --git a/BotSharp.WebStarter/BotSharp.WebStarter.csproj b/BotSharp.WebStarter/BotSharp.WebStarter.csproj
deleted file mode 100644
index 9018544b..00000000
--- a/BotSharp.WebStarter/BotSharp.WebStarter.csproj
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- netcoreapp2.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/BotSharp.WebStarter/Program.cs b/BotSharp.WebStarter/Program.cs
deleted file mode 100644
index d823220c..00000000
--- a/BotSharp.WebStarter/Program.cs
+++ /dev/null
@@ -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()
- .Build();
- }
-}
diff --git a/BotSharp.WebStarter/Settings/settings.app.json b/BotSharp.WebStarter/Settings/settings.app.json
deleted file mode 100644
index 26bb0ac7..00000000
--- a/BotSharp.WebStarter/Settings/settings.app.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "Logging": {
- "IncludeScopes": false,
- "Debug": {
- "LogLevel": {
- "Default": "Warning"
- }
- },
- "Console": {
- "LogLevel": {
- "Default": "Warning"
- }
- }
- }
-}
diff --git a/BotSharp.WebStarter/Settings/settings.auth.json b/BotSharp.WebStarter/Settings/settings.auth.json
deleted file mode 100644
index c8d08264..00000000
--- a/BotSharp.WebStarter/Settings/settings.auth.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "TokenAuthentication": {
- "SecretKey": "QEMYOjgkNEq/krV1Ouzz8w==",
- "Subject": "OpenBotKit",
- "Issuer": "Haiping Chen",
- "Audience": "Haiping Chen",
- "TokenPath": "/token",
- "CookieName": "token",
- "LoginPath": "/login"
- }
-}
\ No newline at end of file
diff --git a/BotSharp.WebStarter/Settings/settings.aws.json b/BotSharp.WebStarter/Settings/settings.aws.json
deleted file mode 100644
index 88d79907..00000000
--- a/BotSharp.WebStarter/Settings/settings.aws.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "AWS": {
- "AWSRegionEndPoint": "us-east-1",
- "AWSSecretKey": "",
- "AWSAccessKey": "",
- "AWSEncoding": "utf-8",
- "SESVerifiedEmail": "",
- "AWSBucketPrefix": ""
- }
-}
\ No newline at end of file
diff --git a/BotSharp.WebStarter/Settings/settings.bot.json b/BotSharp.WebStarter/Settings/settings.bot.json
deleted file mode 100644
index dc0dffa1..00000000
--- a/BotSharp.WebStarter/Settings/settings.bot.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "Rasa": {
- "Host": "http://bot.local:5000"
- }
-}
diff --git a/BotSharp.WebStarter/Settings/settings.db.json b/BotSharp.WebStarter/Settings/settings.db.json
deleted file mode 100644
index ebd2d785..00000000
--- a/BotSharp.WebStarter/Settings/settings.db.json
+++ /dev/null
@@ -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"
- }
- }
-}
\ No newline at end of file
diff --git a/BotSharp.WebStarter/Settings/settings.swagger.json b/BotSharp.WebStarter/Settings/settings.swagger.json
deleted file mode 100644
index a1a35359..00000000
--- a/BotSharp.WebStarter/Settings/settings.swagger.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "Swagger": {
- "Version": "v1",
- "Title": "Open Chatbot Kit",
- "Description": "OpenBotKit API",
- "TermsOfService": "MIT",
- "Contact": {
- "Name": "Haiping Chen",
- "Email": "haiping008@gmail.com"
- }
- }
-}
diff --git a/BotSharp.WebStarter/Startup.cs b/BotSharp.WebStarter/Startup.cs
deleted file mode 100644
index d66f6a00..00000000
--- a/BotSharp.WebStarter/Startup.cs
+++ /dev/null
@@ -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();
- 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();
- }
- }
-}
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..94d0cdca
--- /dev/null
+++ b/README.md
@@ -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**
+
+
+##### 0x2FdE97210cd14F6020C67BAFA61d4c227FdC268d
\ No newline at end of file