Search…
Notifications
Notifications may be sent from a script.

Sending

1
import notifications from 'notifications'
Copied!
Define custom endpoints
1
return notifications.send('c_axon_leave_study', {
2
var1: 'test1',
3
var2: 'test2'
4
}, {
5
endpoints: {
6
push: {
7
template: 'message as template {{var1}}',
8
apn: {
9
topics: [
10
'app',
11
'voip'
12
]
13
}
14
}
15
}
16
})
Copied!
Define custom HTML
1
return notifications.send('c_axon_leave_study', {}, {
2
endpoints: {
3
email: {
4
recipient: '[email protected]',
5
template: null,
6
message: 'testing',
7
html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
8
}
9
}
10
})
Copied!
Send pre-defined notification
1
return notifications.send({
2
var1: 'test1',
3
var2: 'test2'
4
}, {
5
notification: 'c_test_not'
6
})
Copied!
Send an empty notification
1
import constants from 'constants'
2
3
return notifications.send({
4
var1: 'test1',
5
var2: 'test2'
6
}, {
7
notification: constants.emptyId,
8
endpoints: {
9
email: {
10
template: null,
11
message: 'testing',
12
html: '<html></html>'
13
}
14
}
15
})
Copied!
Send notification without template or pre-defined
1
return notifications.send({
2
var1: 'test1',
3
var2: 'test2'
4
}, {
5
endpoints: {
6
push: {
7
message: 'test',
8
apn: {
9
topics: apnsTopics
10
}
11
}
12
}
13
})
Copied!
Send SMS to a custom mobile number using existing template
1
return notifications.send({ age: '32' }, {
2
endpoints: {
3
sms: {
4
template: 'c_sms_template',
5
mobile: '+18004444444'
6
}
7
}
8
})
Copied!
Send SMS to a custom mobile number without any template
1
return notifications.send({}, {
2
endpoints: {
3
sms: {
4
message: 'Medable rocks!',
5
mobile: '+18004444444'
6
}
7
}
8
})
Copied!
Send SMS to a custom mobile number without any template v2
1
return notifications.send('Medable rocks!', {}, {
2
endpoints: {
3
sms: {
4
mobile: '+18004444444'
5
}
6
}
7
})
Copied!
Send SMS to a recipient without any template
1
return notifications.send('Medable rocks!', {}, {
2
endpoints: {
3
sms: {}
4
},
5
recipient: '[email protected]'
6
})
Copied!
Push a mobile notification to a recipient using an existing template
1
return notifications.send({
2
text1: 'Medable rocks!'
3
}, {
4
endpoints: {
5
push: {
6
template: 'c_push_test',
7
apn: {
8
topics: ['app'],
9
pushType: 'alert'
10
}
11
}
12
},
13
recipient: '[email protected]'
14
})
Copied!
Push a mobile notification to a recipient using an existing template
1
return notifications.send({}, {
2
endpoints: {
3
push: {
4
message: 'Medable rocks!',
5
apn: {
6
topics: ['app'],
7
pushType: 'alert'
8
}
9
}
10
}
11
recipient: '[email protected]'
12
})
Copied!
Send an email using an existing template
1
return notifications.send({
2
name: 'Adam',
4
account_id: '12345',
5
study_name: 'Study',
6
study_code: '00001',
7
study_id: '12345'
8
}, {
9
endpoints: {
10
email: {
11
recipients: [
14
],
15
template: 'c_axon_leave_study'
16
}
17
}
18
})
Copied!
Send an email with HTML and no template
1
return notifications.send({}, {
2
endpoints: {
3
email: {
4
recipients: [
7
],
8
subject: 'Medable',
9
html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
10
}
11
}
12
})
Copied!
Send an email with plain message and no template
1
return notifications.send({}, {
2
endpoints: {
3
email: {
4
recipients: [
7
],
8
subject: 'Medable',
9
message: 'Medable rocks!'
10
}
11
}
12
})
Copied!

Legacy

1
const payload = {
2
var1: 'test1',
3
var2: 'test2'
4
}
5
6
notifications.send('c_axon_leave_study', payload)
7
8
notifications.send('c_axon_leave_study', payload, {
9
apnsTopics: [
10
'app',
11
'voip'
12
],
13
fcmTopic: 'all-devices',
14
recipient: '[email protected]'
15
})
16
17
return
Copied!

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 } e.g '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 APN

send(payload, options)

Arguments
    payload { Object | String | Number } In case of string, will be used as payload only if not starts with c_ or __ or not in System notifications names
    options { Object } [Optional]
      context { Object }
      locale { String } e.g '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 }
        sms { Object }
          mobile { String } Recipient phone number
          number { String } Sender number
          message { String }
Last modified 1mo ago