Stone.js API
    Preparing search index...
    • Declare a class as a notification channel.

      The declaration form for a channel of your own, next to the configuration form: this is how sms and push are 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.

      Type Parameters

      • T extends ClassType = ClassType

      Parameters

      • name: string

        The name notifications refer to it by.

      Returns ClassDecorator

      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' }
      }
      }