OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PushNotifications with AmazonSimpleNotificationServiceClient not able to configure TTL for Android

  • Thread starter Thread starter Edwin Vermeer
  • Start date Start date
E

Edwin Vermeer

Guest
Update When I use the legacy time_to_live parameter instead of the ttl parameter then it does work. For more information about this see What's the difference between `ttl` and `time_to_live` property in FCM message for android push?

My current working Message is:

Code:
Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data}, \\\"ttl\\\":\\\"0s\\\", \\\"time_to_live\\\": 0 }\" }";

Then the questions I have are:

  1. Why does AWS only support the legacy time_to_live instead of the ttl?
  2. Is it a good idea to set them both like what Im currently doing?
  3. And Why is the AWS.SNS.MOBILE.FCM.TTL not working? According to the documentation it should always take precedence over whatever is the message itself. Did I use an incorrect value then?

Original question:

For sending pushnotifications I am using AWS SNS which works quite well. I am now trying to configure a 'time to live' of 0 for push notifications. This because I only want the push message when the app is able to process it immediately.

Currently I am using this C# snippet (Running in an Azure App Service). Push notifications do arrive but it's not respecting the TTL:

Code:
var data = JsonHelper.SerializeIgnoreNull(data).Replace("\\", "\\\\").Replace("\"", "\\\"");
var sns = new AmazonSimpleNotificationServiceClient(snsAccessKey, snsAccessSecret);
var data = JsonHelper.SerializeIgnoreNull(data).Replace("\\", "\\\\").Replace("\"", "\\\"");
var publishRequest = new PublishRequest() { 
    TargetArn = arn, 
    Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} }\", \"AWS.SNS.MOBILE.FCM.TTL\":0 }", 
    MessageStructure = "json" 
 };
var result = sns.Publish(publishRequest);

When I do something similar for iOS the ttl does work.

For Android I also tried a couple of other constructions of the Message property: Including a ttl property inside the GCM object

Code:
Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\”{data}, \\\"ttl\\\": 0 }\", \"AWS.SNS.MOBILE.FCM.TTL\":0 }",

The AWS attribute inside the GCM object:

Code:
Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data}, \\\"ttl\\\": 0, \\\"AWS.SNS.MOBILE.FCM.TTL\\\":0 }\"}",

Both ttl and AWS properties outside the GCM object:

Code:
Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} }\", \"ttl\": 0, \"AWS.SNS.MOBILE.FCM.TTL\":0 }",

I alsy tried setting just the ttl with the string 0s

Code:
Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} , \\\"ttl\\\":\\\"0s\\\" }\" }";

I also tried setting the AWS attributes using the MessageAttributes on the object:

Code:
Dictionary<string, MessageAttributeValue> attributes = new Dictionary<string, MessageAttributeValue>();
attributes.Add("AWS.SNS.MOBILE.FCM.TTL", new MessageAttributeValue() { StringValue = "0", DataType = "Number" });
publishRequest.MessageAttributes = attributes;

When I look at the documentation I would think I should use the attributes or the first version of this post. See AWS SNS TTL Documentation
<p><strong>Update</strong>
When I use the legacy time_to_live parameter instead of the ttl parameter then it does work. For more information about this see <a href="https://stackoverflow.com/questions...tl-and-time-to-live-property-in-fcm-message-f">What&#39;s the difference between `ttl` and `time_to_live` property in FCM message for android push?</a></p>
<p>My current working Message is:</p>
<pre><code>Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data}, \\\"ttl\\\":\\\"0s\\\", \\\"time_to_live\\\": 0 }\" }";
</code></pre>
<p>Then the questions I have are:</p>
<ol>
<li>Why does AWS only support the legacy time_to_live instead of the ttl?</li>
<li>Is it a good idea to set them both like what Im currently doing?</li>
<li>And Why is the AWS.SNS.MOBILE.FCM.TTL not working? According to the documentation it should always take precedence over whatever is the message itself. Did I use an incorrect value then?</li>
</ol>
<p><strong>Original question:</strong></p>
<p>For sending pushnotifications I am using AWS SNS which works quite well.
I am now trying to configure a 'time to live' of 0 for push notifications.
This because I only want the push message when the app is able to process it immediately.</p>
<p>Currently I am using this C# snippet (Running in an Azure App Service). Push notifications do arrive but it's not respecting the TTL:</p>
<pre><code>var data = JsonHelper.SerializeIgnoreNull(data).Replace("\\", "\\\\").Replace("\"", "\\\"");
var sns = new AmazonSimpleNotificationServiceClient(snsAccessKey, snsAccessSecret);
var data = JsonHelper.SerializeIgnoreNull(data).Replace("\\", "\\\\").Replace("\"", "\\\"");
var publishRequest = new PublishRequest() {
TargetArn = arn,
Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} }\", \"AWS.SNS.MOBILE.FCM.TTL\":0 }",
MessageStructure = "json"
};
var result = sns.Publish(publishRequest);
</code></pre>
<p>When I do something similar for iOS the ttl does work.</p>
<p>For Android I also tried a couple of other constructions of the Message property:
Including a ttl property inside the GCM object</p>
<pre><code>Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\”{data}, \\\"ttl\\\": 0 }\", \"AWS.SNS.MOBILE.FCM.TTL\":0 }",
</code></pre>
<p>The AWS attribute inside the GCM object:</p>
<pre><code>Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data}, \\\"ttl\\\": 0, \\\"AWS.SNS.MOBILE.FCM.TTL\\\":0 }\"}",
</code></pre>
<p>Both ttl and AWS properties outside the GCM object:</p>
<pre><code>Message = $"{\"GCM\\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} }\", \"ttl\": 0, \"AWS.SNS.MOBILE.FCM.TTL\":0 }",
</code></pre>
<p>I alsy tried setting just the ttl with the string 0s</p>
<pre><code>Message = $"{\"GCM\": \"{\\\"priority\\\": \\\"high\\\", \\\"data\\\":{data} , \\\"ttl\\\":\\\"0s\\\" }\" }";
</code></pre>
<p>I also tried setting the AWS attributes using the MessageAttributes on the object:</p>
<pre><code>Dictionary<string, MessageAttributeValue> attributes = new Dictionary<string, MessageAttributeValue>();
attributes.Add("AWS.SNS.MOBILE.FCM.TTL", new MessageAttributeValue() { StringValue = "0", DataType = "Number" });
publishRequest.MessageAttributes = attributes;
</code></pre>
<p>When I look at the documentation I would think I should use the attributes or the first version of this post. See <a href="https://docs.aws.amazon.com/sns/lat...fy,has to deliver the message to the endpoint." rel="nofollow noreferrer">AWS SNS TTL Documentation</a></p>
Continue reading...
 

Latest posts

J
Replies
0
Views
1
jbowerbir
J
V
Replies
0
Views
1
Vinicius Martin
V
Top