BotSharp/BotSharp.Core/Intents/IntentDriver.cs

40 lines
1.3 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-06-13 12:23:03 +00:00
public static Intent GetIntent(this IBotPlatform bot, Database dc, string intentId)
2018-05-27 15:35:16 +00:00
{
2018-06-06 16:20:02 +00:00
var intent = dc.Table<Intent>()
2018-05-27 15:35:16 +00:00
.Include(x => x.Contexts)
.Include(x => x.Responses).ThenInclude(x => x.Contexts)
2018-06-07 05:53:38 +00:00
.Include(x => x.Responses).ThenInclude(x => x.Parameters).ThenInclude(x => x.Prompts)
2018-05-27 15:35:16 +00:00
.Include(x => x.Responses).ThenInclude(x => x.Messages)
.Include(x => x.UserSays).ThenInclude(x => x.Data)
.FirstOrDefault(x => x.Id == intentId);
2018-06-06 16:20:02 +00:00
// order parts by time
intent.UserSays.ForEach(x => x.Data = x.Data.OrderBy(d => d.UpdatedTime).ToList());
return intent;
2018-05-27 15:35:16 +00:00
}
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;
}
}
}