Reputation: 1236
I registered a device with 2 templates
{
"handle":"handleIdGoeshere",
"installationId":"installationIdgoeshere",
"platform":"gcm",
"templates":{
"ctemplate":
{
"Body" : "{\"data\": {\"message\": \"$(message)\",\"conversation\": \"$(conversation)\"}}",
"Tags":["chatTemplate"]
},
"rtemplate":
{
"Body" : "{\"data\": {\"message\": \"$(message)\"}}",
"Tags":["regularTemplate"]
}
},"tags":["device:tablet","language:en"]}
As you can see above, one template has the variable message and the other message and conversation
Each template has an assigned name, however when sending the push
var properties = new Dictionary<string, string>();
properties.Add("message", message);
properties.Add("conversation", "1234567890");
outcome = await hub.SendTemplateNotificationAsync(properties);
I can't specify which template I want to use, I thought that azure automatically detected the template based on the variables used for the push but I guess is not the case, if I send the push with only the message variable set I get the following
{
conversation=,
message=another test
}
which results in a parse error because the conversation variable is blank. So what's the purpose of templates then if azure will send all of them? and how can I fix this.
Thanks
Upvotes: 1
Views: 1008
Reputation: 376
Notification Hub doesn't detect the template based on push variables. You have to explicitly choose which template to send by using tag. For example, if you want to send notification using ctemplate (and you've defined the tag for this template as chattemplate), then you have to issue the send command something like this.
var properties = new Dictionary<string, string>();
properties.Add("message", message);
properties.Add("conversation", "1234567890");
outcome = await hub.SendTemplateNotificationAsync(properties, "chatTemplate");
Thanks,
Sateesh
Upvotes: 1