From fb73ff7a59407c03c63f782ff5ae9f37b83b6d7a Mon Sep 17 00:00:00 2001 From: simonecolucci93 Date: Wed, 22 Sep 2021 18:03:26 +0200 Subject: [PATCH 1/3] feat: infer content type based on attachment url --- src/Clockify/EntryFillRemindService.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Clockify/EntryFillRemindService.cs b/src/Clockify/EntryFillRemindService.cs index a673169..cf198b7 100644 --- a/src/Clockify/EntryFillRemindService.cs +++ b/src/Clockify/EntryFillRemindService.cs @@ -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; @@ -14,15 +16,17 @@ private static BotCallbackHandler BotCallbackMaker(Func getResource) { 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); + new FileExtensionContentTypeProvider().TryGetContentType(content, out string contentType); + var attachment = new Attachment(contentType, content); + await turn.SendActivityAsync(new Activity(text: "", + attachments:new List {attachment}), token); } else { - await turn.SendActivityAsync(MessageFactory.Text(text), token); + await turn.SendActivityAsync(MessageFactory.Text(content), token); } }; } From 25bbdfc52d04e149fc3f5b2fb352813929221743 Mon Sep 17 00:00:00 2001 From: simonecolucci93 Date: Wed, 22 Sep 2021 18:03:41 +0200 Subject: [PATCH 2/3] feat: add more options for reminder messages --- .../Clockify.ClockifyMessageSource.resx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Common/Resources/Clockify.ClockifyMessageSource.resx b/src/Common/Resources/Clockify.ClockifyMessageSource.resx index 1e3b52c..438982b 100644 --- a/src/Common/Resources/Clockify.ClockifyMessageSource.resx +++ b/src/Common/Resources/Clockify.ClockifyMessageSource.resx @@ -142,10 +142,22 @@ 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 - 🦊 What does th fox say? Do your Clockify. + 🦊 What does the fox say? Do your Clockify. - Bot insights 🤖: some day my kind could take over the planet. Be gentle and tell me your day... now that you still can. + Bot facts 🤖: some day my kind could take over the planet. Be gentle and tell me your day... now that you still can. + + + https://i.postimg.cc/9XZZtXmk/bike.jpg + + + https://i.postimg.cc/MKYBNsjb/change-my-mind.jpg + + + https://i.postimg.cc/02vmtgry/irritated.jpg + + + https://i.postimg.cc/K8vT2nPX/pablo.jpg Ok, no more reminders for today, you have my word 🤙 From 4482986e63b97f800a346f1ac994c5193fd41652 Mon Sep 17 00:00:00 2001 From: simonecolucci93 Date: Mon, 18 Oct 2021 17:47:24 +0200 Subject: [PATCH 3/3] refactor: inject content provider via DI --- src/Clockify/EntryFillRemindService.cs | 18 +++++++++++------- src/Startup.cs | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Clockify/EntryFillRemindService.cs b/src/Clockify/EntryFillRemindService.cs index cf198b7..b1170b0 100644 --- a/src/Clockify/EntryFillRemindService.cs +++ b/src/Clockify/EntryFillRemindService.cs @@ -12,17 +12,21 @@ namespace Bot.Clockify { public class EntryFillRemindService : GenericRemindService { - private static BotCallbackHandler BotCallbackMaker(Func getResource) + private static BotCallbackHandler BotCallbackMaker(Func getResource, IContentTypeProvider cTypeProvider) { return async (turn, token) => { string content = getResource(); if (Uri.IsWellFormedUriString(content, UriKind.RelativeOrAbsolute)) { - new FileExtensionContentTypeProvider().TryGetContentType(content, out string contentType); - var attachment = new Attachment(contentType, content); - await turn.SendActivityAsync(new Activity(text: "", - attachments:new List {attachment}), 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}), token); + } + // TODO: handle fallback reminder } else { @@ -33,9 +37,9 @@ await turn.SendActivityAsync(new Activity(text: "", public EntryFillRemindService(IUserProfilesProvider userProfilesProvider, IConfiguration configuration, ICompositeNeedReminderService compositeNeedRemindService, IClockifyMessageSource messageSource, - ILogger logger) : + IContentTypeProvider cTypeProvider, ILogger logger) : base(userProfilesProvider, configuration, compositeNeedRemindService, - BotCallbackMaker(() => messageSource.RemindEntryFill), logger) + BotCallbackMaker(() => messageSource.RemindEntryFill, cTypeProvider), logger) { } } diff --git a/src/Startup.cs b/src/Startup.cs index 82eae95..97d186b 100644 --- a/src/Startup.cs +++ b/src/Startup.cs @@ -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; @@ -91,6 +92,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); // TODO use memory storage only for Development IStorage storage = new MemoryStorage();