Sign In Register

How can we help you today?

Start a new topic

Broadcast push notification

I was trying to get push notifications to work. I am running Unity + GS + Android. From the FCM tutorial it looks like its a request that is initiated from the app or client and then I need to setup GS to respond to that ? Is there a way where I can broadcast a push notification from GS (and not be it a part of Request/Response ?)


1 person has this question

Hey Priyank,

Yes, you can.
You need to setup a new ScriptMessage and give it some settings (these can be modified in code so dont worry about them too much. The important ones are your socket/push options).

Once you have that setup, you will need to create and event or a scheduler where you will write the logic for when and who the message gets sent to. You need the shortCode of your scriptMessage and the player you need to send it to.

Then, to send a message in your script you can use the following...

var mess = Spark.message("ScriptMessageShortCode");
mess.setPlayerIds(Spark.getPlayer().getPlayerId())
mess.send();

I wouldnt advise sending out messages to all players at once. If you need to do this for a campaign or something, then do some checks to reduce the player you send to, like checking online players or only player active in the last month, etc.

If you have a case where you need to send messages to thousands of players at once, you should use a bulk job for this to ensure the script doesnt timeout.

Let us know if you have any more questions,
Thanks,
Sean


 

Thanks for the prompt response Sean. 1. Where would I run that snippet of code from ? 2. Which players will it target when I use Spark.getPlayer().getPlayerId() ? I'm trying to get proof of concept working before I integrate it in the main game, so for now I run my game on the emulator and phone and I'm trying to have both of those receive this push notification. As an extension, can you tell me how can I send a notification to all the authenticated players ? I can later filter that to lesser players as I learn more about the system.

 This would require a lot of custom setup.


Firstly, you need to create a custom player collection. You can see how to do this at the start of the tutorial here.

Once youve got this list you can query player however you want to get a list of ID. You would then pass those IDs into a bulk-job so you can send as many messages as you want.


I cant tell you where you'd need to run the code from. I'd need to know what you intend to send to the players to advise you further on that.


1 person likes this
Thanks, feels like I'm close to what I want to do. Have a follow-up question. In the doc it mentions, You can send a bulk job request in Cloud Code in two ways: Building a bulk job via request builder. Sending it via Spark.sendRequest. How can I get to the request builder ? How can I invoke spark.sendrequest ? One of the biggest thing I am struggling with is finding where to access or run certain things from. For someone new, I'd say this is a part of the learning curve which is steeper than I expected it to be. Thanks for sharing those references.
Login to post a comment