Skip to content

Commit 477c1ad

Browse files
author
MIDDLEEAST\mmoussa
committed
Renive Shortened Url
1 parent 42571fd commit 477c1ad

File tree

9 files changed

+25
-56
lines changed

9 files changed

+25
-56
lines changed

CSharp/intelligence-Zummer/Handlers/ArticlesIntentHandler.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ internal sealed class ArticlesIntentHandler : IIntentHandler
1818
{
1919
private const int ArticlesMaxResults = 5;
2020

21-
private readonly IUrlShorteningService urlShorteningService;
2221
private readonly ISearchService bingSearchApiHandler;
2322
private readonly IBotToUser botToUser;
2423

25-
public ArticlesIntentHandler(IBotToUser botToUser, IUrlShorteningService urlShorteningService, ISearchService bingSearchApiHandler)
24+
public ArticlesIntentHandler(IBotToUser botToUser, ISearchService bingSearchApiHandler)
2625
{
27-
SetField.NotNull(out this.urlShorteningService, nameof(urlShorteningService), urlShorteningService);
2826
SetField.NotNull(out this.bingSearchApiHandler, nameof(bingSearchApiHandler), bingSearchApiHandler);
2927
SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser);
3028
}
@@ -55,7 +53,7 @@ public async Task Respond(IMessageActivity activity, LuisResult result)
5553

5654
for (int i = 0; i < ArticlesMaxResults; i++)
5755
{
58-
var zummerResult = await this.PrepareZummerResult(bingSearch.webPages.value[i]);
56+
var zummerResult = this.PrepareZummerResult(bingSearch.webPages.value[i]);
5957
reply.Attachments.Add(ArticleCardGenerator.GetArticleCard(zummerResult, activity.ChannelId));
6058
}
6159

@@ -69,7 +67,7 @@ public async Task Respond(IMessageActivity activity, LuisResult result)
6967
await this.botToUser.PostAsync(reply);
7068
}
7169

72-
private async Task<ZummerSearchResult> PrepareZummerResult(Value pages)
70+
private ZummerSearchResult PrepareZummerResult(Value pages)
7371
{
7472
string url;
7573
var myUri = new Uri(pages.url);
@@ -87,8 +85,7 @@ private async Task<ZummerSearchResult> PrepareZummerResult(Value pages)
8785
{
8886
Name = pages.name,
8987
Snippet = pages.snippet,
90-
Url = pages.url,
91-
ShortenedUrl = await this.urlShorteningService.GetShortenedUrl(url),
88+
Url = url
9289
};
9390

9491
return zummerResult;

CSharp/intelligence-Zummer/Handlers/SummaryRegexHandler.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Text.RegularExpressions;
34
using System.Threading.Tasks;
45
using Microsoft.Bot.Builder.Dialogs;
@@ -27,7 +28,19 @@ public async Task Respond(IMessageActivity activity, Match result)
2728
{
2829
string articleUrl = TryParseSummaryUrl(result.Groups[2].Value);
2930

30-
await this.botToUser.PostAsync(string.Format(Strings.SummaryWaitMessage));
31+
var fullArticleMessage = this.botToUser.MakeMessage();
32+
33+
fullArticleMessage.Attachments.Add(CardGenerator.GetHeroCard(Strings.SummaryWaitMessage, cardActions: new List<CardAction>
34+
{
35+
new CardAction
36+
{
37+
Title = Strings.FullArticleString,
38+
Type = ActionTypes.OpenUrl,
39+
Value = articleUrl
40+
}
41+
}));
42+
43+
await this.botToUser.PostAsync(fullArticleMessage);
3144

3245
var bingSummary = await this.summaryService.GetSummary(articleUrl);
3346

@@ -58,8 +71,7 @@ public async Task Respond(IMessageActivity activity, Match result)
5871
private static string TryParseSummaryUrl(string text)
5972
{
6073
Uri uriResult;
61-
bool result = Uri.TryCreate(text, UriKind.Absolute, out uriResult)
62-
&& uriResult.Scheme == Uri.UriSchemeHttp;
74+
bool result = Uri.TryCreate(text, UriKind.Absolute, out uriResult);
6375

6476
if (result && uriResult.IsAbsoluteUri)
6577
{

CSharp/intelligence-Zummer/Modules/MainModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ protected override void Load(ContainerBuilder builder)
2222

2323
// Singlton services
2424
builder.RegisterType<LuisService>().Keyed<ILuisService>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces().SingleInstance();
25-
builder.RegisterType<TinyUrlRequestHandler>().Keyed<IUrlShorteningService>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces().SingleInstance();
2625
builder.RegisterType<BingSearchService>().Keyed<ISearchService>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces().SingleInstance();
2726
builder.RegisterType<BingSummarizeService>().Keyed<ISummarizeService>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces().SingleInstance();
2827
builder.RegisterType<ApiHandler>().Keyed<IApiHandler>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces().SingleInstance();

CSharp/intelligence-Zummer/Services/IUrlShorteningService.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

CSharp/intelligence-Zummer/Services/TinyUrlRequestHandler.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

CSharp/intelligence-Zummer/Strings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CSharp/intelligence-Zummer/Strings.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
<data name="FallbackIntentMessage" xml:space="preserve">
124124
<value>Hmm... I did not understand that. Rephrase your message and try again.</value>
125125
</data>
126-
<data name="FullStoryString" xml:space="preserve">
127-
<value>Full Story</value>
126+
<data name="FullArticleString" xml:space="preserve">
127+
<value>Full Article</value>
128128
</data>
129129
<data name="GreetOnDemand" xml:space="preserve">
130130
<value>Hi! What would you like to read about? You can just type the topic and I'll do my best to fetch best Wikipedia results for you to read, powered by Bing Search.</value>

CSharp/intelligence-Zummer/Utilities/CardGenerators/ArticleCardGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static Attachment GetArticleCard(ZummerSearchResult result, string channe
2424

2525
var actions = new List<CardAction>
2626
{
27-
new CardAction(ActionTypes.ImBack, Strings.ReadSummary, value: "summary " + (string.IsNullOrEmpty(result.ShortenedUrl) ? result.Url : result.ShortenedUrl))
27+
new CardAction(ActionTypes.ImBack, Strings.ReadSummary, value: "summary " + result.Url)
2828
};
2929

3030
switch (channelId)

CSharp/intelligence-Zummer/Zummer.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
<Compile Include="Handlers\SummaryRegexHandler.cs" />
142142
<Compile Include="Services\ISearchService.cs" />
143143
<Compile Include="Services\ISummarizeService.cs" />
144-
<Compile Include="Services\IUrlShorteningService.cs" />
145144
<Compile Include="Utilities\CardGenerators\ArticleCardGenerator.cs" />
146145
<Compile Include="Handlers\IHandlerFactory.cs" />
147146
<Compile Include="Modules\MainModule.cs" />
@@ -154,7 +153,6 @@
154153
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
155154
</Compile>
156155
<Compile Include="Properties\AssemblyInfo.cs" />
157-
<Compile Include="Services\TinyUrlRequestHandler.cs" />
158156
<Compile Include="Strings.Designer.cs">
159157
<AutoGen>True</AutoGen>
160158
<DesignTime>True</DesignTime>

0 commit comments

Comments
 (0)