Klave logo

Making Notifications

To enable complex and real-time application use cases, Klave leverages full duplex connection provided by WebSocket. This means that you can send real-time notifications from within your transaction and query function.

Using Notification from Applications

Sending back notifications is the only way to return any payload from your transaction and query business logic. Klave SDK provides a simple interface to create and send notifications.

The available set of operations is the following one:

ClassOperationParametersReturnsBehavior
NotifiersendJsonmessage-Notify the json object passed as parameter
NotifiersendStringmessage-Notify the string passed as parameter
NotifiersendArrayBuffermessage-Notify the ArrayBuffer passed as parameter

In AssemblyScipt, the notification manager can be accessed through the Notifier keyword. Notifications can be used within query or transaction context. For example:

import { Notifier } from '@klave/sdk';
 
@serializable
export class StoreInput {
    key!: string;
    value!: string;
}
 
@serializable
export class FetchOutput {
    success!: boolean;
    value!: string;
}
 
/**
* @query
*/
export function notifyExample(input: StoreInput): void {
    //Returning the input back
    Notifier.sendJson<StoreInput>(input); 
            
    //Returning a json back
    Notifier.sendJson<FetchOutput>({
        success: true,
        input.value
    });
 
    //Returning a string back
    Notifier.sendString("Notify me!"); ;
}

On this page