Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

Push notification sent from server code logic

Hello, I have a question about a functionality I need to build. Here is the workflow step by step. Please tell me if this is possible to build.

1) JavaScript function that runs once every 10 hours. This function has logic to check for a certain value from database (i.e. value 10)

2) If value is greater than 10, then it would send out a push notification to user with a question like "Your value is greater than 10, would you like to do something about it - click yes or no". User then clicks 'yes' or 'no' inside push notification

3) User is directed to a page based on their yes or no input

Can you please tell me if this functionality can be implemented in Apperyio and the basic steps to do it. Thanks much!

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Push notification sent from server code logic

Hi Deki.

Yes your functionality could be implemented by appery.io.

Please follow this brief plan:

1 Server code. This is your JS function on server which is make logic you have described.

Read more about it:

http://docs.appery.io/tutorials/creat...

http://docs.appery.io/documentation/b...

2 Server code shedule.

See details: http://prntscr.com/3f9wjz/direct

3 Handle push notification on client part.

Try to pass this tutorial to understand how it work:

http://prntscr.com/3f9wjz/direct

It's very recomended to read given documents to understand basic principals for your app.

Regards.

Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

Push notification sent from server code logic

Ok, I found some info here http://docs.appery.io/documentation/b... Let me read it and I'll ask you if I have any questions

Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

Push notification sent from server code logic

I've read through the documentation. I understand that I can use PN.push function to send a notification. I was able to do this by following the guide here http://docs.appery.io/documentation/b...

However, I have one more question regarding push notifications. How can I make a specific page appear in my app once the user clicks on the push notification.

Here is a sample workflow

1) User receives push notification (app is currently closed)
2) User reads the push notification and clicks on it
3) The app opens to a specific screen in the app

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Push notification sent from server code logic

Dear Deki.

You can add push notification js event handler on your start page(or any other you need).

And implement this event handler with following code: http://prntscr.com/3fcitv/direct

pre
code

alert("notification");

var notificationText = data.aps.alert;

alert("notification text = " + notificationText);

//Note "Screen1" - is the page you would like navigate to, after push received.
navigateTo("Screen1");

/code
/pre

Regards.

Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

Push notification sent from server code logic

I notice that there were some updates to the Push Notifications in Apperyio. I still have this question. How can I send push notification from Server Code script? I notice that I can create a POST service inside the app, but that does not allow me to execute from server script. Can anyone help me how I can do this? Thanks

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Push notification sent from server code logic

Hi Deki,

Here is a code to send push from server code:

pre

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}

//Fill this value with your goal diviceID.
var deviceID = "356253050032875;e2346ae4310aff98";

//Here is should be your pushApiKey
var pushApiKey = "d8587f9b-d5e3-4cd8-98be-7663f4c956c3";

var requestBody = {
"status": "sent",

"payload": {
"message": "Hello World",
},

"filter": {
"deviceID": deviceID
}
};

var request = {

"headers": {

Code: Select all

 "X-Appery-Push-API-Key": pushApiKey, 
 "Content-Type": "application/json" 

},

"body": JSON.stringify(requestBody)

};

var XHRResponse = XHR.send("POST", "https://api.appery.io/rest/push/msg", request);

response.success(XHRResponse, "application/json");

'''

Regards./pre

Return to “Issues”