convert payload to JObject

This commit is contained in:
Oceania2018 2018-05-23 00:11:15 -05:00
parent 083f2640ad
commit 4485d65b7d
6 changed files with 27 additions and 7 deletions

View file

@ -18,6 +18,7 @@ namespace BotSharp.Core.Agents
CreatedDate = DateTime.UtcNow;
}
[Required]
[MaxLength(64)]
public String Name { get; set; }
@ -26,6 +27,7 @@ namespace BotSharp.Core.Agents
public Boolean Published { get; set; }
[Required]
[MaxLength(5)]
public String Language { get; set; }

View file

@ -15,6 +15,18 @@ namespace BotSharp.Core.Agents
{
public static class AgentDriver
{
public static Agent LoadAgentById(this IBotEngine engine, Database dc, string agentId)
{
var clientAccessToken = dc.Table<Agent>().Find(agentId).ClientAccessToken;
var config = new AIConfiguration(clientAccessToken, SupportedLanguage.English);
var rasa = new RasaAi(dc, config);
rasa.agent = rasa.LoadAgent(dc, config);
return rasa.agent;
}
public static Agent LoadAgent(this IBotEngine engine, Database dc, AIConfiguration aiConfig)
{
return dc.Table<Agent>()

View file

@ -56,7 +56,8 @@ namespace BotSharp.Core.Engines
}).ToList());
}
agent.Entities.Add(entity.ToObject<EntityType>());
var entityType = entity.ToObject<EntityType>();
agent.Entities.Add(entityType);
}
});
}
@ -107,7 +108,7 @@ namespace BotSharp.Core.Engines
return new IntentResponseMessage
{
Lang = x.Lang,
Payload = JsonConvert.SerializeObject(x.Payload),
Payload = JObject.FromObject(x.Payload),
Type = x.Type
};
} else

View file

@ -60,7 +60,7 @@ namespace BotSharp.Core.Engines
return (new
{
x.Type,
Payload = JObject.Parse(x.Payload)
x.Payload
}) as Object;
}
else
@ -384,7 +384,7 @@ namespace BotSharp.Core.Engines
return (new
{
x.Type,
Payload = JObject.Parse(x.Payload)
x.Payload
}) as Object;
}
else

View file

@ -7,9 +7,9 @@ using System.Text;
namespace BotSharp.Core.Intents
{
public static class IntentExtension
public static class IntentDriver
{
public static string CreateIntent(this Agent agent, Database dc, Intent intent)
public static String CreateIntent(this Agent agent, Database dc, Intent intent)
{
if (dc.Table<Intent>().Any(x => x.Id == intent.Id)) return intent.Id;

View file

@ -1,5 +1,7 @@
using BotSharp.Core.Models;
using EntityFrameworkCore.BootKit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -31,6 +33,9 @@ namespace BotSharp.Core.Intents
/// custom json payload
/// </summary>
[MaxLength(1024)]
public String Payload { get; set; }
public String PayloadJson { get; set; }
[NotMapped]
public JObject Payload { get; set; }
}
}