BotSharp/BotSharp.Core/Intents/IntentDriver.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2018-03-28 22:08:49 +00:00
using BotSharp.Core.Agents;
2018-05-27 15:35:16 +00:00
using BotSharp.Core.Engines;
2018-01-02 18:05:35 +00:00
using EntityFrameworkCore.BootKit;
2018-05-27 15:35:16 +00:00
using Microsoft.EntityFrameworkCore;
2018-01-02 18:05:35 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2018-03-28 22:08:49 +00:00
namespace BotSharp.Core.Intents
2018-01-02 18:05:35 +00:00
{
2018-05-23 05:11:15 +00:00
public static class IntentDriver
2018-01-02 18:05:35 +00:00
{
2018-05-27 15:35:16 +00:00
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);
}
2018-05-23 05:11:15 +00:00
public static String CreateIntent(this Agent agent, Database dc, Intent intent)
2018-01-02 18:05:35 +00:00
{
if (dc.Table<Intent>().Any(x => x.Id == intent.Id)) return intent.Id;
dc.Table<Intent>().Add(intent);
return intent.Id;
}
}
}