Sign In Register

How can we help you today?

Start a new topic

OneSignal or Push with Cloudcode

Hello, Have anyone figured out how to customize the json from the messages to work with onesignal ? I can't figure it out .. And if not, is it possible to intercept a message if it's gonna be send through push and instead extract data from that push and call a http request to onesignals API ?

1 person has this question

I dont understand your question.

All you have to do is set the app_id and the authorization key.

And adjust the parameters to your needs (API is on the OneSignal Doc site).

Looks easy.


What do you have to set before using that code (from Cloud Code, right?) ?

I just use this code :


  

function sendPushYourTurn(playerID)
{
    var jsonBody = {
    
    app_id: "XXX",
    
    include_player_ids : [""+playerID],
    
    android_group_message : {"en" : "You have $[notif_count] turns to make!"},
    
    android_group : "FRIEND_REQUEST",
    
    contents : {"en" : "Its your turn!"},
   
    };
    
    var promise = Spark.getHttp("https://onesignal.com/api/v1/notifications");
    promise = promise.setHeaders({
    
    "Content-Type": "application/json;charset=utf-8",
    
    "Authorization": "Basic KEY"
    
    })
    var t = JSON.parse(JSON.stringify(jsonBody));
    var res = promise = promise.postJson(t);
    var rest = res.getResponseJson();
    return rest;
}

  


1 person likes this

Hey Fabian, did you manage to make it work? I'd like to use OneSignal too but I'm afraid it's complicated to do with GameSparks. Isn't it?

Ok i just need to figure out how to fire up a cloudcode script instead of sending the push notification. Is this possible ?

Login to post a comment