The name notifications refer to it by.
A class decorator.
@NotificationChannel('sms')
export class TwilioChannel {
readonly name = 'sms'
constructor ({ twilio }) { this.twilio = twilio }
async send (message, recipient) {
if (recipient.phone === undefined) {
return { status: 'unreachable', retryable: false, reason: 'No phone number.' }
}
await this.twilio.messages.create({ to: recipient.phone, body: message.body })
return { status: 'sent' }
}
}
Declare a class as a notification channel.
The declaration form for a channel of your own, next to the configuration form: this is how
smsandpushare done, and anything else a provider offers. The class is registered as a service, so its constructor is auto-wired like any other, and the channel is registered under the name given here.The class must answer
send(message, recipient)and return an outcome rather than throw, which is the whole port. A channel that throws is treated as retryable.