Recipe: Make toasts stay visible (persistence)

If a notification toast contains very important information, It can be useful to make it stay visible on the desktop until the user interacts with it. Toasts that do this are called "persistent." However, you should use this capability sparingly, to avoid annoying the user with too many persistent toasts.

Image showing stack of persistent toasts on desktop, with badgingImage showing stack of persistent toasts on desktop, with badging

Image showing stack of persistent toasts on desktop, with badging

User story

Suppose your management has given you the following user stories to implement:

  1. As the head of a trade desk, I want to ensure that traders who are interested in Wayne Enterprises see any relevant news, so that they can stay up to date on current performance and can take action in a timely manner.

  2. As a user of a financial desktop, I want to ensure that I do not miss notifications from important sources amid all the things vying for my attention, so that I can take action about them.

Recipe

To make a toast persistent, you can specify that a notification is "sticky" in the configuration options; the default is not sticky (i.e., transient).

To ensure that users understand the reason for a toast being persistent, you must also use the indicator option to signal to the user about the type of event that the toast is about. See the recipe to show the urgency of a notification for more details.

Code example

const notification = {
   "title": "Stop Loss of 47.22 for Brent Oil Futures reached",
   "category": "Trade",
   "body": "Your stop limit for Brent Oil has been reached. Proceed with the purchase of 1000 Futures?",
   "icon": "http://cdn.openfin.co/examples/notifications/company-T.png",
   "sticky": "sticky",
   "indicator": {
       "text": "Stop Limit Reached",
       "type": "warning"
   },
   "buttons": [
       {
           "title": "Buy Now",
           "type": "button",
           "cta": true, //makes the button prominent by coloring it blue
           "onClick": {
               "task": "buy-threshhold-stock",
               "customData": {
                   "message": "Example data to send back when this entry is clicked"
               }
           }
       },
       {
           "title": "Cancel Order",
           "type": "button",
       }
   ]
};
 
 create(notification);
var notificationId = "notificationId";
var buttons = new List<ButtonOptions>();

var buyNowButton = new ButtonOptions
{
    Title = "Buy Now",
    IsCallToActionButton = true,
    OnNotificationButtonClick = new Dictionary<string, object>
    {
        {"buy-threshold-stock", "Example data to send back when this entry is clicked" }
    }
};

var cancelButton = new ButtonOptions
{
    Title = "Cancel Order"
};

// buttons are added from left to right
buttons.Add(cancelButton);
buttons.Add(buyNowButton);

// create an instance of a Notification indicator
var indicator = new NotificationIndicator
{
    IndicatorText = "Stop Limit Reached",
    IndicatorType = IndicatorType.Warning 
};

var options = new NotificationOptions
{
    Title = "Stop Loss of 47.22 for Brent Oil Futures reached",
    Category = "Trade",
    Body = "Your stop limit for Brent Oil has been reached. Proceed with the purchase of 1000 Futures?",
    Icon = "<http://cdn.openfin.co/examples/notifications/company-T.png",>
    NotificationIndicator = indicator ,
    IsStickyNotification = true //set this property to true to make the notification sticky
};

var notificationOptions = await NotificationClient.CreateNotificationAsync(notificationId, options);

More info

Users can turn off notifications from your app. In future releases, users may be able to turn off persistence of toasts from your app. Therefore, it is not guaranteed that a toast you specify as sticky will always be displayed or be persistent.


Did this page help you?