Skip to content

Commit f6d96ef

Browse files
committed
Cleaned up the Azure QnA command
1 parent 94202f0 commit f6d96ef

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Fritz.Chatbot/Commands/AzureQnACommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public AzureQnACommand(IConfiguration configuration, ILogger<AzureQnACommand> lo
3636

3737
public bool CanExecute(string userName, string fullCommandText)
3838
{
39-
return fullCommandText.EndsWith("?");
39+
40+
return fullCommandText.Length >= 10 && fullCommandText.EndsWith("?");
41+
4042
}
4143

4244
public async Task Execute(IChatService chatService, string userName, string fullCommandText)
@@ -52,7 +54,7 @@ public async Task Execute(IChatService chatService, string userName, string full
5254
public async Task Query(IChatService chatService, string userName, string query)
5355
{
5456
var responseString = string.Empty;
55-
query = WebUtility.UrlEncode(query);
57+
// query = WebUtility.UrlEncode(query);
5658

5759
//Build the URI
5860
var qnamakerUriBase = new Uri("https://fritzbotqna.azurewebsites.net/qnamaker");
@@ -92,6 +94,7 @@ public async Task Query(IChatService chatService, string userName, string query)
9294
QnAMakerResult response;
9395
try
9496
{
97+
9598
response = JsonConvert.DeserializeObject<QnAMakerResult>(responseString);
9699

97100
var thisAnswer = response.Answers.OrderByDescending(a => a.Score).FirstOrDefault();

Fritz.Chatbot/Fritz.Chatbot.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="Markdig" Version="0.18.3" />
1213
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.4" />
1314
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.0.4" />
1415
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />

Fritz.Chatbot/Helpers/StringExtensions.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ namespace Fritz.Chatbot.Helpers
77
{
88
public static class StringExtensions
99
{
10-
private readonly static Regex _regex = new Regex(@"\[([\w\s?.-]+)\]\(((?:http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:[0-9]{1,5})?(?:\/.*)?)\)");
10+
// private readonly static Regex _regex = new Regex(@"\[([\w\s?.-]+)\]\(((?:http:\/\/(www\.)?|https:\/\/(www\.)?|http:\/\/|https:\/\/)?[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:[0-9]{1,5})?(?:\/.*)?)\)");
1111
public static string HandleMarkdownLinks(this string value)
1212
{
1313

14-
foreach (Match match in _regex.Matches(value))
15-
{
14+
//foreach (Match match in _regex.Matches(value))
15+
//{
1616

17-
var title = match.Groups[1]; // The link text (that between the [] in markdown)
18-
var url = match.Groups[2]; // The url (that between the () in markdown)
17+
// var title = match.Groups[1]; // The link text (that between the [] in markdown)
18+
// var url = match.Groups[2]; // The url (that between the () in markdown)
1919

20-
value = value.Replace(match.Value, $"{title} found at {url} ").Replace(" ", " ");
20+
// value = value.Replace(match.Value, $"{title} found at {url} ").Replace(" ", " ");
2121

22-
}
22+
//}
23+
24+
value = Markdig.Markdown.ToPlainText(value);
25+
26+
value = value.Replace("\n", " ");
2327

2428
return value;
2529
}

0 commit comments

Comments
 (0)