Page 1 of 1

Admin notification

Posted: Fri Feb 27, 2015 9:56 pm
by Sunita

Hi,

I am a somewhat functional app, with a couple of user inputs that are stored in a database along with their userID. I want to know how can the admin (me) know there has something been added to a database by any user? Is there some kind of notification system?

Many thanks


Admin notification

Posted: Sat Feb 28, 2015 2:56 am
by Bruce Stuart

Hello Sunita,

The first thing that comes to my mind is 'server code' plus sendgrid email but there are options.

Basically, an outline of a solution I would propose would be as follows:

  1. All of the collections in Appery have a built in column for date added and date last changed. Depending on your needs .... You could key off either to create the notification. ( more below ).

  2. Decide how you'd like to get the notification and what mechanisms you'd like to use to get it. Here are a few options:

    How to get the notification:
    A. Email with server code
    B. Push notification ... Like the ones you get from a lot of apps ( Facebook for example or here in the US - Groupon. ) server code for the push notifications perhaps.
    C. A query in a separate version of your app that you login to. - and it displays the results when you login credentials are sued. You'd build the query and perhaps attach it to a button that only shows when you ... The admin ... Logs in.

    If you think about which method sounds best for your use case ... I could send along links to documentation, and some examples....

    Best,
    Bruce


Admin notification

Posted: Sat Feb 28, 2015 12:31 pm
by Sunita

Hi Bruce,

Thank you so much for your response.

I feel I prefer the Email with server code notification for admin. Could you please link documentation, examples?

Many thanks,
Sunita


Admin notification

Posted: Sat Feb 28, 2015 8:48 pm
by Bruce Stuart

Sunita,

not sure if you've followed this tutorial yet... but here is the link to the server code tutorial... recommended highly ( you may already have done this... but just in case you need some familiartiy with the tools ...):

http://devcenter.appery.io/tutorials/...

there are two basic pieces of knowledge you need to be successful with your goal... how to query your database with a date field, and iterate through the results , and another .... sending an email.


Admin notification

Posted: Sat Feb 28, 2015 9:09 pm
by Bruce Stuart

here is a server code example of creating an email. please note that to send an email using this code, i utilize the sendgrid api ... supported as an integration with Apppery.... get an account here : www.sendgrid.com ( $10 a month for 40,000 emails )

var sendURL = "https://api.sendgrid.com/api/mail.sen...";
var apiuser = "yoursendgriduserid";
var apikey = "yoursendgridpassword";
var requestParameters = {
"parameters": {
"subject": "This is a test email",
"text": avariableherewiththecontentofyourmessage,
"from": "Yourauthorizedsnedgridemailaddressonyouraccount",
"to:": "a href="mailto:sendtoaddress@somedomain.com" rel="nofollow"sendtoaddress@somedomain.com/a",
"api_user": apiuser,
"api_key": apikey
}
};

Code: Select all

 try { // sending the api call 
   var XHRResponse = XHR.send("POST", sendURL, requestParameters); 
   response.success(XHRResponse); 
   responseBody.emailsSent = ncounter + 1; 
   console.log('emails sent:' + parseInt(ncounter + 1)); 
   // console.log('successful email to :' + strIngvarwiththtetoaddress ); 
 } catch (e) { 
   console.log('there was an error in the mail send API call: ' + e.message + ' Error ncode was:' + e.code); 
 } // end sending the api call catch 

please note... be sure to have server code where you have logged in and set up respondbody etc prior to inserting this code and customizing for your use..


Admin notification

Posted: Sat Feb 28, 2015 9:42 pm
by Bruce Stuart

Sunita, for the server code to query your db on date ... I have some libraries I use for manipulating dates from dates to strings etc ... And I'd like to send those by email ... Send me your email address at a href="mailto:Jbrucestuart@comcast.net" rel="nofollow"Jbrucestuart@comcast.net/a and I'll send the code example and my sample date library ...

Best,
Bruce