NodeJS Library to push on iPhone, Android, WindowsPhone.
node-sender can be easily and simply send push notifications on major existing mobile systems.
npm install node-sender
You need to import the sender library.
varSender=require('node-sender');varsender=Sender.send({log : log,// Bunyan logger instance (optional)type : Sender.constants.TYPE_ANDROID,// OS typemessage : {title : "your title",// notification title body : "Test android push",// message to send (optional)any_other_Key : "that you want to send"// other data you want to send, see GCM's doc},tokens : ["your token"],// phone(s) registration id(s)config : {apiKey : "GCM Api-KEY",ttl : 7200// Time to live, (optional, default = 3600 = 1h)}});varSender=require('node-sender');varsender=Sender.send({log : log,// Bunyan logger instance (optional)type : Sender.constants.TYPE_IOS,// OS typemessage : {alert : "your notification",// message to sendbadge : 1,// your badgesound : "cat.caf"// your notification sound},tokens : ["your token"],// phone(s) registration id(s)config : {cert : "path to your cert file",key : "path to your key file",ttl : 7200,// Time to live, (optional, default = 3600 = 1h)production : true// If your application is on the production APNS}});varsender=Sender.send({log : log,// Bunyan logger instance (optional)type : Sender.constants.TYPE_WP,// OS typemessage : {msge : "Message "// message to send},tokens : {url : ["tokenUrl,...."]// phone(s) registration id(s)},config : {sid : "your sid",// Package Security Identifier (SID)secret : "your secret",// Secret passwordttl : 7200// Time to live, (optional, default = 3600 = 1h)}});❗ Important: You can't use the both system at the same time !
You can use the callback system like that (the token and config SID/Secret are wrong ;) )
Sender.send({type : Sender.constants.TYPE_WP,message : {msge : "My beautiful notification"},tokens : {url : ["AOBCIAHJSJAOPFIABFNHAONODBF"]},config : {sid : "ogdjqfqopfnsdopbgfdoqfn",secret : "fdognpsdfogopdfgjonfdgodfgn",}},(error,result)=>{if(!error){console.log(result.successful);console.log(result.failed);console.log(result.unregistered);}});Or you can use the EventEmitter system
varsender=Sender.send({type : Sender.constants.TYPE_WP,message : {msge : "My beautiful notification"},tokens : {url : ["AOBCIAHJSJAOPFIABFNHAONODBF"]},config : {sid : "ogdjqfqopfnsdopbgfdoqfn",secret : "fdognpsdfogopdfgjonfdgodfgn",}});sender.on("error",(err)=>{// When there is an error, it triggers this event.});sender.on("successful",(token)=>{// Each successful push triggers this event // with the token and message_id.});sender.on("failed",(error)=>{// Each failed push triggers this event with the // token and the statusCode or error.});sender.on("unregistered",(token)=>{// Each push where the device is not registered (uninstalled app) // triggers this event instead of the "failed" event.});sender.on("end",(results)=>{// Contains success, failed and unregistered arrays of // notifications responses data // (if there are some).console.log(results.successful);console.log(results.failed);console.log(results.unregistered);});- Refactor Android push system
- Implement Apple Feedback system
- Implement WNS Feedback system
- Implement GCM Feedback system
- Add event pattern to send push fail
Use abstract pattern for the three libs
