Skip to content

Commit 48a053c

Browse files
authored
Merge pull request #34 from dan-nobel/main
Communication tokens link handling fix
2 parents be115a3 + 0f801c6 commit 48a053c

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

Valghalla.Application/Communication/ICommunicationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public interface ICommunicationHelper
44
{
5-
string ReplaceTokens(string template, CommunicationRelatedInfo info);
5+
string ReplaceTokens(string template, CommunicationRelatedInfo info, bool htmlFormatLinks);
66
Task<bool> ValidateTaskInvitationAsync(Guid participantId, Guid taskAssignmentId, CancellationToken cancellationToken);
77
Task<bool> ValidateRemovedFromTaskAsync(Guid participantId, Guid taskAssignmentId, CancellationToken cancellationToken);
88
Task<bool> ValidateRemovedFromTaskByValidationAsync(Guid participantId, Guid taskAssignmentId, CancellationToken cancellationToken);

Valghalla.Integration/Communication/CommunicationHelper.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Valghalla.Application.Communication;
1+
using System;
2+
using System.Security.Policy;
3+
using Valghalla.Application.Communication;
24
using Valghalla.Application.Tenant;
35

46
namespace Valghalla.Integration.Communication
@@ -174,14 +176,25 @@ public async Task<bool> ValidateTaskInvitationRetractedAsync(Guid taskAssignment
174176
return true;
175177
}
176178

177-
public string ReplaceTokens(string template, CommunicationRelatedInfo info)
179+
public string ReplaceTokens(string template, CommunicationRelatedInfo info, bool htmlFormatLinks)
178180
{
179181
if (string.IsNullOrEmpty(template)) return string.Empty;
180182

181183
var externalWebLink = tenantContextProvider.CurrentTenant.ExternalDomain;
182184
var contactLink = tenantContextProvider.CurrentTenant.ExternalDomain + "/kontakt-os";
183185
var invitationLink = tenantContextProvider.CurrentTenant.ExternalDomain + $"/opgaver/invitation/{info.HashValue}/{info.InvitationCode ?? Guid.Empty}";
184186

187+
var externalWebLinkHTML = externalWebLink;
188+
var contactLinkHTML = contactLink;
189+
var invitationLinkHTML = invitationLink;
190+
191+
if (htmlFormatLinks)
192+
{
193+
externalWebLinkHTML = "<a href=\"" + externalWebLink + "\">" + externalWebLink + "</a>";
194+
contactLinkHTML = "<a href=\"" + contactLink + "\">" + contactLink + "</a>";
195+
invitationLinkHTML = "<a href=\"" + invitationLink + "\">" + invitationLink + "</a>";
196+
}
197+
185198
return template
186199
.Replace("!name", info.Participant.Name)
187200
.Replace("!election", info.ElectionTitle)
@@ -195,9 +208,9 @@ public string ReplaceTokens(string template, CommunicationRelatedInfo info)
195208
.Replace("!payment", info.TaskType.Payment.HasValue ? info.TaskType.Payment.ToString() : string.Empty)
196209
.Replace("!days", (info.TaskDate - DateTime.UtcNow).Days.ToString())
197210
.Replace("!municipality", info.MunicipalityName)
198-
.Replace("!invitation", invitationLink)
199-
.Replace("!contact", contactLink)
200-
.Replace("!external_web", externalWebLink);
211+
.Replace("!invitation", invitationLinkHTML)
212+
.Replace("!contact", contactLinkHTML)
213+
.Replace("!external_web", externalWebLinkHTML);
201214
}
202215

203216
private static string PadTimeValue(int value) => value.ToString().PadLeft(2, '0');

Valghalla.Integration/Communication/CommunicationService.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Valghalla.Application.Communication;
1+
using SF1601;
2+
using Valghalla.Application.Communication;
23
using Valghalla.Application.Configuration;
34
using Valghalla.Application.Queue;
45
using Valghalla.Application.Queue.Messages;
@@ -172,8 +173,13 @@ private async Task<Guid> WriteCommunicationLogAsync(Guid participantId, Guid tas
172173

173174
private async Task<Guid> WriteCommunicationLogAsync(CommunicationRelatedInfo info, Guid participantId, CommunicationLogSendType sendType, int templateType, string templateSubject, string templateContent, CancellationToken cancellationToken)
174175
{
175-
var subject = communicationHelper.ReplaceTokens(templateSubject, info);
176-
var content = communicationHelper.ReplaceTokens(templateContent, info);
176+
bool htmlFormatLinks = true;
177+
if (templateType == TemplateType.SMS)
178+
htmlFormatLinks = false;
179+
180+
181+
var subject = communicationHelper.ReplaceTokens(templateSubject, info, htmlFormatLinks);
182+
var content = communicationHelper.ReplaceTokens(templateContent, info, htmlFormatLinks);
177183

178184
if (templateType == TemplateType.DigitalPost)
179185
{

Valghalla.Worker/Services/TaskCommunicationService.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ public async Task SendGroupMessageAsync(Guid logId, Guid participantId, Guid tas
165165
var info = await (isRejectedTask ? communicationQueryRepository.GetRejectedTaskInfoAsync(taskAssignmentId, cancellationToken) : communicationQueryRepository.GetCommunicationRelatedInfoAsync(participantId, taskAssignmentId, cancellationToken))
166166
?? (isRejectedTask ? throw new Exception($"Errors occurred when fetching rejected task related information (taskId = {taskAssignmentId})") : throw new Exception($"Errors occurred when fetching assigned task related information (taskId = {taskAssignmentId})"));
167167

168-
var subject = communicationHelper.ReplaceTokens(templateSubject, info);
169-
var content = communicationHelper.ReplaceTokens(templateContent, info);
168+
bool htmlFormatLinks = true;
169+
if(templateType == TemplateType.SMS)
170+
htmlFormatLinks = false;
171+
172+
var subject = communicationHelper.ReplaceTokens(templateSubject, info, htmlFormatLinks);
173+
var content = communicationHelper.ReplaceTokens(templateContent, info, htmlFormatLinks);
170174

171175
if (templateType == TemplateType.DigitalPost)
172176
{
@@ -191,8 +195,12 @@ private async Task SendAsync(Guid logId, Guid participantId, Guid taskAssignment
191195
var info = await communicationQueryRepository.GetCommunicationRelatedInfoAsync(participantId, taskAssignmentId, cancellationToken)
192196
?? throw new Exception($"Errors occurred when fetching task related information (taskAssignmentId = {taskAssignmentId})");
193197

194-
var subject = communicationHelper.ReplaceTokens(template.Subject, info);
195-
var content = communicationHelper.ReplaceTokens(template.Content, info);
198+
bool htmlFormatLinks = true;
199+
if (template.TemplateType == TemplateType.SMS)
200+
htmlFormatLinks = false;
201+
202+
var subject = communicationHelper.ReplaceTokens(template.Subject, info, htmlFormatLinks);
203+
var content = communicationHelper.ReplaceTokens(template.Content, info, htmlFormatLinks);
196204

197205
if (template.TemplateType == TemplateType.DigitalPost)
198206
{

0 commit comments

Comments
 (0)