Notifications

Notifications may be sent from a script.

Sending

import notifications from 'notifications'

Define custom endpoints:

return notifications.send('c_axon_leave_study', {
  var1: 'test1',
  var2: 'test2'
}, {
  endpoints: {
    push: {
      template: 'message as template {{var1}}',
      apn: {
        topics: [
          'app',
          'voip'
        ]
      }
    }
  }
})

Define custom HTML:

return notifications.send('c_axon_leave_study', {}, {
  endpoints: {
    email: {
      recipient: 'valid@example.com',
      template: null,
      message: 'testing',
      html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
    }
  }
})

Send a predefined notification:

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  notification: 'c_test_not'
})

Send an empty notification:

import constants from 'constants'

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  notification: constants.emptyId,
  endpoints: {
    email: {
      template: null,
      message: 'testing',
      html: '<html></html>'
    }
  }
})

Send a notification without a template or that is not predefined:

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  endpoints: {
    push: {
      message: 'test',
      apn: {
        topics: apnsTopics
      }
    }
  }
})

Send a Short Message Service (SMS) request to a custom mobile number using an existing template:

return notifications.send({ age: '32' }, {
  endpoints: {
    sms: {
      template: 'c_sms_template',
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a custom mobile number without a template:

return notifications.send({}, {
  endpoints: {
    sms: {
      message: 'Medable rocks!',
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a custom mobile number without a template (example 2):

return notifications.send('Medable rocks!', {}, {
  endpoints: {
    sms: {
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a recipient without a template:

return notifications.send('Medable rocks!', {}, {
  endpoints: {
    sms: {}
  },
  recipient: 'valid@example.com'
})

Push a mobile notification to a recipient using an existing template:

return notifications.send({
  text1: 'Medable rocks!'
}, {
  endpoints: {
    push: {
      template: 'c_push_test',
      apn: {
        topics: ['app'],
        pushType: 'alert'
      }
    }
  },
  recipient: 'valid@example.com'
})

Push a mobile notification to a recipient using an existing template:

return notifications.send({}, {
  endpoints: {
    push: {
      message: 'Medable rocks!',
      apn: {
        topics: ['app'],
        pushType: 'alert'
      }
    }
  }
  recipient: 'valid@example.com'
})

Send an email using an existing template:

return notifications.send({
  name: 'Adam',
  email: 'valid@example.com'
  account_id: '12345',
  study_name: 'Study',
  study_code: '00001',
  study_id: '12345'
}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      template: 'c_axon_leave_study'
    }
  }
})

Send an email with HTML and no template:

return notifications.send({}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      subject: 'Medable',
      html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
    }
  }
})

Send an email with a plain message and no template:

return notifications.send({}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      subject: 'Medable',
      message: 'Medable rocks!'
    }
  }
})

Legacy

const payload = {
  var1: 'test1',
  var2: 'test2'
}

notifications.send('c_axon_leave_study', payload)

notifications.send('c_axon_leave_study', payload, {
  apnsTopics: [
    'app',
    'voip'
  ],
  fcmTopic: 'all-devices',
  recipient: 'valid@example.com'
})

return

send(name, variables, options)

Arguments

  • name { String } Notification name

  • variables { Object } Variables to be used in templates

  • options { Object } [Optional]

    • number { String } Sender number

    • recipient { ObjectID, String } ObjectID from account or email

    • context { Object }

    • locale { String } For example, 'en_US'

    • apiKey { String }

    • count { Number } If set, sets the badge on the device icon

    • sound { String } If provided, overrides the default sound

    • apnTopics { String [] }

    • fcmTopic { String [] }

    • pushType { String } Applies only for Apple Push Notification (APN)

send(payload, options)

Arguments

  • payload { Object | String | Number } In case of string, used as payload only; if not, starts with c_ or __ or not in system notification names

  • options { Object } [Optional]

    • context { Object }

    • locale { String } For example, 'en_US'

    • apiKey { String }

    • endpoints { Object }

      • email { Object }

        • recipient { ObjectID | String } ObjectID from account or email

        • template { String }

        • message { String } Plain text message

        • html { String } HTML message

      • push { Object }

        • template { String }

        • message { String }

          • apn { Object }

            • topics { String [] }

            • pushType { String }

          • fcm { Object }

            • topic { String }

          • tpns { Object }

      • sms { Object }

        • mobile { String } Recipient phone number

        • number { String } Sender number

        • message { String }

View Tencent Push Notification Service (TPNS) for more information about Tencent API push notifications.

Last updated