1.0.0 • Published 6 years ago

adonis-webhook-notification-channel v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Adonis Webhook Notification Channel

Webhook Notification Channel for adonis-notifications.

Build Status Coverage Status

Installation

  1. Add package:
$ npm i adonis-webhook-notification-channel --save

or

$ yarn add adonis-webhook-notification-channel
  1. Register provider inside the your start/app.js file.
const providers = [
  ...
  'adonis-webhook-notification-channel/providers/WebhookNotificationChannelProvider',
  ...
]

Usage example

// app/Model/Webhook.js
const Lucid = use('Lucid')

class Webhook extends Lucid {
  static get traits () {
    return [
      '@provider:Notifiable'
    ]
  }

  routeNotificationForWebhook () {
    return this.url
  }
}

module.exports = User
// app/Notifications/MyNotification.js
const WebhookMessage = use('WebhookMessage')

class MyNotification {
  constructor(body) {
    this.body = JSON.stringify(body)
  }

  via () {
    return ['webhook']
  }

  toWebhook () {
    const message = new WebhookMessage()
    message
      .body(this.body)
      .header('content-type', 'application/json')
    return message
  }
}

module.exports = MyNotification
const Notifications = use('Notifications')

...
const webhooks = await Webhook.all()

await Notifications.send(webhooks, new MyNotification({
  payload: {
    text: `It's works!!!`
  }
}))
...

Credits

Support

Having trouble? Open an issue!

License

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