Skip to content

enniel/adonis-webhook-notification-channel

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published