question

arda avatar image
arda asked

TTL on server.SendPushNotification

Hi,

We are trying to implement a push notification system to our game. It works perfectly, but we need to add a time to live option for notifications. Code below does not do anything with ttl.

I think "android":{"priority":"high","ttl":"10s"} is a wrong usage but couldn't find anything in documentation.

Any suggestions? Thanks.

Note: I've already tried AdvancedPlatformDelivery, but it didn't work.

handlers.SendPushNotificationToFriend = function (args)
{
    
    var targetId = args.TargetId;
    var logArrayObject = [];
    var functionMessage = args.FunctionMessage;
    
    var splittedMessage = functionMessage.split("/");
    
    var obj = { playerID: currentPlayerId, fMessage : functionMessage, "android":{"priority":"high","ttl":"10s"} };
    var myJSON = JSON.stringify(obj);
      
        try {
            server.SendPushNotification({
                Recipient : targetId,
                Package : {
                    Message : "Co-Op Game / " + splittedMessage[5] + " / " + splittedMessage[6] + " / " + splittedMessage[7],
                    Title:  splittedMessage[2] + " sent you a challange!",
                    CustomData: myJSON,

                }
            });
            
            
        } catch (ex) 
        {
            logArrayObject.push("Error->" + ex.Message + " ID-->" + args.TargetId);
            // Target player has not registered for Push Notifications
        }
        
         return { returnLogValue: logArrayObject };
}
Push Notifications
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Using AdvancedPlatformDelivery might work, may I know the details about how you do that by code? And, please try this (using AdvancedPlatformDelivery):

{"Platform":"GoogleCloudMessaging","Json":{"priority":"high",
"time_to_live":"10"}}

And, these guides & thread I followed might be helpful for you:

https://community.playfab.com/questions/19275/what-options-are-available-for-advancedpushplatfor.html

https://docs.aws.amazon.com/sns/latest/dg/sns-send-custom-platform-specific-payloads-mobile-devices.html

https://firebase.google.com/docs/cloud-messaging/http-server-ref

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

arda avatar image arda commented ·

Thanks for your reply, I'll try this code. Code is attached below;

string targetId = targetID;
            Debug.Log("Send notification to--->" + AccountDataScript.PLAYFAB_ID);
            PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
            {
                FunctionName = "SendPushToFriend",
                FunctionParameter = new Dictionary<string, object>() {
            { "TargetId",  targetId  },
            { "FunctionMessage",  functionMessage  },
        }
            }, ResultPush, OnPlayFabError);

0 Likes 0 ·
arda avatar image arda commented ·

Okay I'm trying to do it like that but nothing happens when I call the method. No errors on sender's phone and nothing received on the other phone.

 jsonObjectAndroid =
        {
        	
  
      "Platform":"GoogleCloudMessaging","Json":{"priority":"high",
"time_to_live":"10"},
      "message":{
    "topic":"blablabla",
    "notification":{
      "body" : "blablablabla",
      "title" : "blablabla",
    },
    "data" : {
      "volume" : "blablabla",
      "contents" : "blablablabla"
    }
      }


        };
        
        let jsonStringAndroid = JSON.stringify(jsonObjectAndroid);
      


        // try to send push notification
        try {




        let pushNotificationResult = server.SendPushNotification
        ({
        	Recipient: targetId,
        	
            AdvancedPlatformDelivery: [
        	{
                	    Json: jsonStringAndroid
                }
        	]
        });
            
            
        }

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan arda commented ·

I think the code should be like this:

jsonObjectAndroid =
{
  "notification": {
      "body" : "blablablabla",
      "title" : "blablabla"
  },
  "data": {
      "volume" : "blablabla",
      "contents" : "blablablabla"
  },
  "time_to_live": 10,
  "priority": 1
};
 
let jsonStringAndroid = JSON.stringify(jsonObjectAndroid);
 
let plattformAndroid = "GoogleCloudMessaging";
 
let pushNotificationResult = server.SendPushNotification
({
  Recipient: targetId,
        AdvancedPlatformDelivery: [
        {
          Json: jsonStringAndroid,
          Platform: plattformAndroid
        }
  ]
});
1 Like 1 ·
arda avatar image arda Citrus Yan commented ·

Hi Citrus Yan, thanks for your reply, the code you provided is working but only when both of the players already in game. If message receiving phone is not in game, nothing happens, no notifications, no error logs. It's working perfectly if I use "Package" instead of "AdvancedPlatformDelivery" but I cannot use time_to_live on "Package" right? I'm trying to implement an invite system for in-game friends, it's working but there's no point doing that if that notification going to be received after being offline for hours, so that's why I need a ttl for it.

0 Likes 0 ·
image-1.png (15.0 KiB)
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.