fill parameter value for reply message
This commit is contained in:
parent
2e91b54d6d
commit
84e107c19b
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||||
|
// Use hover for the description of the existing attributes
|
||||||
|
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": ".NET Core Launch (console)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
// If you have changed target frameworks, make sure to update the program path.
|
||||||
|
"program": "${workspaceFolder}/BotSharp.UnitTest/bin/Debug/netcoreapp2.0/BotSharp.UnitTest.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/BotSharp.UnitTest",
|
||||||
|
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
|
||||||
|
"console": "internalConsole",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach",
|
||||||
|
"processId": "${command:pickProcess}"
|
||||||
|
}
|
||||||
|
,]
|
||||||
|
}
|
||||||
15
.vscode/tasks.json
vendored
Normal file
15
.vscode/tasks.json
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/BotSharp.UnitTest/BotSharp.UnitTest.csproj"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
<PackageReference Include="DotNetToolkit" Version="1.4.0" />
|
<PackageReference Include="DotNetToolkit" Version="1.4.0" />
|
||||||
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.5.4" />
|
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.5.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="RestSharp" Version="106.2.1" />
|
<PackageReference Include="RestSharp" Version="106.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace BotSharp.Core.Engines
|
namespace BotSharp.Core.Engines
|
||||||
{
|
{
|
||||||
|
|
@ -73,6 +74,8 @@ namespace BotSharp.Core.Engines
|
||||||
|
|
||||||
HandleContext(dc, rasa, intentResponse, aiResponse);
|
HandleContext(dc, rasa, intentResponse, aiResponse);
|
||||||
|
|
||||||
|
Console.WriteLine(JsonConvert.SerializeObject(aiResponse.Result));
|
||||||
|
|
||||||
return aiResponse;
|
return aiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,6 +138,15 @@ namespace BotSharp.Core.Engines
|
||||||
p.Value = query.Substring(entity.Start, entity.End - entity.Start);
|
p.Value = query.Substring(entity.Start, entity.End - entity.Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert to Standard entity value
|
||||||
|
if (!String.IsNullOrEmpty(p.Value) && !p.DataType.StartsWith("@sys."))
|
||||||
|
{
|
||||||
|
p.Value = agent.Entities.FirstOrDefault(x => x.Name == p.Name).Entries.FirstOrDefault((entry) => {
|
||||||
|
return entry.Value.ToLower() == p.Value.ToLower() ||
|
||||||
|
entry.Synonyms.Select(synonym => synonym.Synonym.ToLower()).Contains(p.Value.ToLower());
|
||||||
|
})?.Value;
|
||||||
|
}
|
||||||
|
|
||||||
// fixed entity per request
|
// fixed entity per request
|
||||||
if (request.Entities != null)
|
if (request.Entities != null)
|
||||||
{
|
{
|
||||||
|
|
@ -147,15 +159,6 @@ namespace BotSharp.Core.Engines
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to Standard entity value
|
|
||||||
if (!String.IsNullOrEmpty(p.Value) && !p.DataType.StartsWith("@sys."))
|
|
||||||
{
|
|
||||||
p.Value = agent.Entities.FirstOrDefault(x => x.Name == p.Name).Entries.FirstOrDefault((entry) => {
|
|
||||||
return entry.Value.ToLower() == p.Value.ToLower() ||
|
|
||||||
entry.Synonyms.Select(synonym => synonym.Synonym.ToLower()).Contains(p.Value.ToLower());
|
|
||||||
})?.Value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,10 +177,23 @@ namespace BotSharp.Core.Engines
|
||||||
msg.Speech = msg.Speech.StartsWith("[") ?
|
msg.Speech = msg.Speech.StartsWith("[") ?
|
||||||
ArrayHelper.GetRandom(msg.Speech.Substring(2, msg.Speech.Length - 4).Split("\",\"").ToList()) :
|
ArrayHelper.GetRandom(msg.Speech.Substring(2, msg.Speech.Length - 4).Split("\",\"").ToList()) :
|
||||||
msg.Speech;
|
msg.Speech;
|
||||||
|
|
||||||
|
msg.Speech = ReplaceParameters4Response(intentResponse.Parameters, msg.Speech);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ReplaceParameters4Response(List<IntentResponseParameter> parameters, string text)
|
||||||
|
{
|
||||||
|
var reg = new Regex(@"\$\w+");
|
||||||
|
|
||||||
|
reg.Matches(text).ToList().ForEach(token => {
|
||||||
|
text = text.Replace(token.Value, parameters.FirstOrDefault(x => x.Name == token.Value.Substring(1))?.Value.ToString());
|
||||||
|
});
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
private static void HandleContext(Database dc, RasaAi rasa, IntentResponse intentResponse, AIResponse aiResponse)
|
private static void HandleContext(Database dc, RasaAi rasa, IntentResponse intentResponse, AIResponse aiResponse)
|
||||||
{
|
{
|
||||||
// Merge context lifespan
|
// Merge context lifespan
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue