Class: NotificationClient
Notification Client (Finsemble Workspaces)
Used to send, receive and manipulate notifications
Methods
-
applyOverrides()
-
-
deleteNotifications(notifications)
-
Deletes a notification
All clients subscribed to receive the updated notifications will be sent the new state.
Name Type Description notifications
INotification[] The notifications to delete
-
fetchHistory(options, filter)
-
Fetches all the notifications sent to Finsemble after a specific date.
Name Type Description options
INotificationHistoryOptions | string optional An options object or an ISO8601 formatted date string.
Name Type Description INotificationHistoryOptions
Name Type Description pageNumber
number The page number
pageSize
number The number of notifications to fetch
sentAfter
string ISO8601 date formatted string. Fetch (from) notifications sent after this date
sentBefore
string ISO8601 date formatted string. Fetch (from) notifications sent before this date
filter
IFilter Name Type Description exclude
An array of objects on which to exclude a notification. If more than one object is used it will use an OR match. Exclude takes precedence over Include
include
An array of objects. If more than one object is used it will use an OR match.
Examples
let lastMonth = new Date(); lastMonth.setMonth(lastMonth.getMonth()-1); const notifications = await FSBL.Clients.NotificationClient.fetchHistory(lastMonth.toISOString())
const lastMonth = new Date(); lastMonth.setMonth(lastMonth.getMonth()-1); const filter = new FSBL.Clients.NotificationClient.Filter(); // include all notifications from the OMS filter.include.push({"source":"order-management-system"}) // But exclude informational notifications from the OMS filter.exclude.push({"source":"order-management-system", type:"informational"}) const notifications = await FSBL.Clients.NotificationClient.fetchHistory(lastMonth.toISOString(), filter)
-
getLastIssuedAt(source)
-
Return an ISO8601 date a notification matching the specified source was issued. If no source is provided it will get the latest issue date for all notifications (i.e the last time any notification was issue to the service)
If you're sending notifications to Finsemble from an external source, you might want to know when the last Notification of that type was received by Finsemble, so you're able to send any pending ones to the user's desktop
Name Type Description source
string optional to identify which notification to save lastUpdated time for.
Example
// Get the last date Finsemble received a notification sent with the source field set to "product-update-service" const lastIssuedDate = await FSBL.Clients.NotificationClient.getLastIssuedAt("product-update-service")
-
getMuteFilters()
-
Gets the current mute filters for Notification sources in Finsemble.
-
getPreferences()
-
Gets the current notifications preferences object. It tries to load the configs saved in the user preferences and will fallback to config/schema defaults if none are present.
-
getSources()
-
Gets the available notification sources in Finsemble.
-
markRead(notifications)
-
Sets the states of the isRead field to true.
All clients subscribed to received the updated notifications will be sent the new state.
Name Type Description notifications
INotification[] Example
await FSBL.Clients.NotificationClient.markRead([previouslyReceivedNotification]);
-
markUnread(notifications)
-
Sets the states of the isRead field to false.
All clients subscribed to received the updated notifications will be sent the new state.
Name Type Description notifications
INotification[] Example
await FSBL.Clients.NotificationClient.markUnread([previouslyReceivedNotification]);
-
mute(filter)
-
Sets a user preference on which notifications to mute. All future notifications that match the filter will have the mute flag set to true
Name Type Description filter
IMuteFilter | IMuteFilter[] Notifications to apply action to.
Name Type Description IMuteFilter
IMuteFilter
Name Type Description source
string source
string type
string type
string Example
// Mute all notifications coming from the 'order-management-system' source with type 'informational' await FSBL.Clients.NotificationClient.mute({ source: "order-management-system", type: "informational" });
-
notify(notifications)
-
Send a new notification to Finsemble or update existing notifications already in Finsemble.
Name Type Description notifications
INotification[] | INotification Array of INotification
Name Type Description INotification
INotification
Name Type Description actions
IAction[] List of actions which can be performed on a notification.
actions
IAction[] List of actions which can be performed on a notification.
actionsHistory
IPerformedAction[] list of actions which have been performed on a notification.
actionsHistory
IPerformedAction[] list of actions which have been performed on a notification.
contentLogo
string Logo to display in content section of a notification.HTML source data URI or URL, or CSS class. Defaults set by type in configuration.
contentLogo
string Logo to display in content section of a notification.HTML source data URI or URL, or CSS class. Defaults set by type in configuration.
cssClassName
string Allows a css class to be applied to a notification to change it's appearance.
cssClassName
string Allows a css class to be applied to a notification to change it's appearance.
details
string Details about the notification mainly for display purposes.
details
string Details about the notification mainly for display purposes.
headerLogo
string headerLogo
string headerText
string headerText
string id
string Either set when notification is created to refer to id an external system or if null set to UUID.
id
string Either set when notification is created to refer to id an external system or if null set to UUID.
isDeleted
boolean isDeleted
boolean isMuted
boolean If a Notification has been muted after being recieved
isMuted
boolean If a Notification has been muted after being recieved
isRead
boolean If an notification has been marked as read.
isRead
boolean If an notification has been marked as read.
isSnoozed
boolean If a notification is currently snoozed
isSnoozed
boolean If a notification is currently snoozed
issuedAt
string ISO8601 date formatted string. When the notification was generated.
issuedAt
string ISO8601 date formatted string. When the notification was generated.
meta
Meta Additional metadata to be passed along with a notification. Supports arbitrary metadata fields. For example, a team may decide to include a Source or Channel field in all notifications to support filtering operations, or a Quote or Customer ID field to support grouping of notifications generated by different systems but relating to the same entity (for example for filtering/drill down in the Notification Center).
meta
Meta Additional metadata to be passed along with a notification. Supports arbitrary metadata fields. For example, a team may decide to include a Source or Channel field in all notifications to support filtering operations, or a Quote or Customer ID field to support grouping of notifications generated by different systems but relating to the same entity (for example for filtering/drill down in the Notification Center).
notificationAlertSound
string notificationAlertSound
string receivedAt
string ISO8601 date formatted string. When the notification was received by Finsemble
receivedAt
string ISO8601 date formatted string. When the notification was received by Finsemble
source
string The source that the notification originated from
source
string The source that the notification originated from
stateHistory
INotification[] stateHistory
INotification[] timeout
number How long should the notification appear in the UIs.
timeout
number How long should the notification appear in the UIs.
title
string Main display title
title
string Main display title
type
string The type of notification.
type
string The type of notification.
Example
const notification = new FSBL.Clients.NotificationClient.Notification(); // Set your notification fields accordingly notification.title = "Regarding Order..."; notification.details = "Creates a new notification in UI"; notification.type = "email"; await FSBL.Clients.NotificationClient.notify([notification]);
-
performAction(notifications, action)
-
Tells the service to perform the supplied action on the notification(s)
Name Type Description notifications
INotification[] Notifications to apply action to.
action
IAction Name Type Description buttonText
string Text to display on the button UI.
channel
string optional Channel to transmit payload on QUERY, TRANSMIT and PUBLISH actions
component
string optional Component to spawn when using the spawn action.
id
string For Internal use
markAsRead
boolean optional Mark the Notification as read when performing this action. Defaults to true if not set.
milliseconds
number optional Milliseconds to snooze for when using the snooze action
payload
any optional Payload transmitted along channel on QUERY, TRANSMIT and PUBLISH actions
spawnParams
any optional The spawnParams passed to the spawn function.
type
string DISMISS | SNOOZE | SPAWN | QUERY | PUBLISH | TRANSMIT
Example
await FSBL.Clients.NotificationClient.performAction([notification], action).catch((e) => { console.log("Request to perform action failed"); }); // Request to perform action succeeded. The updated notification state will be broadcast to the subscribed clients
-
subscribe(subscription, onNotification)
-
Subscribe to a notification stream given filters. Returns subscriptionId
Name Type Description subscription
ISubscription TODO: Ensure this interface (or implemented type) is publicly accessible
Name Type Description channel
string optional For Internal use
filter
filter id
string For Internal use
onNotification
OnNotificationCallback Defines the callback to and parameters pass into the onNotification function
Example
const { NotificationClient } = FSBL.Clients; const subscription = new NotificationClient.Subscription(); // Set the filter to match INotification fields subscription.filter = new NotificationClient.Filter(); // subscription.filter.include.push({"type": "chat"}); const onNotification = (notification: INotification) => { // This function will be called when a notification arrives addToList(notification); }; // Use the subscription Id to unsubscribe from a specific subscription const subscriptionId = await NotificationClient.subscribe(subscription, onNotification);
-
unmute(filter)
-
Sets the filter preference on which notifications to mute. All future notifications that match the filter will have the mute flag set to true
Name Type Description filter
IMuteFilter | IMuteFilter[] Notifications to apply action to.
Name Type Description IMuteFilter
IMuteFilter
Name Type Description source
string source
string type
string type
string Example
// Unmute all notifications coming from the 'order-management-system' source with type 'informational' await FSBL.Clients.NotificationClient.unmute({ source: "order-management-system", type: "informational" });
-
unsubscribe(subscriptionId)
-
Used to unsubscribe from a notification stream.
Name Type Description subscriptionId
string which was returned when subscription was created.
Example
// the subscriptionId is returned from the subscribe function await FSBL.Clients.NotificationClient.unsubscribe(subscriptionId);
-
unsubscribeAll()
-
Unsubscribe from all notification streams registered with the window's client instance.
Example
FSBL.Clients.NotificationClient.unsubscribeAll();