From 4485d65b7d5a11ca869d6edeb5153be3a6c4e7a2 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Wed, 23 May 2018 00:11:15 -0500 Subject: [PATCH] convert payload to JObject --- BotSharp.Core/Agents/Agent.cs | 2 ++ BotSharp.Core/Agents/AgentDriver.cs | 12 ++++++++++++ BotSharp.Core/Engines/AgentImporterInDialogflow.cs | 5 +++-- BotSharp.Core/Engines/RequestExtension.cs | 4 ++-- .../Intents/{IntentExtension.cs => IntentDriver.cs} | 4 ++-- BotSharp.Core/Intents/IntentResponseMessage.cs | 7 ++++++- 6 files changed, 27 insertions(+), 7 deletions(-) rename BotSharp.Core/Intents/{IntentExtension.cs => IntentDriver.cs} (79%) diff --git a/BotSharp.Core/Agents/Agent.cs b/BotSharp.Core/Agents/Agent.cs index 651187f9..3b98dec3 100644 --- a/BotSharp.Core/Agents/Agent.cs +++ b/BotSharp.Core/Agents/Agent.cs @@ -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; } diff --git a/BotSharp.Core/Agents/AgentDriver.cs b/BotSharp.Core/Agents/AgentDriver.cs index fe37d28d..fa24e1c5 100644 --- a/BotSharp.Core/Agents/AgentDriver.cs +++ b/BotSharp.Core/Agents/AgentDriver.cs @@ -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().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() diff --git a/BotSharp.Core/Engines/AgentImporterInDialogflow.cs b/BotSharp.Core/Engines/AgentImporterInDialogflow.cs index b715e0a9..7ae1ed16 100644 --- a/BotSharp.Core/Engines/AgentImporterInDialogflow.cs +++ b/BotSharp.Core/Engines/AgentImporterInDialogflow.cs @@ -56,7 +56,8 @@ namespace BotSharp.Core.Engines }).ToList()); } - agent.Entities.Add(entity.ToObject()); + var entityType = entity.ToObject(); + 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 diff --git a/BotSharp.Core/Engines/RequestExtension.cs b/BotSharp.Core/Engines/RequestExtension.cs index d1fe56ba..eef9045b 100644 --- a/BotSharp.Core/Engines/RequestExtension.cs +++ b/BotSharp.Core/Engines/RequestExtension.cs @@ -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 diff --git a/BotSharp.Core/Intents/IntentExtension.cs b/BotSharp.Core/Intents/IntentDriver.cs similarity index 79% rename from BotSharp.Core/Intents/IntentExtension.cs rename to BotSharp.Core/Intents/IntentDriver.cs index de2fd96c..1191e292 100644 --- a/BotSharp.Core/Intents/IntentExtension.cs +++ b/BotSharp.Core/Intents/IntentDriver.cs @@ -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().Any(x => x.Id == intent.Id)) return intent.Id; diff --git a/BotSharp.Core/Intents/IntentResponseMessage.cs b/BotSharp.Core/Intents/IntentResponseMessage.cs index 98cde8d1..6cbaee78 100644 --- a/BotSharp.Core/Intents/IntentResponseMessage.cs +++ b/BotSharp.Core/Intents/IntentResponseMessage.cs @@ -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 /// [MaxLength(1024)] - public String Payload { get; set; } + public String PayloadJson { get; set; } + + [NotMapped] + public JObject Payload { get; set; } } }