# notificator

> Library for handling custom notifications, emails, APS, GCM...

Latest version **0.4.10** (published 2016-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install notificator
pnpm add notificator
yarn add notificator
bun add notificator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.10 |
| Published | 2016-03-15 |
| First published | 2015-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+17 in 3 direct dependencies) |
| Install scripts | no |
| Author | Jakub Knejzlik |
| Maintainers | jakub.knejzlik |
| Keywords | notifications, push, aps, apns, gcm |

## Links

- npm: https://www.npmjs.com/package/notificator
- Repository: https://github.com/jakubknejzlik/node-notificator
- Issues: https://github.com/jakubknejzlik/node-notificator/issues
- npm.io page: https://npm.io/package/notificator

## Dependencies (8)

- [q](https://npm.io/package/q.md) ^1.4.1
- [apn](https://npm.io/package/apn.md) ^1.7.5
- [swig](https://npm.io/package/swig.md) ^1.4.2
- [async](https://npm.io/package/async.md) ^1.4.2
- [extend](https://npm.io/package/extend.md) ^3.0.0
- [node-gcm](https://npm.io/package/node-gcm.md) ^0.12.0
- [validator](https://npm.io/package/validator.md) ^4.1.0
- [nodemailer](https://npm.io/package/nodemailer.md) ^1.8.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.4.10 (latest) — 2016-03-15
- 0.4.9 — 2016-02-12
- 0.4.8 — 2016-01-22
- 0.4.7 — 2016-01-06
- 0.4.6 — 2016-01-05
- 0.4.5 — 2016-01-05
- 0.4.4 — 2016-01-05
- 0.4.3 — 2016-01-05
- 0.4.2 — 2016-01-05
- 0.4.1 — 2015-12-22
- 0.4.0 — 2015-12-22
- 0.3.4 — 2015-12-18
- 0.3.3 — 2015-12-15
- 0.3.2 — 2015-12-15
- 0.3.1 — 2015-12-15
- … 25 more at https://npm.io/package/notificator/versions

## README

# Notificator

[![Build Status](https://travis-ci.org/jakubknejzlik/node-notificator.svg)](https://travis-ci.org/jakubknejzlik/node-notificator)


Create notificator, specify channels and their logic of what, when and who send messages to (e-mail,apns, gcm). All in one place...and in your code use just notificator.notify('event',receiver,data).


# Example

```
Notificator = require('../index')


notificator = new Notificator({
    logging: false, // log messages
    dummy: false // don't send notifications (used for tests)
})

notificator.registerEvent('test') // you can specify wich events are valid


// create your channels

var messageData = {key:'value'}

// use your own model logic, this object is sent to getDestinations method as receiver (you can use for example sequelize object).
// also accepts array of receivers
var receiver = {};
notificator.notify('test',receiver,messageData,{channels:['gcm']})
    .then(done)
    .catch(done)

// or to notify directly
var destination = 'john.doe@example.com'; // also accepts array
notificator.notifyDestination('test','email',destination,messageData)
    .then(done)
    .catch(done)

```

### Email Channel
```
var emailChannel = new Notificator.EmailChannel({
  getDestinations:function(receiver, callback){
    callback(null,[{destination:receiver.email}]) // suppose we have (for example sequelize) user with email attribute
  }
  getTemplates:function(info,callback){
    var template = {
      subject:'default subject {{receiver}}',
      text:'default email body {{receiver}} {{JSON.stringify(_data)}}',
      html:'default email HTML body {{receiver}}'
    }
    callback(null,[template])
  }
//  defaultTemplate:defaultEmailTemplate,
  service: 'MailGun',
  auth: {
    user: 'no-reply@...',
    pass: ''
  }
})

notificator.addChannel('email',emailChannel)
```

### APNS Channel

```
var apnsChannel = new Notificator.APNSChannel({
  getDestinations:function(receiver, callback){
    receiver.getApnsDevice().then(function(device){ // suppose we have (for example sequelize) user object with apnsDevice
        callback(null,[{destination:device.token,language:device.language}]);
    }).catch(callback)
  }
  getTemplates:function(info,callback){
    template = {alert:'{{value}} notification test' + info.event + '_' + info.language,badge:'{{value+1}}'}
    callback(null,template)
  },
  feedbackHandler:function(items){
    items.forEach(function(item){
        console.log('disable destination:',item.destination,'disabled since:',item.date)
    })
  }
  feedbackInterval: 600,
  cert:fs.readFileSync(__dirname + '/apns-cert.pem'),
  key:fs.readFileSync(__dirname + '/apns-key.pem'),
  passphrase:'blah',
  production:true
})

notificator.addChannel('apns',apnsChannel)
```

### GCM Channel

```
var gcmChannel = new Notificator.GCMChannel({
  getDestinations:function(receiver, callback){
    receiver.getGcmDevice().then(function(device){ // suppose we have (for example sequelize) user object with gcmDevice
      callback(null,[new Notificator.GCMChannel.Destination(device.token,device.language)]);
    }).catch(callback)
  },
  getTemplates:function(info,callback){
    template = new Notificator.GCMChannel.Template({
      data:{
        title:'{{value}}' + info.event + '_' + info.language,
        message:'{{value}} body'
      }
    })
    callback(null,template)
  },
  apiKey:'...'
})

notificator.addChannel('gcm',gcmChannel)
```

---
_Source: https://npm.io/package/notificator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
