forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring C# and Node code to Zummer
- Loading branch information
1 parent
477c1ad
commit a6b59f7
Showing
63 changed files
with
843 additions
and
1,244 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
CSharp/intelligence-Zummer/Handlers/ArticlesIntentHandler.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
CSharp/intelligence-Zummer/Handlers/SearchIntentHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Internals; | ||
using Microsoft.Bot.Builder.Internals.Fibers; | ||
using Microsoft.Bot.Builder.Luis; | ||
using Microsoft.Bot.Builder.Luis.Models; | ||
using Microsoft.Bot.Connector; | ||
using Zummer.Models.Search; | ||
using Zummer.Services; | ||
|
||
namespace Zummer.Handlers | ||
{ | ||
internal sealed class SearchIntentHandler : IIntentHandler | ||
{ | ||
private readonly ISearchService bingSearchService; | ||
private readonly ISummarizeService bingSummarizeService; | ||
private readonly IBotToUser botToUser; | ||
|
||
public SearchIntentHandler(IBotToUser botToUser, ISearchService bingSearchService, ISummarizeService bingSummarizeService) | ||
{ | ||
SetField.NotNull(out this.bingSearchService, nameof(bingSearchService), bingSearchService); | ||
SetField.NotNull(out this.bingSummarizeService, nameof(bingSummarizeService), bingSummarizeService); | ||
SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); | ||
} | ||
|
||
public async Task Respond(IAwaitable<IMessageActivity> activity, LuisResult result) | ||
{ | ||
EntityRecommendation entityRecommendation; | ||
|
||
var query = result.TryFindEntity(ZummerStrings.ArticlesEntityTopic, out entityRecommendation) | ||
? entityRecommendation.Entity | ||
: result.Query; | ||
|
||
await this.botToUser.PostAsync(string.Format(Strings.SearchTopicTypeMessage)); | ||
|
||
var bingSearch = await this.bingSearchService.FindArticles(query); | ||
|
||
var zummerResult = this.PrepareZummerResult(query, bingSearch.webPages.value[0]); | ||
|
||
var bingSummary = await this.bingSummarizeService.GetSummary(zummerResult.Url); | ||
|
||
if (bingSummary?.Data != null && bingSummary.Data.Length != 0) | ||
{ | ||
var summaryText = bingSummary.Data.Aggregate( | ||
$"### [{zummerResult.Tile}]({zummerResult.Url})" | ||
+ "\n" + | ||
$"**{Strings.SummaryString}**" | ||
+ "\n\n", | ||
(current, datum) => current + (datum.Text + "\n\n")); | ||
|
||
summaryText += | ||
$"*{string.Format(Strings.PowerBy, $"[Bing™](https://www.bing.com/search/?q={zummerResult.Query} site:wikipedia.org)")}*"; | ||
|
||
await this.botToUser.PostAsync(summaryText); | ||
} | ||
else | ||
{ | ||
await this.botToUser.PostAsync(Strings.SummaryErrorMessage); | ||
} | ||
} | ||
|
||
private ZummerSearchResult PrepareZummerResult(string query, Value page) | ||
{ | ||
string url; | ||
var myUri = new Uri(page.url); | ||
|
||
if (myUri.Host == "www.bing.com" && myUri.AbsolutePath == "/cr") | ||
{ | ||
url = HttpUtility.ParseQueryString(myUri.Query).Get("r"); | ||
} | ||
else | ||
{ | ||
url = page.url; | ||
} | ||
|
||
var zummerResult = new ZummerSearchResult | ||
{ | ||
Url = url, | ||
Query = query, | ||
Tile = page.name | ||
}; | ||
|
||
return zummerResult; | ||
} | ||
} | ||
} |
Oops, something went wrong.