Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by regy42 · Jan 06, 2018 at 11:02 PM · CloudScriptapisPush NotificationsFriends

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

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Jan 06, 2018 at 11:11 PM

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.

Comment

People who like this

0 Show 4 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image regy42 · Jan 06, 2018 at 11:43 PM 0
Share

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?

avatar image Brendan ♦♦ regy42 · Jan 07, 2018 at 04:02 AM 0
Share

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.

avatar image regy42 Brendan ♦♦ · Jan 07, 2018 at 05:01 PM 0
Share

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?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    How to get the value from a variable present in the Cloud Script ? 0 Answers

    Player Name in Push notification template/ Localization of Push notification messsages 1 Answer

    Playfab action-event server system 1 Answer

    Recived notification showing without "Subject" 1 Answer

    DeleteMasterPlayer not working 2 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges