Skip to content

Commit

Permalink
feat(email): amp template
Browse files Browse the repository at this point in the history
fix(email): request formatting, adaptor handling
fix(sms): channel provider adaptor handling
fix(voice: channel provider adaptor handling
  • Loading branch information
JeremyMelton committed Apr 11, 2024
1 parent cbc07b9 commit 14d65df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ private static async Task<HttpContent> CreateMessageContent(IAudienceAddress[] r

private static async Task TryAddAmpContent(IEmail email, IDispatchCommunicationContext context, MultipartFormDataContent form, ExtendedEmailChannelProperties emailProperties)
{
if (emailProperties.AmpHtml == null)
var ampTemplate = emailProperties.AmpHtml.GetTemplateRegistration(context.CultureInfo, false);
if (ampTemplate == null)
return;
if (string.IsNullOrWhiteSpace(email.HtmlBody))
throw new InfobipException("HtmlBody is required when using AmpHtml");

var ampContent = await context.TemplateEngine.RenderAsync(emailProperties.AmpHtml.GetTemplateRegistration(context.CultureInfo, true), context);
var ampContent = await context.TemplateEngine.RenderAsync(ampTemplate, context);
AddStringContent(form, EmailField.AmpHtml, ampContent, false);
}

Expand Down Expand Up @@ -144,7 +145,7 @@ private static void AddStringContent(MultipartFormDataContent form, string key,
else
throw new InfobipException($"Cannot add {key} value is null.");
}
form.Add(new StringContent(value), key);
form.Add(new StringContent(value), String.Format("\"{0}\"", key));
}

private static void TryAddRecipients(IAudienceAddress[] recipients, IEmail email, MultipartFormDataContent form)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static bool ShouldAdapt(IRequestAdaptorContext adaptorContext)
return false;
return
(adaptorContext.GetValue(DeliveryUtil.ChannelIdKey)?.Equals(Id.Channel.Email(), StringComparison.InvariantCultureIgnoreCase) ?? false) &&
(adaptorContext.GetValue(DeliveryUtil.ChannelProviderIdKey)?.Equals(Id.ChannelProvider.Infobip(), StringComparison.InvariantCultureIgnoreCase) ?? false);
(adaptorContext.GetValue(DeliveryUtil.ChannelProviderIdKey)?.StartsWith(Id.ChannelProvider.Infobip(), StringComparison.InvariantCultureIgnoreCase) ?? false);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sealed class SmsDeliveryStatusReportAdaptor : IChannelProviderDeliveryReportRequ
{
public Task<IReadOnlyCollection<DeliveryReport>?> AdaptAsync(IRequestAdaptorContext adaptorContext)
{
if (!ShouldAdapt(adaptorContext.Content))
if (!ShouldAdapt(adaptorContext))
return Task.FromResult<IReadOnlyCollection<DeliveryReport>?>(null);

var statuses = JsonSerializer.Deserialize<SmsStatusReports>(adaptorContext.Content!);
Expand Down Expand Up @@ -53,11 +53,14 @@ sealed class SmsDeliveryStatusReportAdaptor : IChannelProviderDeliveryReportRequ
return Task.FromResult<IReadOnlyCollection<DeliveryReport>?>(ret);
}

private static bool ShouldAdapt(string? content)
private static bool ShouldAdapt(IRequestAdaptorContext adaptorContext)
{
if (string.IsNullOrWhiteSpace(content))
if (string.IsNullOrWhiteSpace(adaptorContext.Content))
return false;
return Array.TrueForAll(["pricePerMessage", "smsCount", "messageId", "bulkId"], x => content!.Contains(x));

return
(adaptorContext.GetValue(DeliveryUtil.ChannelIdKey)?.Equals(Id.Channel.Sms(), StringComparison.InvariantCultureIgnoreCase) ?? false) &&
(adaptorContext.GetValue(DeliveryUtil.ChannelProviderIdKey)?.StartsWith(Id.ChannelProvider.Infobip(), StringComparison.InvariantCultureIgnoreCase) ?? false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private static bool ShouldAdapt(string? content)
{
if (string.IsNullOrWhiteSpace(content))
return false;
return Array.TrueForAll(["voiceCall", "pricePerSecond", "answerTime", "messageId", "bulkId"], x => content!.Contains(x));
return
(adaptorContext.GetValue(DeliveryUtil.ChannelIdKey)?.Equals(Id.Channel.Voice(), StringComparison.InvariantCultureIgnoreCase) ?? false) &&
(adaptorContext.GetValue(DeliveryUtil.ChannelProviderIdKey)?.StartsWith(Id.ChannelProvider.Infobip(), StringComparison.InvariantCultureIgnoreCase) ?? false);
}
}
}

0 comments on commit 14d65df

Please sign in to comment.