From a06745ffb023262f553ea98986c8a89b2856b0ec Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 29 Sep 2018 13:18:34 -0500 Subject: [PATCH] refactor articulate platform --- BotSharp.Core/AgentStorageInMemory.cs | 14 ++-- BotSharp.Core/PlatformBuilderBase.cs | 12 ++-- .../IAgentStorage.cs | 10 +-- .../IPlatformBuilder.cs | 12 ++-- BotSharp.Platform.Models/AgentBase.cs | 36 ++++++++++ BotSharp.Platform.Models/EntityBase.cs | 10 +++ BotSharp.Platform.Models/IntentBase.cs | 23 ++++++ .../IntentResponseBase.cs | 16 +++++ BotSharp.Platform.Models/StandardAgent.cs | 40 ++--------- BotSharp.WebHost/Startup.cs | 2 + Platform.Articulate/ArticulateAi.cs | 18 ++--- .../Controllers/AgentController.cs | 35 +++------ .../Controllers/DomainController.cs | 31 ++++---- .../Controllers/EntityController.cs | 13 +++- .../Controllers/IntentController.cs | 71 ++++++++++--------- Platform.Articulate/Models/AgentModel.cs | 20 ++++-- Platform.Articulate/Models/DomainModel.cs | 7 +- Platform.Articulate/Models/EntityModel.cs | 6 +- .../Models/IntentExampleModel.cs | 2 +- Platform.Articulate/Models/IntentModel.cs | 13 ++-- .../IntentScenarioViewModel.cs} | 4 +- 21 files changed, 228 insertions(+), 167 deletions(-) create mode 100644 BotSharp.Platform.Models/AgentBase.cs create mode 100644 BotSharp.Platform.Models/EntityBase.cs create mode 100644 BotSharp.Platform.Models/IntentBase.cs create mode 100644 BotSharp.Platform.Models/IntentResponseBase.cs rename Platform.Articulate/{Models/IntentScenarioModel.cs => ViewModels/IntentScenarioViewModel.cs} (84%) diff --git a/BotSharp.Core/AgentStorageInMemory.cs b/BotSharp.Core/AgentStorageInMemory.cs index 12658806..a25b3d46 100644 --- a/BotSharp.Core/AgentStorageInMemory.cs +++ b/BotSharp.Core/AgentStorageInMemory.cs @@ -11,16 +11,16 @@ namespace BotSharp.Core /// Save agent instance into memory. /// Caution: Data will be lost once application restarts. /// - public class AgentStorageInMemory : IAgentStorage + public class AgentStorageInMemory : IAgentStorage where TAgent : AgentBase { - private static Dictionary> agents; + private static Dictionary agents; public AgentStorageInMemory() { - if (agents == null) agents = new Dictionary>(); + if (agents == null) agents = new Dictionary(); } - public StandardAgent FetchById(string agentId) + public TAgent FetchById(string agentId) { if (agents.ContainsKey(agentId)) { @@ -32,14 +32,14 @@ namespace BotSharp.Core } } - public StandardAgent FetchByName(string agentName) + public TAgent FetchByName(string agentName) { var data = agents.FirstOrDefault(x => x.Value.Name == agentName); return data.Value; } - public bool Persist(StandardAgent agent) + public bool Persist(TAgent agent) { if (String.IsNullOrEmpty(agent.Id)) { @@ -54,7 +54,7 @@ namespace BotSharp.Core return true; } - public List> Query() + public List Query() { return agents.Select(x => x.Value).ToList(); } diff --git a/BotSharp.Core/PlatformBuilderBase.cs b/BotSharp.Core/PlatformBuilderBase.cs index 4b5777fe..db2e842e 100644 --- a/BotSharp.Core/PlatformBuilderBase.cs +++ b/BotSharp.Core/PlatformBuilderBase.cs @@ -6,8 +6,8 @@ using System.Text; namespace BotSharp.Core { - public abstract class PlatformBuilderBase - where TStorage : IAgentStorage, new () + public abstract class PlatformBuilderBase + where TStorage : IAgentStorage, new () { protected static TStorage storage; @@ -16,23 +16,23 @@ namespace BotSharp.Core if (storage == null) storage = new TStorage(); } - public List> GetAllAgents() + public List GetAllAgents() { return storage.Query(); } - public StandardAgent GetAgentById(string agentId) + public TAgent GetAgentById(string agentId) { return storage.FetchById(agentId); } - public StandardAgent GetAgentByName(string agentName) + public TAgent GetAgentByName(string agentName) { return storage.FetchByName(agentName); } - public virtual bool SaveAgent(StandardAgent agent) + public virtual bool SaveAgent(TAgent agent) { // default save agent in FileStorage storage.Persist(agent); diff --git a/BotSharp.Platform.Abstraction/IAgentStorage.cs b/BotSharp.Platform.Abstraction/IAgentStorage.cs index fc169877..4cdaa18d 100644 --- a/BotSharp.Platform.Abstraction/IAgentStorage.cs +++ b/BotSharp.Platform.Abstraction/IAgentStorage.cs @@ -9,33 +9,33 @@ 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 + public interface IAgentStorage { /// /// Save agent instance /// /// /// - bool Persist(StandardAgent agent); + bool Persist(TAgent agent); /// /// Get agent by id /// /// /// - StandardAgent FetchById(string agentId); + TAgent FetchById(string agentId); /// /// Get agent by name /// /// /// - StandardAgent FetchByName(string agentName); + TAgent FetchByName(string agentName); /// /// Query agents /// /// - List> Query(); + List Query(); } } diff --git a/BotSharp.Platform.Abstraction/IPlatformBuilder.cs b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs index fe2d11b2..b00e91ce 100644 --- a/BotSharp.Platform.Abstraction/IPlatformBuilder.cs +++ b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs @@ -10,8 +10,8 @@ namespace BotSharp.Platform.Abstraction /// Platform abstraction /// Implement this interface to build a Chatbot platform /// - public interface IPlatformBuilder - where TStorage : IAgentStorage, new() + public interface IPlatformBuilder + where TStorage : IAgentStorage, new() { /// /// Parse options for the incoming text or voice request from the sender. @@ -23,14 +23,14 @@ namespace BotSharp.Platform.Abstraction /// /// /// - StandardAgent StandardizeAgent(TAgent agent); + StandardAgent StandardizeAgent(TAgent agent); /// /// Recover standard agent to specific agent format /// /// /// - TAgent RecoverAgent(StandardAgent agent); + TAgent RecoverAgent(StandardAgent agent); /// /// @@ -38,8 +38,6 @@ namespace BotSharp.Platform.Abstraction /// /// /// - bool SaveAgent(StandardAgent agent); - - StandardAgent GetAgentById(string agentId); + bool SaveAgent(TAgent agent); } } diff --git a/BotSharp.Platform.Models/AgentBase.cs b/BotSharp.Platform.Models/AgentBase.cs new file mode 100644 index 00000000..cbff5be6 --- /dev/null +++ b/BotSharp.Platform.Models/AgentBase.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace BotSharp.Platform.Models +{ + public abstract class AgentBase + { + /// + /// Guid + /// + [StringLength(36)] + public String Id { get; set; } + + /// + /// Name of chatbot + /// + [Required] + [MaxLength(64)] + public virtual String Name { get; set; } + + /// + /// Description of chatbot + /// + [MaxLength(256)] + public String Description { get; set; } + + /// + /// + /// + [Required] + [MaxLength(5)] + public String Language { get; set; } + } +} diff --git a/BotSharp.Platform.Models/EntityBase.cs b/BotSharp.Platform.Models/EntityBase.cs new file mode 100644 index 00000000..42971aa5 --- /dev/null +++ b/BotSharp.Platform.Models/EntityBase.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Platform.Models +{ + public abstract class EntityBase + { + } +} diff --git a/BotSharp.Platform.Models/IntentBase.cs b/BotSharp.Platform.Models/IntentBase.cs new file mode 100644 index 00000000..0e66822e --- /dev/null +++ b/BotSharp.Platform.Models/IntentBase.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace BotSharp.Platform.Models +{ + public abstract class IntentBase + { + /// + /// Guid + /// + [StringLength(36)] + public String Id { get; set; } + + /// + /// Name of chatbot + /// + [Required] + [MaxLength(64)] + public String Name { get; set; } + } +} diff --git a/BotSharp.Platform.Models/IntentResponseBase.cs b/BotSharp.Platform.Models/IntentResponseBase.cs new file mode 100644 index 00000000..9728d944 --- /dev/null +++ b/BotSharp.Platform.Models/IntentResponseBase.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace BotSharp.Platform.Models +{ + public abstract class IntentResponseBase + { + /// + /// Guid + /// + [StringLength(36)] + public String Id { get; set; } + } +} diff --git a/BotSharp.Platform.Models/StandardAgent.cs b/BotSharp.Platform.Models/StandardAgent.cs index 22ef28f0..5eceab1a 100644 --- a/BotSharp.Platform.Models/StandardAgent.cs +++ b/BotSharp.Platform.Models/StandardAgent.cs @@ -10,45 +10,20 @@ namespace BotSharp.Platform.Models /// Standard agent data structure /// All other platform agent has to align with this standard data structure. /// - public class StandardAgent + public class StandardAgent : AgentBase { public StandardAgent() { CreatedDate = DateTime.UtcNow; - Entities = new List(); + Entities = new List(); + Intents = 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 /// @@ -61,9 +36,9 @@ namespace BotSharp.Platform.Models [StringLength(32)] public String DeveloperAccessToken { get; set; } - //public List Intents { get; set; } + public List Intents { get; set; } - public List Entities { get; set; } + public List Entities { get; set; } public String Birthday { @@ -74,10 +49,5 @@ namespace BotSharp.Platform.Models } public DateTime CreatedDate { get; set; } - - /// - /// Save extra information for specific platform - /// - public TExtraData ExtraData { get; set; } } } diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index 91cb9792..9696c2a2 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -107,6 +107,8 @@ namespace BotSharp.WebHost c.RoutePrefix = String.Empty; c.DocumentTitle = info.Title; c.InjectStylesheet(Configuration.GetValue("Swagger:Stylesheet")); + + Console.WriteLine($"Current Mode: {info.Title}"); }); app.Use(async (context, next) => diff --git a/Platform.Articulate/ArticulateAi.cs b/Platform.Articulate/ArticulateAi.cs index 204571b7..dafd8eb3 100644 --- a/Platform.Articulate/ArticulateAi.cs +++ b/Platform.Articulate/ArticulateAi.cs @@ -13,21 +13,21 @@ namespace Platform.Articulate /// 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 class ArticulateAi : + PlatformBuilderBase, + IPlatformBuilder + where TStorage : IAgentStorage, new() { public DialogRequestOptions RequestOptions { get; set; } - public TAgent RecoverAgent(StandardAgent agent) + public TAgent RecoverAgent(StandardAgent agent) { if (agent == null) return default(TAgent); var agent1 = new AgentModel { Id = agent.Id, - AgentName = agent.Name, + Name = agent.Name, Description = agent.Description, Language = agent.Language }; @@ -35,13 +35,13 @@ namespace Platform.Articulate return (TAgent)(agent1 as Object); } - public StandardAgent StandardizeAgent(TAgent specificAgent) + public StandardAgent StandardizeAgent(TAgent specificAgent) { var agent1 = specificAgent as AgentModel; - var standardAgent = new StandardAgent + var standardAgent = new StandardAgent { - Name = agent1.AgentName, + Name = agent1.Name, Language = agent1.Language, Description = agent1.Description }; diff --git a/Platform.Articulate/Controllers/AgentController.cs b/Platform.Articulate/Controllers/AgentController.cs index 84ae4ecb..0d22ca22 100644 --- a/Platform.Articulate/Controllers/AgentController.cs +++ b/Platform.Articulate/Controllers/AgentController.cs @@ -21,6 +21,7 @@ namespace Platform.Articulate.Controllers public class AgentController : ControllerBase { private readonly IBotPlatform _platform; + private ArticulateAi, AgentModel> builder; /// /// Initialize agent controller and get a platform instance @@ -29,6 +30,7 @@ namespace Platform.Articulate.Controllers public AgentController(IBotPlatform platform) { _platform = platform; + builder = new ArticulateAi, AgentModel>(); } [HttpPost] @@ -43,11 +45,10 @@ namespace Platform.Articulate.Controllers } // convert to standard Agent structure - var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); - var standardAgent = builder.StandardizeAgent(agent); - builder.SaveAgent(standardAgent); - - agent.Id = standardAgent.Id; + var builder = new ArticulateAi, AgentModel>(); + agent.Id = Guid.NewGuid().ToString(); + agent.Name = agent.AgentName; + builder.SaveAgent(agent); return agent; } @@ -55,24 +56,8 @@ namespace Platform.Articulate.Controllers [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(); + var agents = results.Select(x => x as AgentModel).ToList(); return agents; } @@ -80,9 +65,7 @@ namespace Platform.Articulate.Controllers [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); + var agent = builder.GetAgentById(agentId); return agent; } @@ -102,7 +85,7 @@ namespace Platform.Articulate.Controllers var agentTmp = JsonConvert.DeserializeObject(json); - if(agentTmp.AgentName == agentName) + if(agentTmp.Name == agentName) { agent = agentTmp; } diff --git a/Platform.Articulate/Controllers/DomainController.cs b/Platform.Articulate/Controllers/DomainController.cs index 465d752d..97823996 100644 --- a/Platform.Articulate/Controllers/DomainController.cs +++ b/Platform.Articulate/Controllers/DomainController.cs @@ -1,4 +1,5 @@ using BotSharp.Core; +using BotSharp.Platform.Models; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -17,6 +18,13 @@ namespace Platform.Articulate.Controllers [Route("[controller]")] public class DomainController : ControllerBase { + private ArticulateAi, AgentModel> builder; + + public DomainController() + { + builder = new ArticulateAi, AgentModel>(); + } + [HttpGet("{domainId}")] public DomainModel GetDomain([FromRoute] int domainId) { @@ -41,32 +49,21 @@ namespace Platform.Articulate.Controllers domain = JsonConvert.DeserializeObject(body); } - var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); var agent = builder.GetAgentByName(domain.Agent); - agent.ExtraData = domain; + domain.Id = Guid.NewGuid().ToString(); + (agent as AgentModel).Domains.Add(domain); builder.SaveAgent(agent); return domain; } [HttpGet("/agent/{agentId}/domain")] - public DomainPageViewModel GetAgentDomains([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit) + public DomainPageViewModel GetAgentDomains([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit) { - var domains = new List(); + var agent = builder.GetAgentById(agentId); + - string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); - - var agentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-domain-")).ToList(); - for (int i = 0; i < agentPaths.Count; i++) - { - string json = System.IO.File.ReadAllText(agentPaths[i]); - - var domain = JsonConvert.DeserializeObject(json); - - domains.Add(domain); - } - - return new DomainPageViewModel { Domains = domains, Total = domains.Count }; + return new DomainPageViewModel { /*Domains = agent.d, Total = domains.Count*/ }; } } #endif diff --git a/Platform.Articulate/Controllers/EntityController.cs b/Platform.Articulate/Controllers/EntityController.cs index 36037a2d..42199ff3 100644 --- a/Platform.Articulate/Controllers/EntityController.cs +++ b/Platform.Articulate/Controllers/EntityController.cs @@ -1,4 +1,5 @@ using BotSharp.Core; +using BotSharp.Platform.Models; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Platform.Articulate.Models; @@ -15,8 +16,15 @@ namespace Platform.Articulate.Controllers [Route("[controller]")] public class EntityController : ControllerBase { + private ArticulateAi, AgentModel> builder; + + public EntityController() + { + builder = new ArticulateAi, AgentModel>(); + } + [HttpGet("{entityId}")] - public EntityModel GetEntity([FromRoute] int entityId) + public EntityModel GetEntity([FromRoute] string entityId) { string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); @@ -30,7 +38,7 @@ namespace Platform.Articulate.Controllers } [HttpGet("/agent/{agentId}/entity")] - public EntityPageViewModel GetAgentEntities([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit) + public EntityPageViewModel GetAgentEntities([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit) { var entities = new List(); @@ -48,7 +56,6 @@ namespace Platform.Articulate.Controllers entity = JsonConvert.DeserializeObject(body); } - var builder = new ArticulateAi, AgentModel, DomainModel, EntityModel>(); var agent = builder.GetAgentByName(entity.Agent); agent.Entities.Add(entity); diff --git a/Platform.Articulate/Controllers/IntentController.cs b/Platform.Articulate/Controllers/IntentController.cs index 4dc878f8..6b7b23e6 100644 --- a/Platform.Articulate/Controllers/IntentController.cs +++ b/Platform.Articulate/Controllers/IntentController.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNetCore.Mvc; +using BotSharp.Core; +using BotSharp.Platform.Models; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Platform.Articulate.Models; using Platform.Articulate.ViewModels; @@ -14,8 +16,15 @@ namespace Platform.Articulate.Controllers [Route("[controller]")] public class IntentController : ControllerBase { + private ArticulateAi, AgentModel> builder; + + public IntentController() + { + builder = new ArticulateAi, AgentModel>(); + } + [HttpGet("{intentId}")] - public IntentModel GetIntent([FromRoute] int intentId) + public IntentModel GetIntent([FromRoute] string intentId) { string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); @@ -28,8 +37,27 @@ namespace Platform.Articulate.Controllers return intent; } + [HttpPost] + public IntentModel PostIntent() + { + IntentModel intent = null; + + using (var reader = new StreamReader(Request.Body)) + { + string body = reader.ReadToEnd(); + intent = JsonConvert.DeserializeObject(body); + } + + var agent = builder.GetAgentByName(intent.Agent); + intent.Id = Guid.NewGuid().ToString(); + agent.Domains[0].Intents.Add(intent); + builder.SaveAgent(agent); + + return intent; + } + [HttpGet("{intentId}/scenario")] - public IntentScenarioModel GetIntentScenario([FromRoute] int intentId) + public IntentScenarioViewModel GetIntentScenario([FromRoute] string intentId) { string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); @@ -37,25 +65,25 @@ namespace Platform.Articulate.Controllers string json = System.IO.File.ReadAllText(dataPath); - var scenario = JsonConvert.DeserializeObject(json); + var scenario = JsonConvert.DeserializeObject(json); return scenario; } [HttpGet("{intentId}/webhook")] - public void GetIntentWebhook([FromRoute] int intentId) + public void GetIntentWebhook([FromRoute] string intentId) { } [HttpGet("{intentId}/postFormat")] - public void GetIntentPostFormat([FromRoute] int intentId) + public void GetIntentPostFormat([FromRoute] string intentId) { } [HttpGet("/agent/{agentId}/intent")] - public IntentPageViewModel GetAgentIntents([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit) + public IntentPageViewModel GetAgentIntents([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit) { var intents = new List(); @@ -75,7 +103,7 @@ namespace Platform.Articulate.Controllers } [HttpGet("/entity/{entityId}/intent")] - public List GetReferencedIntentsByEntity([FromRoute] int entityId, [FromQuery] int start, [FromQuery] int limit) + public List GetReferencedIntentsByEntity([FromRoute] string entityId, [FromQuery] int start, [FromQuery] int limit) { var intents = new List(); @@ -107,33 +135,12 @@ namespace Platform.Articulate.Controllers } [HttpGet("/domain/{domainId}/intent")] - public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] int domainId, [FromQuery] int start, [FromQuery] int limit) + public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit) { var intents = new List(); - string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); - - string domainPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.Contains($"-domain-{domainId}.json")); - var domain = JsonConvert.DeserializeObject(System.IO.File.ReadAllText(domainPath)); - - string agentId = domainPath.Split(Path.DirectorySeparatorChar).Last().Split('-')[1]; - - string agentPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.Contains($"agent-{agentId}.json")); - var agent = JsonConvert.DeserializeObject(System.IO.File.ReadAllText(agentPath)); - - var intentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-intent-")).ToList(); - - for (int i = 0; i < intentPaths.Count; i++) - { - string json = System.IO.File.ReadAllText(intentPaths[i]); - - var intent = JsonConvert.DeserializeObject(json); - - if (intent.Domain == domain.DomainName) - { - intents.Add(intent); - } - } + var results = builder.GetAllAgents(); + //var agents = results.Select(x => builder.RecoverAgent(x) as AgentModel).Where(x => x.).ToList(); return new IntentPageViewModel { Intents = intents, Total = intents.Count }; } diff --git a/Platform.Articulate/Models/AgentModel.cs b/Platform.Articulate/Models/AgentModel.cs index a05163f0..cc1e60fe 100644 --- a/Platform.Articulate/Models/AgentModel.cs +++ b/Platform.Articulate/Models/AgentModel.cs @@ -1,25 +1,27 @@ -using System; +using BotSharp.Platform.Models; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Text; namespace Platform.Articulate.Models { - public class AgentModel + public class AgentModel : AgentBase { - public string Id { get; set; } + public AgentModel() + { + Domains = new List(); + Entities = new List(); + } public string Status { get; set; } public string Timezone { get; set; } - public string Language { get; set; } - public string AgentName { get; set; } public bool UseWebhook { get; set; } - public string Description { get; set; } - public bool UsePostFormat { get; set; } public bool ExtraTrainingData { get; set; } @@ -29,5 +31,9 @@ namespace Platform.Articulate.Models public bool EnableModelsPerDomain { get; set; } public decimal DomainClassifierThreshold { get; set; } + + public List Domains { get; set; } + + public List Entities { get; set; } } } diff --git a/Platform.Articulate/Models/DomainModel.cs b/Platform.Articulate/Models/DomainModel.cs index ec2206ea..6f792468 100644 --- a/Platform.Articulate/Models/DomainModel.cs +++ b/Platform.Articulate/Models/DomainModel.cs @@ -1,4 +1,5 @@ -using System; +using BotSharp.Platform.Models; +using System; using System.Collections.Generic; using System.Text; @@ -6,7 +7,7 @@ namespace Platform.Articulate.Models { public class DomainModel { - public int Id { get; set; } + public string Id { get; set; } public string Agent { get; set; } @@ -19,5 +20,7 @@ namespace Platform.Articulate.Models public decimal IntentThreshold { get; set; } public string Status { get; set; } + + public List Intents { get; set; } } } diff --git a/Platform.Articulate/Models/EntityModel.cs b/Platform.Articulate/Models/EntityModel.cs index 24f86360..f0c5552d 100644 --- a/Platform.Articulate/Models/EntityModel.cs +++ b/Platform.Articulate/Models/EntityModel.cs @@ -1,10 +1,12 @@ -using System; +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using System; using System.Collections.Generic; using System.Text; namespace Platform.Articulate.Models { - public class EntityModel + public class EntityModel : EntityBase { public int Id { get; set; } diff --git a/Platform.Articulate/Models/IntentExampleModel.cs b/Platform.Articulate/Models/IntentExampleModel.cs index ff211417..98a942f0 100644 --- a/Platform.Articulate/Models/IntentExampleModel.cs +++ b/Platform.Articulate/Models/IntentExampleModel.cs @@ -14,6 +14,6 @@ namespace Platform.Articulate.Models public class ArticulateTrainingIntentExpressionPart : TrainingIntentExpressionPart { - public int EntityId { get; set; } + public string EntityId { get; set; } } } diff --git a/Platform.Articulate/Models/IntentModel.cs b/Platform.Articulate/Models/IntentModel.cs index 7688afc3..e02d7739 100644 --- a/Platform.Articulate/Models/IntentModel.cs +++ b/Platform.Articulate/Models/IntentModel.cs @@ -1,14 +1,15 @@ -using System; +using BotSharp.Platform.Models; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Text; namespace Platform.Articulate.Models { - public class IntentModel + public class IntentModel : IntentBase { - public int Id { get; set; } - - public string IntentName { get; set; } + [JsonProperty("IntentName")] + public new string Name { get; set; } public string Agent { get; set; } @@ -19,5 +20,7 @@ namespace Platform.Articulate.Models public bool UseWebhook { get; set; } public List Examples { get; set; } + + public IntentResponseBase Response { get; set; } } } diff --git a/Platform.Articulate/Models/IntentScenarioModel.cs b/Platform.Articulate/ViewModels/IntentScenarioViewModel.cs similarity index 84% rename from Platform.Articulate/Models/IntentScenarioModel.cs rename to Platform.Articulate/ViewModels/IntentScenarioViewModel.cs index 20a692a3..684856f9 100644 --- a/Platform.Articulate/Models/IntentScenarioModel.cs +++ b/Platform.Articulate/ViewModels/IntentScenarioViewModel.cs @@ -4,10 +4,8 @@ using System.Text; namespace Platform.Articulate.Models { - public class IntentScenarioModel + public class IntentScenarioViewModel { - public int Id { get; set; } - public string Domain { get; set; } public string Agent { get; set; }