Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 123 forks source link

[QUERY] Still unclear how to select a specific template when targeting specific tags #178

Closed Tommigun1980 closed 2 years ago

Tommigun1980 commented 3 years ago

Query/Question SendTemplateNotificationAsync doesn't take in a template name, and the documentation doesn't at all explain how to select a specific template. From what I gather from closed tickets templates in an Installation object automatically register the template names as tags. So now to my question - how does one pick a specific template when targeting users via tags?

Currently I convert the list of tags to a tag expression, where the template name is concatenated with every tag.

This can't be the correct way of doing things, right? I mean it's completely undocumented, it completely defeats the entire point with the methods that accept tag collections, and it's inefficient and obscure. Or is this something that was dropped when refactoring the APIs and this really is the way to do it?

My code is currently as follows:

public Task SendPush(string templateName, IDictionary<string, string> templateParameters, IEnumerable<string> tags)
{
    return this.Hub()?.SendTemplateNotificationAsync(templateParameters, TagExpressionFromTemplateNameAndTags(templateName, tags));
}

private static string TagExpressionFromTemplateNameAndTags(string templateName, IEnumerable<string> tags)
{
    return string.Join(" || ", tags.Select(t => $"({t} && {templateName})"));
}

Please advice on whether this really is the intended way? If it is, please finish the refactoring of the API so this monstrosity is not needed (it looks to me like this use case was forgotten in the refactoring of the API), or at the very least document this.

Thank you.

Reference: https://github.com/Azure/azure-notificationhubs-dotnet/issues/10

Why is this not a Bug or a feature Request? It is unclear to me how this should be handled.

Setup (please complete the following information if applicable):

mpodwysocki commented 2 years ago

@Tommigun1980 An installation template can be targeted by using the name of the template as a tag. We will update our documentation accordingly to reflect this.