Notifications help users stay up-to-date with events in UCloud.
Rationale
Powers the notification feature of UCloud. Other services can call this service to create a new notification for users. Notifications are automatically delivered to any connected frontend via websockets.
NotificationDescriptions.create.call(CreateNotification( notification =Notification( id =null, message ="Something has happened", meta =JsonObject(mapOf("myParameter" to JsonLiteral( coerceToInlineType =null, content ="42", isString =false, )),)), read =false, ts =1704180845770, type ="MY_NOTIFICATION_TYPE", ), user ="User#1234", ), ucloud).orThrow()/*FindByLongId( id = 56123, )*/
Communication Flow: Curl
# ------------------------------------------------------------------------------------------------------# $host is the UCloud instance to contact. Example: 'http://localhost:8080' or 'https://cloud.sdu.dk'# $accessToken is a valid access-token issued by UCloud# ------------------------------------------------------------------------------------------------------# Authenticated as ucloudcurl -XPUT -H "Authorization: Bearer $accessToken" -H "Content-Type: content-type: application/json; charset=utf-8" "$host/api/notifications" -d '{
"user":"User#1234","notification":{"type":"MY_NOTIFICATION_TYPE","message":"Something has happened","id":null,"meta":{"myParameter":42 },"ts":1704180845770,"read":false }}'# {# "id": 56123# }
Communication Flow: Visual
Example: Listening to notifications
Frequency of use
Common
Actors
An authenticated user (user)
Communication Flow: Kotlin
NotificationDescriptions.subscription.subscribe( Unit, user, handler = { /* will receive messages listed below */ })/*Notification( id = 56123, message = "Something has happened", meta = JsonObject(mapOf("myParameter" to JsonLiteral( coerceToInlineType = null, content = "42", isString = false, )),)), read = false, ts = 1704180845774, type = "MY_NOTIFICATION_TYPE", )*/NotificationDescriptions.markAsRead.call(FindByNotificationIdBulk( ids ="56123", ), user).orThrow()/*MarkResponse( failures = emptyList(), )*/
Communication Flow: Curl
# ------------------------------------------------------------------------------------------------------# $host is the UCloud instance to contact. Example: 'http://localhost:8080' or 'https://cloud.sdu.dk'# $accessToken is a valid access-token issued by UCloud# ------------------------------------------------------------------------------------------------------# Authenticated as usercurl -XPOST -H "Authorization: Bearer $accessToken" -H "Content-Type: content-type: application/json; charset=utf-8" "$host/api/notifications/read" -d '{
"ids":"56123"}'# {# "failures": [# ]# }
Communication Flow: Visual
Example: List and Clear notifications
Frequency of use
Common
Actors
An authenticated user (user)
Communication Flow: Kotlin
NotificationDescriptions.list.call(ListNotificationRequest( itemsPerPage =null, page =null, since =null, type =null, ), user).orThrow()/*Page( items = listOf(Notification( id = 56123, message = "Something has happened", meta = JsonObject(mapOf("myParameter" to JsonLiteral( coerceToInlineType = null, content = "42", isString = false, )),)), read = false, ts = 1704180845776, type = "MY_NOTIFICATION_TYPE", )), itemsInTotal = 1, itemsPerPage = 50, pageNumber = 0, )*/NotificationDescriptions.markAllAsRead.call( Unit, user).orThrow()/*Unit*/
Communication Flow: Curl
# ------------------------------------------------------------------------------------------------------# $host is the UCloud instance to contact. Example: 'http://localhost:8080' or 'https://cloud.sdu.dk'# $accessToken is a valid access-token issued by UCloud# ------------------------------------------------------------------------------------------------------# Authenticated as usercurl-XGET-H"Authorization: Bearer $accessToken""$host/api/notifications?"# {# "itemsInTotal": 1,# "itemsPerPage": 50,# "pageNumber": 0,# "items": [# {# "type": "MY_NOTIFICATION_TYPE",# "message": "Something has happened",# "id": 56123,# "meta": {# "myParameter": 42# },# "ts": 1704180845776,# "read": false# }# ]# }curl-XPOST-H"Authorization: Bearer $accessToken""$host/api/notifications/read/all"# {# }
Communication Flow: Visual
Remote Procedure Calls
internalNotification
Notifies an instance of this service that it should notify an end-user