Notifications
Notifications may be sent from a script.
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: '[email protected]',
template: null,
message: 'testing',
html: '<html><p>Medable rocks!<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: '[email protected]'
})
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: 'val[email protected]'
})
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: '[email protected]'
})
Send an email using an existing template:
return notifications.send({
name: 'Adam',
email: '[email protected]'
account_id: '12345',
study_name: 'Study',
study_code: '00001',
study_id: '12345'
}, {
endpoints: {
email: {
recipients: [
],
template: 'c_axon_leave_study'
}
}
})
Send an email with HTML and no template:
return notifications.send({}, {
endpoints: {
email: {
recipients: [
],
subject: 'Medable',
html: '<html><p>Medable rocks!<p></html>'
}
}
})
Send an email with a plain message and no template:
return notifications.send({}, {
endpoints: {
email: {
recipients: [
],
subject: 'Medable',
message: 'Medable rocks!'
}
}
})
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: '[email protected]'
})
return
Arguments
name
{ String } Notification namevariables
{ Object } Variables to be used in templatesoptions
{ Object } [Optional]number
{ String } Sender numberrecipient
{ ObjectID, String } ObjectID from account or emailcontext
{ Object }locale
{ String } For example, 'en_US'apiKey
{ String }count
{ Number } If set, sets the badge on the device iconsound
{ String } If provided, overrides the default soundapnTopics
{ String [] }fcmTopic
{ String [] }pushType
{ String } Applies only for Apple Push Notification (APN)
Arguments
payload
{ Object | String | Number } In case of string, used as payload only; if not, starts withc_ or __ or not
in system notification namesoptions
{ Object } [Optional]context
{ Object }locale
{ String } For example, 'en_US'apiKey
{ String }endpoints
{ Object }email
{ Object }recipient
{ ObjectID | String } ObjectID from account or emailtemplate
{ String }message
{ String } Plain text messagehtml
{ 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 numbernumber
{ String } Sender numbermessage
{ String }
View Tencent Push Notification Service (TPNS) for more information about Tencent API push notifications.
Last modified 1yr ago