Skip to main content
Version: 1.34.0

SimplePushNotification

This class contains methods for creating and sending push notifications from the SimpleOne system to user browsers.

Specify recipients

To send a notification, you must specify at least one recipient using the setRecipientUserIds() or setRecipientGroupIds() method. If a specified user belongs to one or more specified groups, the system creates a single recipient record for that user. A single notification can have no more than 1000 unique recipients.

setRecipientUserIds(userIds)


Use this method to set push notification recipients with user IDs. Repeated calls overwrite the value.

Parameter(s):

NameTypeMandatoryDefault value
userIdsArray of StringsYN

Return:

TypeDescription
BooleanReturns true if the value is accepted. Returns false if the value is invalid.

Example:

setRecipientUserIds()
let webpush = new SimplePushNotification();
webpush.setRecipientUserIds(['155931135900000001','155931135900000032']);

setRecipientGroupIds(groupIds)


Use this method to set push notification recipients with group IDs. Repeated calls overwrite the value.

Parameter(s):

NameTypeMandatoryDefault value
groupIdsArray of StringsYN

Return:

TypeDescription
BooleanReturns true if the value is accepted. Returns false if the value is invalid.

Example:

setRecipientGroupIds()
let webpush = new SimplePushNotification();
webpush.setRecipientGroupIds(['177068186608977300']);

Specify notification contents and behavior

caution

The setTitle(title) and setBody(body) methods are mandatory when creating a push notification. They must not be Empty or Null.

setTitle(title)


Use this method to set the push notification title. The title length must not exceed 35 characters. If the value exceeds 35 characters, it is truncated.

Parameter(s):

NameTypeMandatoryDefault value
titleStringYN

Return:

TypeDescription
BooleanReturns true if the value is accepted without modification. Returns false if the value is missing, has an invalid type, or was truncated to 35 characters.

Example:

setTitle()
let webpush = new SimplePushNotification();
webpush.setTitle('Title Text');

setBody(body)


Use this method to set the push notification body text. The body length must not exceed 255 characters. If the value exceeds 255 characters, it is truncated.

Parameter(s):

NameTypeMandatoryDefault value
bodyStringYN

Return:

TypeDescription
BooleanReturns true if the value is accepted without modification. Returns false if the value is missing, has an invalid type, or was truncated to 255 characters.

Example:

setBody()
let webpush = new SimplePushNotification();
webpush.setBody('Notification body text');

setIconUrl(iconUrl)


Use this method to display an icon in the push notification, the URL of which is passed in the iconUrl parameter. The default value is set by the push_notifications.default_icon_url system property.

Parameter(s):

NameTypeMandatoryDefault value
iconUrlStringYhttps://simpleone.ru/favicon/favicon.ico

Return:

TypeDescription
BooleanReturns false if an invalid iconUrl value is set.

Example:

setIconUrl()
let webpush = new SimplePushNotification();
webpush.setIconUrl('https://simpleone.ru/favicon/favicon.ico')

setUrl(linkUrl)


Use this method to set the URL for navigation when a user clicks the push notification.

Parameter(s):

NameTypeMandatoryDefault value
linkUrlStringYN

Return:

TypeDescription
BooleanReturns false if an invalid linkUrl value is set.

Example:

setUrl()
let webpush = new SimplePushNotification();
webpush.setUrl('https://your-instance.simpleone.ru/');

setUrgency(severity)


Use this method to set the urgency level of the push notification.

If the value is not set or is invalid, the value of the push_notifications.default_urgency system property is used. If this property does not exist, is not set, or is set incorrectly, the value set in the column properties of the Urgency column of the Push Notification (sys_push_notification) table is used.

Parameter(s):

NameTypeMandatoryValid valuesDefault value
severityStringY
  • very-low
  • low
  • normal
  • high
normal

Return:

TypeDescription
BooleanReturns false if an invalid severity value is set.

Example:

setUrgency()
let webpush = new SimplePushNotification();
webpush.setUrgency('normal');

setTtl(ttl)


Use this method to set the time to live of the push notification in seconds. Maximum value: 2419200.

If the value is invalid (not an integer from 0 to 2419200) or not set, the value of the push_notifications.default_ttl system property is used. If this property does not exist, is not set, or is set incorrectly, the value set in the column properties of the Time to live column of the Push Notification (sys_push_notification) table is used.

Parameter(s):

NameTypeMandatoryValid valuesDefault value
ttlIntegerYFrom 0 to 241920086400

Return:

TypeDescription
BooleanReturns false if an invalid ttl value is set.

Example:

setTtl()
let webpush = new SimplePushNotification();
webpush.setTtl(86400);

setInteraction(interaction)


Use this method to set whether a click on the push notification is required to dismiss it.

Parameter(s):

NameTypeMandatoryValid valuesDefault value
interactionBooleanY
  • true
  • false
N

Return:

TypeDescription
BooleanReturns false if an invalid interaction value is set.

Example:

setInteraction()
let webpush = new SimplePushNotification();
webpush.setInteraction(true);

Retrieve and validate data

getJson()


Use this method to get the current values of the SimplePushNotification class instance.

This method does not accept any parameters.

Return:

TypeDescription
StringA serialized JSON string containing the current field values of the class instance.

Example:

getJson()
const webpush = new SimplePushNotification();

webpush.setTitle('Request processed');
webpush.setBody('Your request has been processed');

ss.info(webpush.getJson());

validate()


Use this method to validate the current values of the SimplePushNotification instance without sending the notification.

This method does not accept any parameters.

Return:

TypeDescription
StringA serialized JSON string containing the validation results of the class instance fields.

The result string may contain the following messages:

MessageFieldsCondition
The parameter does not contain a valuetitle, bodyA mandatory value is missing.
Some values are incorrectuserIds, groupIdsThe array contains incorrect identifiers.
The parameter contains an invalid valueurl, ttl, iconUrl, urgency, interactionThe value does not match the type, format, or valid range.
The parameter value has been truncatedtitle, bodyThe value has been truncated to the maximum allowed length.
userID or groupID must be completedrecipientsNo valid recipient users or groups specified.

Example:

validate()
const webpush = new SimplePushNotification();

webpush.setTitle('Request processed');
webpush.setBody('Your request has been processed');

ss.info(webpush.validate());

Send notification

send()


Use this method for the logical sending of a push notification.

Before logical sending, the system validates the parameters. If mandatory parameters are not set or are set incorrectly, the following occurs:

  • logical sending is not performed,
  • a corresponding record is created in the System Log (sys_log).

Return:

TypeDescription
StringIf logical sending is successful, returns the ID (sys_id) of the created record from the Push Notification (sys_push_notification) table. Otherwise, returns false.

Example

SimplePushNotification
let webpush = new SimplePushNotification();

webpush.setTitle('Request processed');
webpush.setBody('Your request has been processed');
webpush.setIconUrl('https://simpleone.ru/favicon/favicon.ico')
webpush.setUrl('https://your-instance.simpleone.ru/');
webpush.setInteraction(true);
webpush.setUrgency('normal');
webpush.setTtl(86400);
webpush.setRecipientUserIds(['155931135900000001']);
webpush.setRecipientGroupIds(['177068186608977300']);

ss.info(webpush.getJson());

const validate = webpush.validate();
ss.info(validate);

const id = webpush.send()
ss.info(id);