Glavin001 / SMMApp2

Saint Mary's Mobile App, Version 2.0 @
http://society.cs.smu.ca:7000
2 stars 0 forks source link

Push Notifications (SMS/Email Notifications) #10

Open Glavin001 opened 10 years ago

Glavin001 commented 10 years ago

http://blog.mashape.com/post/56272188360/list-of-50-sms-apis

Twilio integration: https://www.twilio.com/blog/2013/03/introducing-the-twilio-module-for-node-js.html

Notifications:

Danlock commented 10 years ago

@Glavin001 you mentioned about a free twilio trial account, did you make one already?

Danlock commented 10 years ago

also twilio trial accounts can only send SMS messages to phone numbers registered with twilio, im unable to find any other SMS service that looks any better tho

Glavin001 commented 10 years ago

@danlock I made a personal account but we should be able to just switch between each of our personal accounts -- have a configuration file that is loaded and each of ours will have our own account info. So 140 SMS each * 4 of us.

Yeah I couldn't find a better one either.

Glavin001 commented 10 years ago

Another interesting article on Node.js and Twilio SMS: https://www.twilio.com/blog/2012/09/building-a-real-time-sms-voting-app-part-1-node-js-couchdb.html

Glavin001 commented 10 years ago

For email: https://github.com/niftylettuce/node-email-templates

Danlock commented 10 years ago

i pushed up a push notifications module, but for some reason twilio isnt verifying any bahamian phone numbers i give it so i cant get a twilio number to test the code i made a twilio-cred file, if you put your twilio account creds there and your twilio number it should be able to work

Glavin001 commented 10 years ago

Awesome, @Danlock ! I'll take a look now.

Glavin001 commented 10 years ago

We now have a configuration module that is used.

Pull my branch:

git pull origin glavin

And the run our app:

node app.js

And it will create a copy of config.custom.sample.js to config.custom.js. You can quit our app. Edit config.custom.js to something like mine:

/**
Custom Configuration
This will take in the argument `config` and manipulate it's configuration values.
*/
module.exports = function(config) {

    // Server configuration
    config.server.production = true;
    config.server.multiCore = true;
   /*
// FOR WINDOWS:
config.server.redis.enabled = false;
*/ 

    // Twilio
    config.twilio.sid = "ACb08acfcdb50c00b820068d14fa4b5956";
    config.twilio.token = "598cfa4d5ea98c2e6adb5afa52956b51";
    config.twilio.number = "+17787620482"; // A number you bought from Twilio and can use for outbound communication

};

Yours will of course have different authentication values for Twilio.

Now run our app again:

node app.js

And you should be using your new custom configuration. The config.js contains all of the defaults.

To use in your own Node.js module call:

var config = require("./config");

Note that you may have to use the following since the relative path is different inside ./app/server/modules/:

var config = require("./../../../config");
Glavin001 commented 10 years ago

Our internal API should all funnel down to a NotificationCenter, that will organize all push notification requests of various types.

For example:

// User object, containing properties for id, name, optional phone number, email, etc
var User = ...; 

// Notification Options
var options = { 
   web: true // Sent to Web app, via Socket.io
   , sms: true // Text message to User's phone number
   , voice: false // Twilio TwiML, Text to Speech to Users' phone number
   , email: true // Email to User's email
   , message: "This is the message." // Plain text message, for SMS and Voice
   , htmlMessage: "<strong>This is the message.</strong>" // HTML message, for Email body
};

// Send notification to User
NotificationCenter.send(User, options, function(error, result) {
   if (!error) {
      // Successful
      console.log(result);
   } else {
      // Error
      console.error(error);
   }
});

The NotificationCenter module requires the Email and Twilio modules and handles them accordingly. It will also use the config module:

// Configuration Module
var config = require("../../../config"); // Relative path to ./app/server/modules/

// Check if Email is enabled
console.log( config.email.enabed );
// Check if Twilio is enabled
console.log( config.twilio.enabled );
Glavin001 commented 10 years ago

@Danlock, would you be interested in working on #52, if you finish this?