From d9e1b40d1c5da1af5983af6a5db336f54461acd0 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Fri, 28 Sep 2018 17:25:55 -0500 Subject: [PATCH] Refactoring the system, abstracting the platform builder, and decouple the implementation of each platform. --- BotSharp.Core/AgentStorageInMemory.cs | 62 +++++++ BotSharp.Core/BotSharp.Core.csproj | 2 + BotSharp.Core/PlatformBuilderBase.cs | 43 +++++ .../BotSharp.Platform.Abstraction.csproj | 11 ++ .../IAgentStorage.cs | 41 +++++ .../IPlatformBuilder.cs | 45 +++++ .../BotSharp.Platform.Models.csproj | 13 ++ .../DialogRequestOptions.cs | 10 ++ BotSharp.Platform.Models/StandardAgent.cs | 83 ++++++++++ .../Articulate/AgentController.cs | 74 --------- .../Articulate/SettingsController.cs | 28 ---- BotSharp.RestApi/BotSharp.RestApi.csproj | 1 + BotSharp.WebHost/BotSharp.WebHost.csproj | 1 + BotSharp.WebHost/Settings/ArticulateAi.json | 40 +++++ .../Settings/{bot.json => BotSharpAi.json} | 0 BotSharp.sln | 154 ++++++++++++++++++ Platform.Articulate/ArticulateAi.cs | 52 ++++++ .../Controllers/AgentController.cs | 115 +++++++++++++ .../Controllers}/DomainController.cs | 22 ++- .../Controllers}/EntityController.cs | 33 ++-- .../Controllers}/IntentController.cs | 7 +- .../Controllers/SettingsController.cs | 52 ++++++ .../Models}/AgentModel.cs | 4 +- .../Models}/DomainModel.cs | 2 +- .../Models}/EntityModel.cs | 2 +- .../Models}/EntitySynonymModel.cs | 2 +- .../Models}/IntentExampleModel.cs | 5 +- .../Models}/IntentModel.cs | 2 +- .../Models}/IntentScenarioModel.cs | 2 +- .../Models}/LanguageModel.cs | 2 +- .../Models}/PipelineModel.cs | 2 +- .../Models}/SettingsModel.cs | 2 +- .../Models}/SlotModel.cs | 2 +- .../Platform.Articulate.csproj | 20 +++ .../ViewModels}/DomainPageViewModel.cs | 4 +- .../ViewModels}/EntityPageViewModel.cs | 4 +- .../ViewModels}/IntentPageViewModel.cs | 4 +- Platform.Botpress/Platform.Botpress.csproj | 7 + .../Platform.Dialogflow.csproj | 7 + Platform.RasaTalk/Platform.RasaTalk.csproj | 7 + Platform.RasaUI/Platform.RasaUI.csproj | 7 + 41 files changed, 838 insertions(+), 138 deletions(-) create mode 100644 BotSharp.Core/AgentStorageInMemory.cs create mode 100644 BotSharp.Core/PlatformBuilderBase.cs create mode 100644 BotSharp.Platform.Abstraction/BotSharp.Platform.Abstraction.csproj create mode 100644 BotSharp.Platform.Abstraction/IAgentStorage.cs create mode 100644 BotSharp.Platform.Abstraction/IPlatformBuilder.cs create mode 100644 BotSharp.Platform.Models/BotSharp.Platform.Models.csproj create mode 100644 BotSharp.Platform.Models/DialogRequestOptions.cs create mode 100644 BotSharp.Platform.Models/StandardAgent.cs delete mode 100644 BotSharp.RestApi/Articulate/AgentController.cs delete mode 100644 BotSharp.RestApi/Articulate/SettingsController.cs create mode 100644 BotSharp.WebHost/Settings/ArticulateAi.json rename BotSharp.WebHost/Settings/{bot.json => BotSharpAi.json} (100%) create mode 100644 Platform.Articulate/ArticulateAi.cs create mode 100644 Platform.Articulate/Controllers/AgentController.cs rename {BotSharp.RestApi/Articulate => Platform.Articulate/Controllers}/DomainController.cs (70%) rename {BotSharp.RestApi/Articulate => Platform.Articulate/Controllers}/EntityController.cs (60%) rename {BotSharp.RestApi/Articulate => Platform.Articulate/Controllers}/IntentController.cs (97%) create mode 100644 Platform.Articulate/Controllers/SettingsController.cs rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/AgentModel.cs (89%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/DomainModel.cs (91%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/EntityModel.cs (91%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/EntitySynonymModel.cs (83%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/IntentExampleModel.cs (81%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/IntentModel.cs (91%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/IntentScenarioModel.cs (91%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/LanguageModel.cs (82%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/PipelineModel.cs (78%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/SettingsModel.cs (95%) rename {BotSharp.Core/Engines/Articulate => Platform.Articulate/Models}/SlotModel.cs (88%) create mode 100644 Platform.Articulate/Platform.Articulate.csproj rename {BotSharp.RestApi/Articulate => Platform.Articulate/ViewModels}/DomainPageViewModel.cs (72%) rename {BotSharp.RestApi/Articulate => Platform.Articulate/ViewModels}/EntityPageViewModel.cs (72%) rename {BotSharp.RestApi/Articulate => Platform.Articulate/ViewModels}/IntentPageViewModel.cs (72%) create mode 100644 Platform.Botpress/Platform.Botpress.csproj create mode 100644 Platform.Dialogflow/Platform.Dialogflow.csproj create mode 100644 Platform.RasaTalk/Platform.RasaTalk.csproj create mode 100644 Platform.RasaUI/Platform.RasaUI.csproj diff --git a/BotSharp.Core/AgentStorageInMemory.cs b/BotSharp.Core/AgentStorageInMemory.cs new file mode 100644 index 00000000..12658806 --- /dev/null +++ b/BotSharp.Core/AgentStorageInMemory.cs @@ -0,0 +1,62 @@ +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BotSharp.Core +{ + /// + /// Save agent instance into memory. + /// Caution: Data will be lost once application restarts. + /// + public class AgentStorageInMemory : IAgentStorage + { + private static Dictionary> agents; + + public AgentStorageInMemory() + { + if (agents == null) agents = new Dictionary>(); + } + + public StandardAgent FetchById(string agentId) + { + if (agents.ContainsKey(agentId)) + { + return agents[agentId]; + } + else + { + return null; + } + } + + public StandardAgent FetchByName(string agentName) + { + var data = agents.FirstOrDefault(x => x.Value.Name == agentName); + + return data.Value; + } + + public bool Persist(StandardAgent agent) + { + if (String.IsNullOrEmpty(agent.Id)) + { + agent.Id = Guid.NewGuid().ToString(); + agents[agent.Id] = agent; + } + else + { + agents[agent.Id] = agent; + } + + return true; + } + + public List> Query() + { + return agents.Select(x => x.Value).ToList(); + } + } +} diff --git a/BotSharp.Core/BotSharp.Core.csproj b/BotSharp.Core/BotSharp.Core.csproj index 1f60af4f..b7afbf98 100644 --- a/BotSharp.Core/BotSharp.Core.csproj +++ b/BotSharp.Core/BotSharp.Core.csproj @@ -66,6 +66,8 @@ If you feel that this project is helpful to you, please Star on the project, we + + diff --git a/BotSharp.Core/PlatformBuilderBase.cs b/BotSharp.Core/PlatformBuilderBase.cs new file mode 100644 index 00000000..4b5777fe --- /dev/null +++ b/BotSharp.Core/PlatformBuilderBase.cs @@ -0,0 +1,43 @@ +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core +{ + public abstract class PlatformBuilderBase + where TStorage : IAgentStorage, new () + { + protected static TStorage storage; + + public PlatformBuilderBase() + { + if (storage == null) storage = new TStorage(); + } + + public List> GetAllAgents() + { + return storage.Query(); + } + + + public StandardAgent GetAgentById(string agentId) + { + return storage.FetchById(agentId); + } + + public StandardAgent GetAgentByName(string agentName) + { + return storage.FetchByName(agentName); + } + + public virtual bool SaveAgent(StandardAgent agent) + { + // default save agent in FileStorage + storage.Persist(agent); + + return true; + } + } +} diff --git a/BotSharp.Platform.Abstraction/BotSharp.Platform.Abstraction.csproj b/BotSharp.Platform.Abstraction/BotSharp.Platform.Abstraction.csproj new file mode 100644 index 00000000..0dddb6cc --- /dev/null +++ b/BotSharp.Platform.Abstraction/BotSharp.Platform.Abstraction.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/BotSharp.Platform.Abstraction/IAgentStorage.cs b/BotSharp.Platform.Abstraction/IAgentStorage.cs new file mode 100644 index 00000000..fc169877 --- /dev/null +++ b/BotSharp.Platform.Abstraction/IAgentStorage.cs @@ -0,0 +1,41 @@ +using BotSharp.Platform.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Platform.Abstraction +{ + /// + /// Agent could be persisted in any kind of storage. + /// Example: local file storage, cloud storage, relational database, key-value database or memory + /// + public interface IAgentStorage + { + /// + /// Save agent instance + /// + /// + /// + bool Persist(StandardAgent agent); + + /// + /// Get agent by id + /// + /// + /// + StandardAgent FetchById(string agentId); + + /// + /// Get agent by name + /// + /// + /// + StandardAgent FetchByName(string agentName); + + /// + /// Query agents + /// + /// + List> Query(); + } +} diff --git a/BotSharp.Platform.Abstraction/IPlatformBuilder.cs b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs new file mode 100644 index 00000000..fe2d11b2 --- /dev/null +++ b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs @@ -0,0 +1,45 @@ +using BotSharp.Platform.Models; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace BotSharp.Platform.Abstraction +{ + /// + /// Platform abstraction + /// Implement this interface to build a Chatbot platform + /// + public interface IPlatformBuilder + where TStorage : IAgentStorage, new() + { + /// + /// Parse options for the incoming text or voice request from the sender. + /// + // DialogRequestOptions RequestOptions { get; set; } + + /// + /// Convert platform specific agent to standard agent format + /// + /// + /// + StandardAgent StandardizeAgent(TAgent agent); + + /// + /// Recover standard agent to specific agent format + /// + /// + /// + TAgent RecoverAgent(StandardAgent agent); + + /// + /// + /// + /// + /// + /// + bool SaveAgent(StandardAgent agent); + + StandardAgent GetAgentById(string agentId); + } +} diff --git a/BotSharp.Platform.Models/BotSharp.Platform.Models.csproj b/BotSharp.Platform.Models/BotSharp.Platform.Models.csproj new file mode 100644 index 00000000..5ca7d4a8 --- /dev/null +++ b/BotSharp.Platform.Models/BotSharp.Platform.Models.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + + + + + C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.1.0\ref\netcoreapp2.1\System.ComponentModel.Annotations.dll + + + + diff --git a/BotSharp.Platform.Models/DialogRequestOptions.cs b/BotSharp.Platform.Models/DialogRequestOptions.cs new file mode 100644 index 00000000..b8cec948 --- /dev/null +++ b/BotSharp.Platform.Models/DialogRequestOptions.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Platform.Models +{ + public class DialogRequestOptions + { + } +} diff --git a/BotSharp.Platform.Models/StandardAgent.cs b/BotSharp.Platform.Models/StandardAgent.cs new file mode 100644 index 00000000..22ef28f0 --- /dev/null +++ b/BotSharp.Platform.Models/StandardAgent.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace BotSharp.Platform.Models +{ + /// + /// Standard agent data structure + /// All other platform agent has to align with this standard data structure. + /// + public class StandardAgent + { + public StandardAgent() + { + CreatedDate = DateTime.UtcNow; + Entities = new List(); + } + + /// + /// Guid + /// + [StringLength(36)] + public String Id { get; set; } + + /// + /// Name of chatbot + /// + [Required] + [MaxLength(64)] + public String Name { get; set; } + + /// + /// Description of chatbot + /// + [MaxLength(256)] + public String Description { get; set; } + + /// + /// Is the chatbot public or private + /// + public Boolean Published { get; set; } + + /// + /// + /// + [Required] + [MaxLength(5)] + public String Language { get; set; } + + /// + /// Only access text/ audio rquest + /// + [StringLength(32)] + public String ClientAccessToken { get; set; } + + /// + /// Developer can access more APIs + /// + [StringLength(32)] + public String DeveloperAccessToken { get; set; } + + //public List Intents { get; set; } + + public List Entities { get; set; } + + public String Birthday + { + get + { + return CreatedDate.ToShortDateString(); + } + } + + public DateTime CreatedDate { get; set; } + + /// + /// Save extra information for specific platform + /// + public TExtraData ExtraData { get; set; } + } +} diff --git a/BotSharp.RestApi/Articulate/AgentController.cs b/BotSharp.RestApi/Articulate/AgentController.cs deleted file mode 100644 index c20d4ecd..00000000 --- a/BotSharp.RestApi/Articulate/AgentController.cs +++ /dev/null @@ -1,74 +0,0 @@ -using BotSharp.Core.Engines.Articulate; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace BotSharp.RestApi.Articulate -{ -#if ARTICULATE - [Route("[controller]")] - public class AgentController : ControllerBase - { - [HttpGet] - public List GetAgent() - { - var agents = new List(); - - string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); - - var agentPaths = Directory.GetFiles(dataDir).Where(x => Regex.IsMatch(x, @"agent-\d+.json")).ToList(); - for (int i = 0; i< agentPaths.Count; i++) - { - string json = System.IO.File.ReadAllText(agentPaths[i]); - - var agent = JsonConvert.DeserializeObject(json); - - agents.Add(agent); - } - - return agents; - } - - [HttpGet("{agentId}")] - public AgentModel GetAgent([FromRoute] int agentId) - { - string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", $"agent-{agentId}.json"); - - string json = System.IO.File.ReadAllText(dataPath); - - var agent = JsonConvert.DeserializeObject(json); - - return agent; - } - - [HttpGet("name/{agentName}")] - public AgentModel GetAgent([FromRoute] string agentName) - { - AgentModel agent = null; - - string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); - - var agentPaths = Directory.GetFiles(dataDir).Where(x => Regex.IsMatch(x, @"agent-\d+\.json")).ToList(); - - for (int i = 0; i < agentPaths.Count; i++) - { - string json = System.IO.File.ReadAllText(agentPaths[i]); - - var agentTmp = JsonConvert.DeserializeObject(json); - - if(agentTmp.AgentName == agentName) - { - agent = agentTmp; - } - } - - return agent; - } - } -#endif -} diff --git a/BotSharp.RestApi/Articulate/SettingsController.cs b/BotSharp.RestApi/Articulate/SettingsController.cs deleted file mode 100644 index 34e33c90..00000000 --- a/BotSharp.RestApi/Articulate/SettingsController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using BotSharp.Core.Engines.Articulate; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace BotSharp.RestApi.Articulate -{ -#if ARTICULATE - [Route("[controller]")] - public class SettingsController : ControllerBase - { - [HttpGet] - public SettingsModel GetSettings() - { - string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json"); - - string json = System.IO.File.ReadAllText(dataPath); - - var settings = JsonConvert.DeserializeObject(json); - - return settings; - } - } -#endif -} diff --git a/BotSharp.RestApi/BotSharp.RestApi.csproj b/BotSharp.RestApi/BotSharp.RestApi.csproj index 1cb54d7d..0d5fbdd3 100644 --- a/BotSharp.RestApi/BotSharp.RestApi.csproj +++ b/BotSharp.RestApi/BotSharp.RestApi.csproj @@ -88,6 +88,7 @@ + diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index 9730e053..1186a617 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -65,6 +65,7 @@ + diff --git a/BotSharp.WebHost/Settings/ArticulateAi.json b/BotSharp.WebHost/Settings/ArticulateAi.json new file mode 100644 index 00000000..51480a35 --- /dev/null +++ b/BotSharp.WebHost/Settings/ArticulateAi.json @@ -0,0 +1,40 @@ +{ + "ArticulateAi": { + "Lang": "en", + + "Provider": "BotSharpProvider", + "BotSharpProvider": { + }, + + "Pipe": "BotSharpTokenizer, BotSharpTagger, BotSharpCRFNer, BotSharpIntentClassifier", + + "BotSharpTokenizer": { + "tokenizer": "TreebankTokenizer" + }, + + "BotSharpIntentClassifier": { + "classifer": "SVMClassifier" + }, + + "BotSharpTagger": { + "tagger": "NGramTagger" + }, + + "BotSharpCRFNer": { + "template": "|App_Data|CRFLite/template.en" + }, + + "CRFsuiteEntityRecognizer": { + "fields": "y w pos chk", + "uniFeatures": "w wl pos chk shape shaped type p1 p2 p3 p4 s1 s2 s3 s4 2d 4d d&a d&- d&/ d&, d&. up iu au al ad ao cu cl ca cd cs", + "biFeatures": "w pos chk shaped type" + }, + + "WitAiEntityRecognizer": { + "url": "https://api.wit.ai", + "resource": "message", + "serverAccessToken": "SERVER_ACCESS_TOKEN", + "version": "20180811" + } + } +} diff --git a/BotSharp.WebHost/Settings/bot.json b/BotSharp.WebHost/Settings/BotSharpAi.json similarity index 100% rename from BotSharp.WebHost/Settings/bot.json rename to BotSharp.WebHost/Settings/BotSharpAi.json diff --git a/BotSharp.sln b/BotSharp.sln index 8248a89a..87c59f3f 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -31,6 +31,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.NLP.UnitTest", "Bo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Core.UnitTest", "BotSharp.Core.UnitTest\BotSharp.Core.UnitTest.csproj", "{30F80E7D-951A-4E8F-9C3C-2C866528EABD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Platform.Abstraction", "BotSharp.Platform.Abstraction\BotSharp.Platform.Abstraction.csproj", "{62F08F9F-16C2-4754-90B0-B604DC18AE23}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Platform.Models", "BotSharp.Platform.Models\BotSharp.Platform.Models.csproj", "{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.Articulate", "Platform.Articulate\Platform.Articulate.csproj", "{2B279A6C-C829-4D29-9C1C-809C8A8E36B2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.RasaTalk", "Platform.RasaTalk\Platform.RasaTalk.csproj", "{4D8203E8-0A68-42C9-AA21-9A0514E1008A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.Dialogflow", "Platform.Dialogflow\Platform.Dialogflow.csproj", "{25503190-0B4B-4ECA-8C0C-D12A53A09583}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.RasaUI", "Platform.RasaUI\Platform.RasaUI.csproj", "{FD087443-4A45-4796-893C-6EEB2D5029D5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.Botpress", "Platform.Botpress\Platform.Botpress.csproj", "{D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution ARTICULATE|Any CPU = ARTICULATE|Any CPU @@ -265,6 +279,146 @@ Global {30F80E7D-951A-4E8F-9C3C-2C866528EABD}.Release|Any CPU.Build.0 = Release|Any CPU {30F80E7D-951A-4E8F-9C3C-2C866528EABD}.Release|x64.ActiveCfg = Release|x64 {30F80E7D-951A-4E8F-9C3C-2C866528EABD}.Release|x64.Build.0 = Release|x64 + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Debug|x64.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Debug|x64.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.RASA|Any CPU.Build.0 = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.RASA|x64.ActiveCfg = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.RASA|x64.Build.0 = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Release|Any CPU.Build.0 = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Release|x64.ActiveCfg = Release|Any CPU + {62F08F9F-16C2-4754-90B0-B604DC18AE23}.Release|x64.Build.0 = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Debug|x64.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Debug|x64.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.RASA|Any CPU.Build.0 = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.RASA|x64.ActiveCfg = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.RASA|x64.Build.0 = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.Build.0 = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.ActiveCfg = Release|Any CPU + {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.Build.0 = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Debug|x64.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Debug|x64.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.RASA|Any CPU.Build.0 = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.RASA|x64.ActiveCfg = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.RASA|x64.Build.0 = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Release|Any CPU.Build.0 = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Release|x64.ActiveCfg = Release|Any CPU + {2B279A6C-C829-4D29-9C1C-809C8A8E36B2}.Release|x64.Build.0 = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Debug|x64.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Debug|x64.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.RASA|Any CPU.Build.0 = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.RASA|x64.ActiveCfg = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.RASA|x64.Build.0 = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Release|Any CPU.Build.0 = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Release|x64.ActiveCfg = Release|Any CPU + {4D8203E8-0A68-42C9-AA21-9A0514E1008A}.Release|x64.Build.0 = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Debug|x64.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Debug|x64.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.RASA|Any CPU.Build.0 = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.RASA|x64.ActiveCfg = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.RASA|x64.Build.0 = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Release|Any CPU.Build.0 = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Release|x64.ActiveCfg = Release|Any CPU + {25503190-0B4B-4ECA-8C0C-D12A53A09583}.Release|x64.Build.0 = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Debug|x64.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Debug|x64.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.RASA|Any CPU.Build.0 = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.RASA|x64.ActiveCfg = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.RASA|x64.Build.0 = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Release|Any CPU.Build.0 = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Release|x64.ActiveCfg = Release|Any CPU + {FD087443-4A45-4796-893C-6EEB2D5029D5}.Release|x64.Build.0 = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.ARTICULATE|x64.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Debug|x64.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Debug|x64.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.RASA|Any CPU.ActiveCfg = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.RASA|Any CPU.Build.0 = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.RASA|x64.ActiveCfg = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.RASA|x64.Build.0 = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Release|Any CPU.Build.0 = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Release|x64.ActiveCfg = Release|Any CPU + {D796FD0C-D161-41D1-8D3C-5B9B39FB3C28}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Platform.Articulate/ArticulateAi.cs b/Platform.Articulate/ArticulateAi.cs new file mode 100644 index 00000000..204571b7 --- /dev/null +++ b/Platform.Articulate/ArticulateAi.cs @@ -0,0 +1,52 @@ +using BotSharp.Core; +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using Platform.Articulate.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Platform.Articulate +{ + /// + /// A platform for building conversational interfaces with intelligent agents (chatbots) + /// http://spg.ai/projects/articulate + /// This implementation takes over APIs of Articulate's 7500 port. + /// + public class ArticulateAi : + PlatformBuilderBase, + IPlatformBuilder + where TStorage : IAgentStorage, new() + { + public DialogRequestOptions RequestOptions { get; set; } + + public TAgent RecoverAgent(StandardAgent agent) + { + if (agent == null) return default(TAgent); + + var agent1 = new AgentModel + { + Id = agent.Id, + AgentName = agent.Name, + Description = agent.Description, + Language = agent.Language + }; + + return (TAgent)(agent1 as Object); + } + + public StandardAgent StandardizeAgent(TAgent specificAgent) + { + var agent1 = specificAgent as AgentModel; + + var standardAgent = new StandardAgent + { + Name = agent1.AgentName, + Language = agent1.Language, + Description = agent1.Description + }; + + return standardAgent; + } + } +} diff --git a/Platform.Articulate/Controllers/AgentController.cs b/Platform.Articulate/Controllers/AgentController.cs new file mode 100644 index 00000000..84ae4ecb --- /dev/null +++ b/Platform.Articulate/Controllers/AgentController.cs @@ -0,0 +1,115 @@ +using BotSharp.Core; +using BotSharp.Core.Agents; +using BotSharp.Core.Engines; +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Platform.Articulate; +using Platform.Articulate.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Platform.Articulate.Controllers +{ +#if ARTICULATE + [Route("[controller]")] + public class AgentController : ControllerBase + { + private readonly IBotPlatform _platform; + + /// + /// Initialize agent controller and get a platform instance + /// + /// + public AgentController(IBotPlatform platform) + { + _platform = platform; + } + + [HttpPost] + public AgentModel PostAgent() + { + AgentModel agent = null; + + using (var reader = new StreamReader(Request.Body)) + { + string body = reader.ReadToEnd(); + agent = JsonConvert.DeserializeObject(body); + } + + // convert to standard Agent structure + var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); + var standardAgent = builder.StandardizeAgent(agent); + builder.SaveAgent(standardAgent); + + agent.Id = standardAgent.Id; + + return agent; + } + + [HttpGet] + public List GetAgent() + { + /*var agents = new List(); + + string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); + + var agentPaths = Directory.GetFiles(dataDir).Where(x => Regex.IsMatch(x, @"agent-\d+.json")).ToList(); + for (int i = 0; i< agentPaths.Count; i++) + { + string json = System.IO.File.ReadAllText(agentPaths[i]); + + var agent = JsonConvert.DeserializeObject(json); + + agents.Add(agent); + }*/ + + var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); + + var results = builder.GetAllAgents(); + var agents = results.Select(x => builder.RecoverAgent(x)).ToList(); + + return agents; + } + + [HttpGet("{agentId}")] + public AgentModel GetAgentById([FromRoute] string agentId) + { + var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); + var standardAgent = builder.GetAgentById(agentId); + var agent = builder.RecoverAgent(standardAgent); + + return agent; + } + + [HttpGet("name/{agentName}")] + public AgentModel GetAgentByName([FromRoute] string agentName) + { + AgentModel agent = null; + + string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); + + var agentPaths = Directory.GetFiles(dataDir).Where(x => Regex.IsMatch(x, @"agent-\d+\.json")).ToList(); + + for (int i = 0; i < agentPaths.Count; i++) + { + string json = System.IO.File.ReadAllText(agentPaths[i]); + + var agentTmp = JsonConvert.DeserializeObject(json); + + if(agentTmp.AgentName == agentName) + { + agent = agentTmp; + } + } + + return agent; + } + } +#endif +} diff --git a/BotSharp.RestApi/Articulate/DomainController.cs b/Platform.Articulate/Controllers/DomainController.cs similarity index 70% rename from BotSharp.RestApi/Articulate/DomainController.cs rename to Platform.Articulate/Controllers/DomainController.cs index 58619bf6..465d752d 100644 --- a/BotSharp.RestApi/Articulate/DomainController.cs +++ b/Platform.Articulate/Controllers/DomainController.cs @@ -1,7 +1,9 @@ -using BotSharp.Core.Engines.Articulate; +using BotSharp.Core; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Platform.Articulate.Models; +using Platform.Articulate.ViewModels; using System; using System.Collections.Generic; using System.IO; @@ -9,7 +11,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.Controllers { #if ARTICULATE [Route("[controller]")] @@ -29,8 +31,22 @@ namespace BotSharp.RestApi.Articulate } [HttpPost] - public void PostModel([FromBody] DomainModel domain) + public DomainModel PostDomain() { + DomainModel domain = null; + + using (var reader = new StreamReader(Request.Body)) + { + string body = reader.ReadToEnd(); + domain = JsonConvert.DeserializeObject(body); + } + + var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); + var agent = builder.GetAgentByName(domain.Agent); + agent.ExtraData = domain; + builder.SaveAgent(agent); + + return domain; } [HttpGet("/agent/{agentId}/domain")] diff --git a/BotSharp.RestApi/Articulate/EntityController.cs b/Platform.Articulate/Controllers/EntityController.cs similarity index 60% rename from BotSharp.RestApi/Articulate/EntityController.cs rename to Platform.Articulate/Controllers/EntityController.cs index 9b4943c4..36037a2d 100644 --- a/BotSharp.RestApi/Articulate/EntityController.cs +++ b/Platform.Articulate/Controllers/EntityController.cs @@ -1,13 +1,15 @@ -using BotSharp.Core.Engines.Articulate; +using BotSharp.Core; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using Platform.Articulate.Models; +using Platform.Articulate.ViewModels; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.Controllers { #if ARTICULATE [Route("[controller]")] @@ -32,19 +34,28 @@ namespace BotSharp.RestApi.Articulate { var entities = new List(); - string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); + return new EntityPageViewModel { Entities = entities, Total = entities.Count }; + } - var agentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-entity-")).ToList(); - for (int i = 0; i < agentPaths.Count; i++) + [HttpPost] + public EntityModel PostEntity() + { + EntityModel entity = null; + + using (var reader = new StreamReader(Request.Body)) { - string json = System.IO.File.ReadAllText(agentPaths[i]); - - var entity = JsonConvert.DeserializeObject(json); - - entities.Add(entity); + string body = reader.ReadToEnd(); + entity = JsonConvert.DeserializeObject(body); } - return new EntityPageViewModel { Entities = entities, Total = entities.Count }; + var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); + var agent = builder.GetAgentByName(entity.Agent); + + agent.Entities.Add(entity); + + builder.SaveAgent(agent); + + return entity; } } #endif diff --git a/BotSharp.RestApi/Articulate/IntentController.cs b/Platform.Articulate/Controllers/IntentController.cs similarity index 97% rename from BotSharp.RestApi/Articulate/IntentController.cs rename to Platform.Articulate/Controllers/IntentController.cs index f0babcb9..4dc878f8 100644 --- a/BotSharp.RestApi/Articulate/IntentController.cs +++ b/Platform.Articulate/Controllers/IntentController.cs @@ -1,13 +1,14 @@ -using BotSharp.Core.Engines.Articulate; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using Platform.Articulate.Models; +using Platform.Articulate.ViewModels; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.Controllers { #if ARTICULATE [Route("[controller]")] diff --git a/Platform.Articulate/Controllers/SettingsController.cs b/Platform.Articulate/Controllers/SettingsController.cs new file mode 100644 index 00000000..6608ffe0 --- /dev/null +++ b/Platform.Articulate/Controllers/SettingsController.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Platform.Articulate.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Platform.Articulate.Controllers +{ +#if ARTICULATE + [Route("[controller]")] + public class SettingsController : ControllerBase + { + [HttpGet] + public SettingsModel GetSettings() + { + string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json"); + + string json = System.IO.File.ReadAllText(dataPath); + + var settings = JsonConvert.DeserializeObject(json); + + return settings; + } + + [HttpGet("/agent/{agentId}/settings")] + public SettingsModel GetSettingsByAgent([FromRoute] string agentId) + { + string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json"); + + string json = System.IO.File.ReadAllText(dataPath); + + var settings = JsonConvert.DeserializeObject(json); + + return settings; + } + + [HttpPut("/agent/{agentId}/settings")] + public SettingsModel PutSettingsByAgent([FromRoute] string agentId) + { + string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json"); + + string json = System.IO.File.ReadAllText(dataPath); + + var settings = JsonConvert.DeserializeObject(json); + + return settings; + } + } +#endif +} diff --git a/BotSharp.Core/Engines/Articulate/AgentModel.cs b/Platform.Articulate/Models/AgentModel.cs similarity index 89% rename from BotSharp.Core/Engines/Articulate/AgentModel.cs rename to Platform.Articulate/Models/AgentModel.cs index 2fe437c3..a05163f0 100644 --- a/BotSharp.Core/Engines/Articulate/AgentModel.cs +++ b/Platform.Articulate/Models/AgentModel.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class AgentModel { - public int Id { get; set; } + public string Id { get; set; } public string Status { get; set; } diff --git a/BotSharp.Core/Engines/Articulate/DomainModel.cs b/Platform.Articulate/Models/DomainModel.cs similarity index 91% rename from BotSharp.Core/Engines/Articulate/DomainModel.cs rename to Platform.Articulate/Models/DomainModel.cs index aa183c02..ec2206ea 100644 --- a/BotSharp.Core/Engines/Articulate/DomainModel.cs +++ b/Platform.Articulate/Models/DomainModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class DomainModel { diff --git a/BotSharp.Core/Engines/Articulate/EntityModel.cs b/Platform.Articulate/Models/EntityModel.cs similarity index 91% rename from BotSharp.Core/Engines/Articulate/EntityModel.cs rename to Platform.Articulate/Models/EntityModel.cs index 976c2a68..24f86360 100644 --- a/BotSharp.Core/Engines/Articulate/EntityModel.cs +++ b/Platform.Articulate/Models/EntityModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class EntityModel { diff --git a/BotSharp.Core/Engines/Articulate/EntitySynonymModel.cs b/Platform.Articulate/Models/EntitySynonymModel.cs similarity index 83% rename from BotSharp.Core/Engines/Articulate/EntitySynonymModel.cs rename to Platform.Articulate/Models/EntitySynonymModel.cs index 3cd7fa4a..cc3f0b62 100644 --- a/BotSharp.Core/Engines/Articulate/EntitySynonymModel.cs +++ b/Platform.Articulate/Models/EntitySynonymModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class EntitySynonymModel { diff --git a/BotSharp.Core/Engines/Articulate/IntentExampleModel.cs b/Platform.Articulate/Models/IntentExampleModel.cs similarity index 81% rename from BotSharp.Core/Engines/Articulate/IntentExampleModel.cs rename to Platform.Articulate/Models/IntentExampleModel.cs index 94e86bf8..ff211417 100644 --- a/BotSharp.Core/Engines/Articulate/IntentExampleModel.cs +++ b/Platform.Articulate/Models/IntentExampleModel.cs @@ -1,8 +1,9 @@ -using System; +using BotSharp.Core.Engines; +using System; using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class IntentExampleModel { diff --git a/BotSharp.Core/Engines/Articulate/IntentModel.cs b/Platform.Articulate/Models/IntentModel.cs similarity index 91% rename from BotSharp.Core/Engines/Articulate/IntentModel.cs rename to Platform.Articulate/Models/IntentModel.cs index a5da0fcf..7688afc3 100644 --- a/BotSharp.Core/Engines/Articulate/IntentModel.cs +++ b/Platform.Articulate/Models/IntentModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class IntentModel { diff --git a/BotSharp.Core/Engines/Articulate/IntentScenarioModel.cs b/Platform.Articulate/Models/IntentScenarioModel.cs similarity index 91% rename from BotSharp.Core/Engines/Articulate/IntentScenarioModel.cs rename to Platform.Articulate/Models/IntentScenarioModel.cs index 38ffb66c..20a692a3 100644 --- a/BotSharp.Core/Engines/Articulate/IntentScenarioModel.cs +++ b/Platform.Articulate/Models/IntentScenarioModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class IntentScenarioModel { diff --git a/BotSharp.Core/Engines/Articulate/LanguageModel.cs b/Platform.Articulate/Models/LanguageModel.cs similarity index 82% rename from BotSharp.Core/Engines/Articulate/LanguageModel.cs rename to Platform.Articulate/Models/LanguageModel.cs index d4df3f6f..1e799e6f 100644 --- a/BotSharp.Core/Engines/Articulate/LanguageModel.cs +++ b/Platform.Articulate/Models/LanguageModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class LanguageModel { diff --git a/BotSharp.Core/Engines/Articulate/PipelineModel.cs b/Platform.Articulate/Models/PipelineModel.cs similarity index 78% rename from BotSharp.Core/Engines/Articulate/PipelineModel.cs rename to Platform.Articulate/Models/PipelineModel.cs index d9445380..0078ef55 100644 --- a/BotSharp.Core/Engines/Articulate/PipelineModel.cs +++ b/Platform.Articulate/Models/PipelineModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class PipelineModel { diff --git a/BotSharp.Core/Engines/Articulate/SettingsModel.cs b/Platform.Articulate/Models/SettingsModel.cs similarity index 95% rename from BotSharp.Core/Engines/Articulate/SettingsModel.cs rename to Platform.Articulate/Models/SettingsModel.cs index aec28999..e9a9911a 100644 --- a/BotSharp.Core/Engines/Articulate/SettingsModel.cs +++ b/Platform.Articulate/Models/SettingsModel.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class SettingsModel { diff --git a/BotSharp.Core/Engines/Articulate/SlotModel.cs b/Platform.Articulate/Models/SlotModel.cs similarity index 88% rename from BotSharp.Core/Engines/Articulate/SlotModel.cs rename to Platform.Articulate/Models/SlotModel.cs index d47a69da..098b5e54 100644 --- a/BotSharp.Core/Engines/Articulate/SlotModel.cs +++ b/Platform.Articulate/Models/SlotModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Core.Engines.Articulate +namespace Platform.Articulate.Models { public class SlotModel { diff --git a/Platform.Articulate/Platform.Articulate.csproj b/Platform.Articulate/Platform.Articulate.csproj new file mode 100644 index 00000000..411a0c54 --- /dev/null +++ b/Platform.Articulate/Platform.Articulate.csproj @@ -0,0 +1,20 @@ + + + + netstandard2.0 + + + + TRACE;DEBUG;ARTICULATE + + + + + + + + + + + + diff --git a/BotSharp.RestApi/Articulate/DomainPageViewModel.cs b/Platform.Articulate/ViewModels/DomainPageViewModel.cs similarity index 72% rename from BotSharp.RestApi/Articulate/DomainPageViewModel.cs rename to Platform.Articulate/ViewModels/DomainPageViewModel.cs index b4e5e8ed..d5f51636 100644 --- a/BotSharp.RestApi/Articulate/DomainPageViewModel.cs +++ b/Platform.Articulate/ViewModels/DomainPageViewModel.cs @@ -1,9 +1,9 @@ -using BotSharp.Core.Engines.Articulate; +using Platform.Articulate.Models; using System; using System.Collections.Generic; using System.Text; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.ViewModels { public class DomainPageViewModel { diff --git a/BotSharp.RestApi/Articulate/EntityPageViewModel.cs b/Platform.Articulate/ViewModels/EntityPageViewModel.cs similarity index 72% rename from BotSharp.RestApi/Articulate/EntityPageViewModel.cs rename to Platform.Articulate/ViewModels/EntityPageViewModel.cs index a8bb908b..09d75a8c 100644 --- a/BotSharp.RestApi/Articulate/EntityPageViewModel.cs +++ b/Platform.Articulate/ViewModels/EntityPageViewModel.cs @@ -1,9 +1,9 @@ -using BotSharp.Core.Engines.Articulate; +using Platform.Articulate.Models; using System; using System.Collections.Generic; using System.Text; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.ViewModels { public class EntityPageViewModel { diff --git a/BotSharp.RestApi/Articulate/IntentPageViewModel.cs b/Platform.Articulate/ViewModels/IntentPageViewModel.cs similarity index 72% rename from BotSharp.RestApi/Articulate/IntentPageViewModel.cs rename to Platform.Articulate/ViewModels/IntentPageViewModel.cs index 6bb18e9a..28704e6c 100644 --- a/BotSharp.RestApi/Articulate/IntentPageViewModel.cs +++ b/Platform.Articulate/ViewModels/IntentPageViewModel.cs @@ -1,9 +1,9 @@ -using BotSharp.Core.Engines.Articulate; +using Platform.Articulate.Models; using System; using System.Collections.Generic; using System.Text; -namespace BotSharp.RestApi.Articulate +namespace Platform.Articulate.ViewModels { public class IntentPageViewModel { diff --git a/Platform.Botpress/Platform.Botpress.csproj b/Platform.Botpress/Platform.Botpress.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/Platform.Botpress/Platform.Botpress.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/Platform.Dialogflow/Platform.Dialogflow.csproj b/Platform.Dialogflow/Platform.Dialogflow.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/Platform.Dialogflow/Platform.Dialogflow.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/Platform.RasaTalk/Platform.RasaTalk.csproj b/Platform.RasaTalk/Platform.RasaTalk.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/Platform.RasaTalk/Platform.RasaTalk.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/Platform.RasaUI/Platform.RasaUI.csproj b/Platform.RasaUI/Platform.RasaUI.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/Platform.RasaUI/Platform.RasaUI.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + +