# pronto-notification-service

> Support for notifications across platforms (email, sms, push). Pluggable platform providers. Boilerplate for checking user settings. Standardized templating from platform events.

Latest version **0.0.2** (published 2018-03-22) · 0 weekly downloads

## Install

```sh
npm install pronto-notification-service
pnpm add pronto-notification-service
yarn add pronto-notification-service
bun add pronto-notification-service
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-03-22 |
| First published | 2018-03-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Prontotype |
| Maintainers | spro |

## Links

- npm: https://www.npmjs.com/package/pronto-notification-service
- Repository: https://github.com/prontotype-us/pronto-notification-service
- Homepage: https://github.com/prontotype-us/pronto-notification-service#readme
- Issues: https://github.com/prontotype-us/pronto-notification-service/issues
- npm.io page: https://npm.io/package/pronto-notification-service

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^2.1.4
- [somata](https://npm.io/package/somata.md) ^0.3.1

## Recent versions

- 0.0.2 (latest) — 2018-03-22
- 0.0.1 — 2018-03-05

## README

# Notification Service

Support for notifications across platforms (email, sms, push). Pluggable platform providers. Boilerplate for checking user settings. Standardized templating from platform events.

## Usage

You build a Notification Service with a configuration and a set of notification templates.


### Configuration

Configure the service and any platforms it will use.

in `./config.coffee`

```coffee
module.exports =
    id_key: 'id'
    platform_slug: 'tryna'
    email:
        # email service config
    (sms):
        # sms service config...
    (push):
        # push service config...
```


### Templates

Set up templates for each notification type for notification providers you are using.

in `./templates.coffee`

```coffee
module.exports =
    'announcements:created': (announcement) ->
        {body} = announcement

        return {
            'email':
                type: "text" #or html
                subject: "New announcement from Platform Name."
                body: "#{body}"
            'sms': "Platform Name announcement: #{body}"
        }

```

If you want to send an html email, compile the html in your `templates.coffee` file and pass it into the body of your template.


### Run the Service

```coffee
somata = require 'somata'

templates = require './templates'
config = require './config'

Notifications = require('notification-service')(config, templates)
{notifyUser, notifyUsers, notifyContacts} = Notifications

client = new somata.Client
DataService = client.remote.bind client, 'tryna:data'

# Set up any schema update notifications
# -----------------------------------------------------------------------------

applySubscriptions = (S) ->
    Object.keys(S).map (s_k) ->
        client.subscribe 'tryna:data', s_k, S[s_k]

subscriptions = {

    "announcements:created": (event) ->
        {
            DataService 'find', 'users', {}, (err, all_users) ->
                notifyUsers all_users, "app_invites:created", event.item, ->
        }
}

applySubscriptions(subscriptions)

# Export any utility functions you'd like from the service
# -----------------------------------------------------------------------------

service = new somata.Service 'tryna:notification', {
    notifyUser
    notifyContact
}
```


### API

A user is a person who has signed up / logged into an app.

A contact is a person with a record that has at least an email/phone and maybe more data. Currently the Notification Service can view a User or pieces of the user as a Contact if it needs to. Notification kinds should look as much as possible like "[type]:[event]", like "invite:created" or "tryna:updated", keyed off of raw schema notifications. More custom kinds like "my-special-invite" may also be appropriate as long as you think you can keep the templates file scalable.

```
notifyUser(user, kind, context, cb)
notifyUsers(users, kind, context, cb)
notifyContact(contact, kind, context, cb)
notifyContacts(contacts, kind, context, cb)
```

You can send an HTML email by setting the type to 'html' and compiling html from the context within your templates.coffee file.


### TODO:

Consider being able to specify the type of notification to send (email vs. sms, etc). Though this will be mostly contextual or based off user settings.

Pass in custom checking of user setting and app context to stop or send notifications.

Is it necessary to have sms and push be pluggable like email is (for ses/mailgun/etc)?

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