Webhook Notification Channel for adonis-notifications.
- Add package:
$ npm i adonis-webhook-notification-channel --save
or
$ yarn add adonis-webhook-notification-channel
- Register provider inside the your
start/app.js
file.
const providers = [
...
'adonis-webhook-notification-channel/providers/WebhookNotificationChannelProvider',
...
]
// 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!!!`
}
}))
...
Having trouble? Open an issue!
The MIT License (MIT). Please see License File for more information.