npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonis-notifications

v1.1.2

Published

The Adonis Notifications package.

Downloads

92

Readme

Adonis Notifications

A provider for easy sending notifications (Inspired Laravel Notifications)

Build Status Coverage Status

Installation

  1. Add package:
$ npm i adonis-notifications --save

or

$ yarn add adonis-notifications
  1. Register providers inside the your start/app.js file.
const providers = [
  ...
  'adonis-notifications/providers/NotificationsProvider',
  ...
]
const aceProviders = [
  ...
  'adonis-notifications/providers/CommandsProvider',
  ...
]
  1. Notifications table
./ace run notifications:setup

Examples

// app/Model/User.js

...
class User extends Lucid {
  static get traits () {
    return [
      '@provider:Morphable',
      '@provider:HasDatabaseNotifications',
      '@provider:Notifiable'
    ]
  }
}
...

This package used adonis-lucid-polymorphic for database channel.

// app/Notifications/TestNotification.js

...
class TestNotification {
  static get type () {
    return 'test'
  }

  via () {
    return ['database']
  }

  toJSON () {
    return {
      foo: 'bar'
    }
  }
}
...
// app/Http/routes.js

const Notifications = use('Notifications')

...

  // from model instance
  const user = await User.find(1)
  await user.notify(user, new TestNotification())
  // to one user
  const user = await User.find(1)
  await Notifications.send(user, new TestNotification())
  // to many users
  const users = await User.query().fetch()
  await Notifications.send(users, new TestNotification())

...

Custom Channels

// app/providers/YourProvider.js

...

boot () {
  const NotificationManager = this.app.use('Notifications')
  NotificationManager.extend('custom', () => {
    return new CustomChannel()
  })
}

...

On-Demand Notifications

const FcmMessage = use('FcmMessage')
const Notifications = use('Notifications')

class PushTestNotification {
  constructor (animal) {
    this.animal = animal
  }

  static get type () {
    return 'pushtest'
  }

  via () {
    return ['fcm']
  }

  toFcm () {
    const message = new FcmMessage()
    switch (this.animal) {
      case 'cat':
        message.addNotification('title', 'Cat')
        message.addNotification('body', 'Meow!')
        message.addNotification('icon', 'cat_black')
        message.addNotification('color', '#ffab00')
        message.addNotification('sound', 'default')
        message.addData('animal', 'cat')
        break

      case 'cow':
        message.addNotification('title', 'Cow')
        message.addNotification('body', 'Moo!')
        message.addNotification('icon', 'cow_black')
        message.addNotification('color', '#aeaeaf')
        message.addNotification('sound', 'default')
        message.addData('animal', 'cow')
        break

      case 'dog':
        message.addNotification('title', 'Dog')
        message.addNotification('body', 'Woof!')
        message.addNotification('icon', 'dog_black')
        message.addNotification('color', '#b19267')
        message.addNotification('sound', 'default')
        message.addData('animal', 'dog')
        break

      case 'duck':
        message.addNotification('title', 'Duck')
        message.addNotification('body', 'Quack!')
        message.addNotification('icon', 'duck_black')
        message.addNotification('color', '#bd7f00')
        message.addNotification('sound', 'default')
        message.addData('animal', 'duck')
        break

      case 'pig':
        message.addNotification('title', 'Pig')
        message.addNotification('body', 'Oink!')
        message.addNotification('icon', 'pig_black')
        message.addNotification('color', '#d37b93')
        message.addNotification('sound', 'default')
        message.addData('animal', 'pig')
        break

      default:
        message.addNotification('title', 'Animal')
        message.addNotification('body', 'A wild animal has appeared!')
        message.addNotification('sound', 'default')
        break
    }
    return message
  }
}

Notifications
  .route('fcm', '<DEVICE_TOKEN>')
  .notify(new PushTestNotification('cat'))

Channels

Credits

Support

Having trouble? Open an issue!

License

The MIT License (MIT). Please see License File for more information.