Class: NotificationClient
Notification Client (Finsemble Workspaces)
Used to send, receive and manipulate notifications
Methods
-
deleteNotifications(notifications)
-
Deletes a notification
All clients subscribed to receive the updated notifications will be sent the new state.
Name Type Description notificationsINotification[] The notifications to delete
-
fetchHistory(options, filter)
-
Fetches all the notifications sent to Finsemble after a specific date.
Name Type Description optionsINotificationHistoryOptions | string optional An options object or an ISO8601 formatted date string.
Name Type Description INotificationHistoryOptionsName Type Description pageNumberThe page number
pageSizeThe number of notifications to fetch
sentAfterISO8601 date formatted string. Fetch (from) notifications sent after this date
sentBeforeISO8601 date formatted string. Fetch (from) notifications sent before this date
filterIFilter Name Type Description excludeAn 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
includeAn array of objects. If more than one object is used it will use an OR match.
Examples
Get notifications sent between now and one month ago
let lastMonth = new Date(); lastMonth.setMonth(lastMonth.getMonth()-1); const notifications = await FSBL.Clients.NotificationClient.fetchHistory({sentAfter: lastMonth.toISOString()})Get notifications sent between now and one month ago that matches a filter.
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({sentAfter: 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 sourceundefined | 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") -
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 notificationsINotification[] 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 notificationsINotification[] 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 filterIMuteFilter | IMuteFilter[] Notifications to apply action to.
Name Type Description IMuteFilterName Type Description sourcetypeExample
// 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 notificationsPartial[] | Partial Array of INotification
Example
Send a new notification
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]); -
onClose(cb)
-
Name Type Description cbany -
performAction(notifications, action)
-
Tells the service to perform the supplied action on the notification(s)
Name Type Description notificationsPartial[] Notifications to apply action to.
actionIAction Name Type Description buttonTextstring Text to display on the button UI.
channeloptional Channel to transmit payload on QUERY, TRANSMIT and PUBLISH actions
componentoptional Component to spawn when using the spawn action.
idoptional For Internal use
markAsReadoptional Mark the Notification as read when performing this action. Defaults to true if not set.
millisecondsoptional Milliseconds to snooze for when using the snooze action
payloadany optional Payload transmitted along channel on QUERY, TRANSMIT and PUBLISH actions
spawnParamsany optional The spawnParams passed to the spawn function. These are the configuration settings from the finsemble.appd[].manifest.window section of the application manifest, except for the `options` element.
typestring 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 subscriptionPartial with name value pair used to match on.
onNotificationOnNotificationCallback 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 filterIMuteFilter | IMuteFilter[] Notifications to apply action to.
Name Type Description IMuteFilterName Type Description sourcetypeExample
// 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 subscriptionIdstring 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();