CorvidReference

notifications

The Notifications API is used to send notifications to the site owner and contributors.

Notifications are messages that are sent to the site dashboard, Wix app, and/or browser of your site's contributors.

To learn more about notifications, see About Site Notifications.

To use the Notifications API, import wixCrm from the wix-crm-backend module:

   import wixCrm from 'wix-crm-backend';

Table of Contents

FUNCTIONS

?
Perform actions on an object.
notify( )Sends a notification.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
ActionTargetAn object containing information about where to navigate when a notification is clicked.
NotificationOptionsAn object representing notification options.
SiteContributorsAn object containing information about which contributors will receive a notification.

notify( )

Sends a notification.

Description

The notify() function sends a notification to the specified site contributors on the specified channels.

Use the channels parameter to specify which channels to send the notification to.

Use the recipients property of the options parameter to specify which site contributors to send the notification to.

Syntax

function notify(body: string, channels: Array<string>, options: NotificationOptions): Promise<void>
PARAMETERS
?
Values that you pass to a function.
body
string
Contents of the notification. Max length: 512 characters.
channels
Array<string>

The channels to send the notification on. One or more of:

  • "Mobile": Sends the notification to the Wix App.
  • "Dashboard": Sends the notification to the contributor's Wix dashboard.
  • "Browser": Sends the notification to the contributor's browser.
options
Additional notification related information.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the send notification request is received.

Examples

Send a notification to the site owner's Dashboard

import wixCrm from 'wix-crm-backend';

export function notifyOwnerOnDashboard() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Dashboard"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": {"role": "Owner"}
    }
  );
}

Send a notification to the site owner on multiple channels (browser and mobile)

import wixCrm from 'wix-crm-backend';

export function notifyMultipleChannels() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Browser", "Mobile"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": {"role": "Owner"}
    }
  );
}

Send a notification to all site contributors on mobile

import wixCrm from 'wix-crm-backend';

export function notifySiteContributors() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Mobile"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": { "role": "All_Contributors"}
    }
  );
}

ActionTarget

An object containing information about where to navigate when a notification is clicked.

See Also

NotificationOptions

Syntax

type ActionTarget = {
  url: string
}
MEMBERS
?
The properties of an object.
url(Optional)
string
URL to navigate to when the actionTitle text is clicked.

Examples

Send a notification to all site contributors on mobile

import wixCrm from 'wix-crm-backend';

export function notifySiteContributors() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Mobile"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": { "role": "All_Contributors"}
    }
  );
}

NotificationOptions

An object representing notification options.

See Also

notify( )

Syntax

type NotificationOptions = {
  title: string
  actionTitle: string
  actionTarget: ActionTarget
  recipients: SiteContributors
}
MEMBERS
?
The properties of an object.
title(Optional)
string
Notification title. Only displayed on mobile and browser notifications. Max length: 512 characters.
actionTitle(Optional)
string
Call to action text to be clicked on. When clicked, navigates to the actionTarget URL. Max length: 512 characters.
actionTarget(Optional)
Where to navigate to when the actionTitle text is clicked.
recipients(Optional)

Contributor that will receive the notifications, based on their assigned roles. One of:

  • "All_Contributors": All site contributors, including the site owner.
  • "Owner": Only the site owner.

Examples

Send a notification to all site contributors on mobile

import wixCrm from 'wix-crm-backend';

export function notifySiteContributors() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Mobile"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": { "role": "All_Contributors"}
    }
  );
}

SiteContributors

An object containing information about which contributors will receive a notification.

See Also

NotificationOptions

Syntax

type SiteContributors = {
  role: string
}
MEMBERS
?
The properties of an object.
role(Optional)
string

Roles to receive the notification. One of:

  • "All_Contributors": All site contributors (default).
  • "Owner": Only the site owner.

Examples

Send a notification to all site contributors on mobile

import wixCrm from 'wix-crm-backend';

export function notifySiteContributors() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Mobile"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": { "role": "All_Contributors"}
    }
  );
}