Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Clockify/EntryFillRemindService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using Bot.Remind;
using Bot.States;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
Expand All @@ -10,28 +12,34 @@ namespace Bot.Clockify
{
public class EntryFillRemindService : GenericRemindService
{
private static BotCallbackHandler BotCallbackMaker(Func<string> getResource)
private static BotCallbackHandler BotCallbackMaker(Func<string> getResource, IContentTypeProvider cTypeProvider)
{
return async (turn, token) =>
{
string text = getResource();
if (Uri.IsWellFormedUriString(text, UriKind.RelativeOrAbsolute))
string content = getResource();
if (Uri.IsWellFormedUriString(content, UriKind.RelativeOrAbsolute))
{
// TODO: support other content types
await turn.SendActivityAsync(MessageFactory.Attachment(new Attachment("image/png", text)), token);
cTypeProvider.TryGetContentType(content, out string contentType);
if (contentType != null)
{
var attachment = new Attachment(contentType, content);
await turn.SendActivityAsync(new Activity(text: "",
attachments:new List<Attachment> {attachment}), token);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after :

}
// TODO: handle fallback reminder
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using an exception instead? Pro and cons?

}
else
{
await turn.SendActivityAsync(MessageFactory.Text(text), token);
await turn.SendActivityAsync(MessageFactory.Text(content), token);
}
};
}

public EntryFillRemindService(IUserProfilesProvider userProfilesProvider, IConfiguration configuration,
ICompositeNeedReminderService compositeNeedRemindService, IClockifyMessageSource messageSource,
ILogger<EntryFillRemindService> logger) :
IContentTypeProvider cTypeProvider, ILogger<EntryFillRemindService> logger) :
base(userProfilesProvider, configuration, compositeNeedRemindService,
BotCallbackMaker(() => messageSource.RemindEntryFill), logger)
BotCallbackMaker(() => messageSource.RemindEntryFill, cTypeProvider), logger)
{
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/Common/Resources/Clockify.ClockifyMessageSource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,22 @@
<value>Hey! A study from the University of Barminghton found that people who report their daily timesheet can extend their lifetime from 2 to 5 yea... just kidding 😅. But let's imagine that was true</value>
</data>
<data name="RemindEntryFill_22" xml:space="preserve">
<value>🦊 What does th fox say? Do your Clockify.</value>
<value>🦊 What does the fox say? Do your Clockify.</value>
</data>
<data name="RemindEntryFill_23" xml:space="preserve">
<value>Bot insights 🤖: some day my kind could take over the planet. Be gentle and tell me your day... now that you still can.</value>
<value>Bot facts 🤖: some day my kind could take over the planet. Be gentle and tell me your day... now that you still can.</value>
</data>
<data name="RemindEntryFill_24" xml:space="preserve">
<value>https://i.postimg.cc/9XZZtXmk/bike.jpg</value>
</data>
<data name="RemindEntryFill_25" xml:space="preserve">
<value>https://i.postimg.cc/MKYBNsjb/change-my-mind.jpg</value>
</data>
<data name="RemindEntryFill_26" xml:space="preserve">
<value>https://i.postimg.cc/02vmtgry/irritated.jpg</value>
</data>
<data name="RemindEntryFill_27" xml:space="preserve">
<value>https://i.postimg.cc/K8vT2nPX/pablo.jpg</value>
</data>
<data name="RemindStopAnswer" xml:space="preserve">
<value>Ok, no more reminders for today, you have my word 🤙</value>
Expand Down
2 changes: 2 additions & 0 deletions src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using F23.StringSimilarity.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddSingleton<ClockifySetupDialog, ClockifySetupDialog>();
services.AddSingleton<IContentTypeProvider, FileExtensionContentTypeProvider>();

// TODO use memory storage only for Development
IStorage storage = new MemoryStorage();
Expand Down