1.0.0 • Published 7 years ago
adonis-webhook-notification-channel v1.0.0
Adonis Webhook Notification Channel
Webhook Notification Channel for adonis-notifications.
Installation
- Add package:
 
$ npm i adonis-webhook-notification-channel --saveor
$ yarn add adonis-webhook-notification-channel- Register provider inside the your 
start/app.jsfile. 
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 = MyNotificationconst 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.
1.0.0
7 years ago