diff --git a/BotSharp.Platform.Models/IntentBase.cs b/BotSharp.Platform.Models/IntentBase.cs index 0e66822e..5e0ee6ca 100644 --- a/BotSharp.Platform.Models/IntentBase.cs +++ b/BotSharp.Platform.Models/IntentBase.cs @@ -12,12 +12,5 @@ namespace BotSharp.Platform.Models /// [StringLength(36)] public String Id { get; set; } - - /// - /// Name of chatbot - /// - [Required] - [MaxLength(64)] - public String Name { get; set; } } } diff --git a/Platform.Articulate/Controllers/AgentController.cs b/Platform.Articulate/Controllers/AgentController.cs index 0d22ca22..d6f90380 100644 --- a/Platform.Articulate/Controllers/AgentController.cs +++ b/Platform.Articulate/Controllers/AgentController.cs @@ -73,23 +73,7 @@ namespace Platform.Articulate.Controllers [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.Name == agentName) - { - agent = agentTmp; - } - } + var agent = builder.GetAgentByName(agentName); return agent; } diff --git a/Platform.Articulate/Controllers/IntentController.cs b/Platform.Articulate/Controllers/IntentController.cs index d667441a..d66e190d 100644 --- a/Platform.Articulate/Controllers/IntentController.cs +++ b/Platform.Articulate/Controllers/IntentController.cs @@ -1,5 +1,6 @@ using BotSharp.Core; using BotSharp.Platform.Models; +using DotNetToolkit; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Platform.Articulate.Models; @@ -24,27 +25,27 @@ namespace Platform.Articulate.Controllers } [HttpGet("{intentId}")] - public IntentModel GetIntent([FromRoute] string intentId) + public IntentViewModel GetIntent([FromRoute] string intentId) { var agent = builder.GetAgentByIntentId(intentId); - return agent.Item3; + return agent.Item3.ToObject(); } [HttpPost] - public IntentModel PostIntent() + public IntentViewModel PostIntent() { - IntentModel intent = null; + IntentViewModel intent = null; using (var reader = new StreamReader(Request.Body)) { string body = reader.ReadToEnd(); - intent = JsonConvert.DeserializeObject(body); + intent = JsonConvert.DeserializeObject(body); } var agent = builder.GetAgentByName(intent.Agent); intent.Id = Guid.NewGuid().ToString(); - agent.Domains[0].Intents.Add(intent); + agent.Domains[0].Intents.Add(intent.ToObject()); builder.SaveAgent(agent); return intent; @@ -65,7 +66,7 @@ namespace Platform.Articulate.Controllers [HttpGet("/agent/{agentId}/intent")] public IntentPageViewModel GetAgentIntents([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit) { - var intents = new List(); + var intents = new List(); string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate"); @@ -74,7 +75,7 @@ namespace Platform.Articulate.Controllers { string json = System.IO.File.ReadAllText(agentPaths[i]); - var intent = JsonConvert.DeserializeObject(json); + var intent = JsonConvert.DeserializeObject(json); intents.Add(intent); } @@ -118,7 +119,7 @@ namespace Platform.Articulate.Controllers public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit) { var agent = builder.GetAgentByDomainId(domainId); - var intents = agent.Item2.Intents.Select(x => x as IntentModel).ToList(); + var intents = agent.Item2.Intents.Select(x => x.ToObject()).ToList(); return new IntentPageViewModel { Intents = intents, Total = intents.Count }; } diff --git a/Platform.Articulate/Models/IntentExampleModel.cs b/Platform.Articulate/Models/IntentExampleModel.cs index 98a942f0..825d9eaa 100644 --- a/Platform.Articulate/Models/IntentExampleModel.cs +++ b/Platform.Articulate/Models/IntentExampleModel.cs @@ -7,7 +7,7 @@ namespace Platform.Articulate.Models { public class IntentExampleModel { - public string userSays { get; set; } + public string UserSays { get; set; } public List Entities { get; set; } } diff --git a/Platform.Articulate/ViewModels/IntentPageViewModel.cs b/Platform.Articulate/ViewModels/IntentPageViewModel.cs index 28704e6c..f78a4e25 100644 --- a/Platform.Articulate/ViewModels/IntentPageViewModel.cs +++ b/Platform.Articulate/ViewModels/IntentPageViewModel.cs @@ -7,7 +7,7 @@ namespace Platform.Articulate.ViewModels { public class IntentPageViewModel { - public List Intents { get; set; } + public List Intents { get; set; } public int Total { get; set; } } diff --git a/Platform.Articulate/ViewModels/IntentViewModel.cs b/Platform.Articulate/ViewModels/IntentViewModel.cs new file mode 100644 index 00000000..dee25d43 --- /dev/null +++ b/Platform.Articulate/ViewModels/IntentViewModel.cs @@ -0,0 +1,23 @@ +using BotSharp.Platform.Models; +using Platform.Articulate.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Platform.Articulate.ViewModels +{ + public class IntentViewModel : IntentBase + { + public string IntentName { get; set; } + + public string Agent { get; set; } + + public string Domain { get; set; } + + public bool UsePostFormat { get; set; } + + public bool UseWebhook { get; set; } + + public List Examples { get; set; } + } +}