Sign In Register

How can we help you today?

Start a new topic
Answered

Push notifications and custom JSON

Hi, 


I'm trying to customize the JSON payload of my push notifications in cloud code. In particular I'd like to use `loc-key` to send localized messages and `loc-args` to include the player name in the message -- hence I cannot just create a static script message extension. But I cannot get it to work and am not sure how the JSON relates to / integrates with the standard message's configured Message, Title and SubTitle fields

  • Sending custom JSON payload via "Test certificate" in Integrations works like a charm
  • When I create a script message extension and try `message.setMessageData(...)` the push notification is always showing the default message (Message field) configured in the script message extension
  • When I create a script message using the below code, the push notification received shows "ScriptMessage" rather than "Test" (I'm guessing the 'default' default message)

var payload = {};
payload.badge = 1;
payload.alert = "Test";

var message = Spark.message();
message.setSendAsPush(true);
message.setSendViaSocket(false);
message.setMessageData(payload);
message.setPlayerIds(allUserIds);
message.send();

 

I saw there was upcoming support for this about half a year ago but not sure about its current status:
https://support.gamesparks.net/support/discussions/topics/1000068414

Any help is appreciated.


Best Answer
Hi Ivo

In the message set up you can set the default message, title and subtitle to read in from the cloud code using ${data.key}
for example ${data.message} will read in "Test" if set in code
message.setMessageData({"message":"Test"};

Regards
Katie

 


Is it in any way possible to use placeholder variables (something like ${myVar} ) in the JSON Template of the advanced configuration of ScriptMessage extensions? That would also solve the issue. I saw placeholders like ${who} and ${challenge.challengeName} can be used within the context of standard GS messages but after trying a few tests it seems they don't work for ScriptMessage extensions and the placeholders are copied verbatim. 


Right now I don't seem to have any way to customise the message / payload of push notifications in custom messages using Cloud Code, unless I'm missing something obvious. Which I hope because it seems like such a common use case.

Answer
Hi Ivo

In the message set up you can set the default message, title and subtitle to read in from the cloud code using ${data.key}
for example ${data.message} will read in "Test" if set in code
message.setMessageData({"message":"Test"};

Regards
Katie

 

Thanks Katie, works like a charm. Also works in the JSON template of the advanced configuration, awesome!

While we're at it, any way to do the same with the badge number? The JSON expects a number but the placeholder variables are strings.


So something like 

{"aps":{"badge":"${data.badgeNr}", "alert": ...

 

in the JSON template does not work.

did you get the badge number to work? I'm having the same issue

Hi One More Turn,


Sorry, we ended up just always using a static badge number (1). If you still need this, maybe good to open a new ticket as this one is marked as Answered.


1 person likes this
Login to post a comment