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:
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"};
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.
Customer Support
said
almost 6 years ago
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
I
Ivo Swartjes
said
almost 6 years ago
Thanks Katie, works like a charm. Also works in the JSON template of the advanced configuration, awesome!
I
Ivo Swartjes
said
almost 6 years ago
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.
O
One More Turn
said
over 5 years ago
did you get the badge number to work? I'm having the same issue
I
Ivo Swartjes
said
over 5 years ago
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
P
Peter Wiseman
said
about 3 years ago
Has anyone figured out if there's a way to set the badge number in the template as a number rather than a string? My json template is this:
{
"aps": {
"alert": {
"title": "${data.title}",
"body": "${data.body}"
},
"badge": "${data.count}",
}
}
but the badge is being sent as a string instead of a number and iOS doesn't like that. Any workarounds?
Ivo Swartjes
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
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstIvo Swartjes
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.
Customer Support
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
Ivo Swartjes
Thanks Katie, works like a charm. Also works in the JSON template of the advanced configuration, awesome!
Ivo Swartjes
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
in the JSON template does not work.
One More Turn
did you get the badge number to work? I'm having the same issue
Ivo Swartjes
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
Peter Wiseman
Has anyone figured out if there's a way to set the badge number in the template as a number rather than a string? My json template is this:
{
"aps": {
"alert": {
"title": "${data.title}",
"body": "${data.body}"
},
"badge": "${data.count}",
}
}
but the badge is being sent as a string instead of a number and iOS doesn't like that. Any workarounds?
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics