2018-09-28 22:25:55 +00:00
|
|
|
|
using BotSharp.Core;
|
|
|
|
|
|
using BotSharp.Core.Agents;
|
|
|
|
|
|
using BotSharp.Core.Engines;
|
|
|
|
|
|
using BotSharp.Platform.Abstraction;
|
|
|
|
|
|
using BotSharp.Platform.Models;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-10-01 17:15:17 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2018-09-28 22:25:55 +00:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2018-10-01 17:15:17 +00:00
|
|
|
|
private readonly IConfiguration configuration;
|
2018-09-28 22:25:55 +00:00
|
|
|
|
private readonly IBotPlatform _platform;
|
2018-10-01 17:15:17 +00:00
|
|
|
|
private ArticulateAi<AgentModel> builder;
|
2018-09-28 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initialize agent controller and get a platform instance
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="platform"></param>
|
2018-10-01 17:15:17 +00:00
|
|
|
|
public AgentController(IBotPlatform platform, IConfiguration configuration)
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
_platform = platform;
|
2018-10-01 17:15:17 +00:00
|
|
|
|
builder = new ArticulateAi<AgentModel>();
|
|
|
|
|
|
builder.PlatformConfig = configuration.GetSection("ArticulateAi");
|
2018-09-28 22:25:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public AgentModel PostAgent()
|
|
|
|
|
|
{
|
|
|
|
|
|
AgentModel agent = null;
|
|
|
|
|
|
|
|
|
|
|
|
using (var reader = new StreamReader(Request.Body))
|
|
|
|
|
|
{
|
|
|
|
|
|
string body = reader.ReadToEnd();
|
|
|
|
|
|
agent = JsonConvert.DeserializeObject<AgentModel>(body);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// convert to standard Agent structure
|
2018-10-02 02:49:01 +00:00
|
|
|
|
agent.Id = new Random().Next(Int32.MaxValue).ToString();
|
2018-09-29 18:18:34 +00:00
|
|
|
|
agent.Name = agent.AgentName;
|
|
|
|
|
|
builder.SaveAgent(agent);
|
2018-09-28 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
return agent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public List<AgentModel> GetAgent()
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = builder.GetAllAgents();
|
2018-10-01 13:36:39 +00:00
|
|
|
|
var agents = results.ToList();
|
2018-09-28 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
return agents;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{agentId}")]
|
|
|
|
|
|
public AgentModel GetAgentById([FromRoute] string agentId)
|
|
|
|
|
|
{
|
2018-09-29 18:18:34 +00:00
|
|
|
|
var agent = builder.GetAgentById(agentId);
|
2018-09-28 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
return agent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("name/{agentName}")]
|
|
|
|
|
|
public AgentModel GetAgentByName([FromRoute] string agentName)
|
|
|
|
|
|
{
|
2018-09-30 21:52:33 +00:00
|
|
|
|
var agent = builder.GetAgentByName(agentName);
|
2018-09-28 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
return agent;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|