Notify : Message push and report
The notify
is a message push and system notification module provided by EdgerOS for applications. For example, it can notify the system application status, push information to mobile clients and share information with other EdgerOS apps.
User can use the following code to import the notify
module.
var notify = require('notify');
Support
The following shows notify
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
notify.push | ● | ● |
notify.share | ● | ● |
notify Object
notify.push(topic, message[, extra])
topic
{String} Topic of the message.message
{String} Messages to push.extra
{Object} Extra Information.- Returns: {Boolean} Whether the operation was successful.
EdgerOS applications can use this interface to push a notification message to the mobile client. Please make sure that the app has permission to push messages.
Example
notify.push('Work done', 'The current work has been completed.');
extra
can have the following members:
accounts
{Array} EdgerOS acoid array, specify the list of members to receive.templateId
{String} Optional push message template ID for Android vendors, to ensure higher delivery rate. Check Push Message for more information.letter
{Object} Optional property to set options for front-end interaction. For example, bringing up specific application page. Check Share : Share message between apps for more information.
notify.share(eapid, msg)
eapid
{String} EdgerOS App package ID (Bundle ID).msg
{Object} Information to be shared, JSON stringify cannot exceed 14KBytes.- Returns: {Boolean} Whether the operation was successful.
Send sharing message to the specified application.
Example
notify.share('com.acoinfo.xxx', {
type: 'show',
msg: 'This is shared message.'
});
The msg
object is not allowed to contain the from
property, this property will be overwritten by the system, when the target App receives the shared information, from
is current App Bundle ID which called notify.share
.
Share Message Receive
- When the App is already started.
var message = require('message');
message.on('message', function(msg) {
if (msg.from) {
// Shared messages from apps
console.log('received share message from:', msg.from);
} else {
// Shared messages from the system service
}
});
- When the App is launched by sharing information.
var msg = ARGUMENT;
if (msg && typeof msg === 'object') {
if (msg.from) {
// Shared messages from apps
console.log('received share message from:', msg.from);
} else {
// Shared messages from the system service
}
}
- Received a system favorite button click event message.
var message = require('message');
var msg = ARGUMENT;
if (msg && msg.type === 'favorite' && msg.action === 'click' && msg.from === undefined) {
// App launched by system favorite button click event
}
message.on('message', function(msg) {
if (msg.type === 'favorite' && msg.action === 'click' && msg.from === undefined) {
// System favorite button click event catched
}
});