question

regy42 avatar image
regy42 asked

Avoid push notfication errors when sending notification to friends

Hi,

I am trying to create a cloud script that can notify your friends you join the game. I did something like this:

var result = server.GetFriendsList(request);
  if(result.Friends) {
    for (var i = 0; i <  result.Friends.length; i++) {
  		
    	var currId = result.Friends[i].FriendPlayFabId;
      	var request = {
          Recipient: currId,
          Subject:"Your friend's joined the run!",
          Message:  name + " joined the game!"
        };
  		
      try {
       	var notifyResult = server.SendPushNotification(request);
        //log.info(notifyResult);
      } catch (e) {
       	//var msg = "Error: " + JSON.stringify(e);
        //log.info(msg);
      }
    }
    
  }

It partly works, but I want to avoid errors for friends whose don't have any device connected to recieve notification. Try/Catch didn't help, I still get error for each friend without device connected. I just implement registration for push notifications, so in product version every player shoud have a device connected. But I still want to solve this for situation that there is no device registered.

And I have a second question: Is there way to notify all friends with the same notification without sending notifications in a loop? Because in this situation, I reached CloudScript execution API requests limit quickly and I have to split calls for many friends.

Or is there a way to send notification directly from unity API without using cloud script?

Thanks,

Regy

apisCloudScriptPush NotificationsFriends
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

·
brendan avatar image
brendan answered

First things first, you should never iterate across all the player's friends and make a call to the service. And attempting to bypass the limits for a player by calling Cloud Script multiple times is also not something you should do. Those things are pretty much guaranteed to get your title throttled or even blocked, as you would be trying to make potentially hundreds or even thousands of API calls in a short period for a single player. In general, your design should be to make only a few calls per minute, per player, over the lifetime of the player session. Bursts of calls in a short period are fine, as long as the average works out to be lower.

I'd recommend taking a step back and looking at the high level design on what it is you're trying to do. While you could potentially do what you describe by using a bulk Push service, a game that spams every friend of the player every time they play a game is one that's going to generate a lot of "noise" for players - so much so that it would likely irritate players, resulting in abandonment. In general, sending Push messages when they have more relevance to players is a more successful approach - like when a friend beats your score on a leaderboard. For detecting if friends are in a game session, you can use the data returned in the friends list to see what session they're in, if you're using custom game servers.

4 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.

regy42 avatar image regy42 commented ·

Maybe I shoud describe more what I am trying to approach. I only want to send push notification if a friend join the game for the first time (Only when account is created/linked with other account). I know I could make some logic inside the game to check if there is a new friend and show it when game starts. But I think that it's the most important thing to notify, because if your friend joined, it coud extremely improve a player engagement. So is there way to select friends and send them push notification via bulk Push service (as you mentioned) thru playfab?

0 Likes 0 ·
brendan avatar image brendan regy42 commented ·

No, there is not currently a bulk Push notification system, apart from the Segment-based Push you can do via Scheduled Tasks. To do this, you would need to use an external Push service.

0 Likes 0 ·
regy42 avatar image regy42 brendan commented ·

Ok, thanks. And what about avoiding errors in output when trying to send push notification to player without device registered? Is it ok to just ignore errors or is there some better way, like check if user can receive notifications (but it will increase API calls I think)? Why error appears in output when I use try/catch construct?

0 Likes 0 ·
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.