Skip to content

Latest commit

History

84 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-sender

NodeJS Library to push on iPhone, Android, WindowsPhone.

Presentation

node-sender can be easily and simply send push notifications on major existing mobile systems.

License

Install

npm install node-sender

Quick Examples

At the beginning

You need to import the sender library.

varSender=require('node-sender');

Android (GCM)

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)}});

iOS (APNs HTTP/2)

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}});

Windows Phone (WNS)

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: If there is a parameters problem, it'll be throw and not send through callback or event system !

How to retrieve the failed/successful notifications

❗ Important: You can't use the both system at the same time !

Callback

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);}});
EventEmitter

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);});

TODO

  • 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

Bitdeli Badge

About

NodeJS Library tu push on Iphone, Android, WindowsPhone, Blackberry 5+

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages