fix intent edit for articulate.
This commit is contained in:
parent
5fc98cc327
commit
374a82f17b
|
|
@ -12,12 +12,5 @@ namespace BotSharp.Platform.Models
|
|||
/// </summary>
|
||||
[StringLength(36)]
|
||||
public String Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of chatbot
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public String Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<AgentModel>(json);
|
||||
|
||||
if(agentTmp.Name == agentName)
|
||||
{
|
||||
agent = agentTmp;
|
||||
}
|
||||
}
|
||||
var agent = builder.GetAgentByName(agentName);
|
||||
|
||||
return agent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IntentViewModel>();
|
||||
}
|
||||
|
||||
[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<IntentModel>(body);
|
||||
intent = JsonConvert.DeserializeObject<IntentViewModel>(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<IntentModel>());
|
||||
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<IntentModel>();
|
||||
var intents = new List<IntentViewModel>();
|
||||
|
||||
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<IntentModel>(json);
|
||||
var intent = JsonConvert.DeserializeObject<IntentViewModel>(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<IntentViewModel>()).ToList();
|
||||
|
||||
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Platform.Articulate.Models
|
|||
{
|
||||
public class IntentExampleModel
|
||||
{
|
||||
public string userSays { get; set; }
|
||||
public string UserSays { get; set; }
|
||||
|
||||
public List<ArticulateTrainingIntentExpressionPart> Entities { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Platform.Articulate.ViewModels
|
|||
{
|
||||
public class IntentPageViewModel
|
||||
{
|
||||
public List<IntentModel> Intents { get; set; }
|
||||
public List<IntentViewModel> Intents { get; set; }
|
||||
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
|
|
|||
23
Platform.Articulate/ViewModels/IntentViewModel.cs
Normal file
23
Platform.Articulate/ViewModels/IntentViewModel.cs
Normal file
|
|
@ -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<IntentExampleModel> Examples { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue