BotSharp/BotSharp.Core/Intents/IntentDriver.cs
2018-06-02 22:53:54 -05:00

40 lines
1.2 KiB
C#

using BotSharp.Core.Agents;
using BotSharp.Core.Engines;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BotSharp.Core.Intents
{
public static class IntentDriver
{
public static Intent GetIntent(this IBotEngine bot, Database dc, string intentId)
{
return dc.Table<Intent>()
.Include(x => x.Contexts)
.Include(x => x.Responses).ThenInclude(x => x.Contexts)
.Include(x => x.Responses).ThenInclude(x => x.Parameters)
.Include(x => x.Responses).ThenInclude(x => x.Messages)
.Include(x => x.UserSays).ThenInclude(x => x.Data)
.FirstOrDefault(x => x.Id == intentId);
}
public static String CreateIntent(this Agent agent, Database dc, Intent intent)
{
if (String.IsNullOrEmpty(intent.Id))
{
intent.Id = Guid.NewGuid().ToString();
}
if (dc.Table<Intent>().Any(x => x.Id == intent.Id)) return intent.Id;
dc.Table<Intent>().Add(intent);
return intent.Id;
}
}
}