API Reference
OptaveJavaScriptSDK(options)
Creates a new instance of the OptaveJavaScriptSDK.
Parameters
options(Object): Configuration options.websocketUrl(string): The WebSocket URL.authenticationUrl(string, optional): The authentication URL.clientId(string, optional): The client ID for authentication.clientSecret(string, optional): The client secret for authentication.
authenticate()
Authenticates the client using the provided credentials and retrieves an access token.
- Returns:
Promise<string>: The access token.
openConnection(bearerToken)
Establishes a WebSocket connection using the provided bearer token.
Parameters
bearerToken(string): The authentication token.
closeConnection()
Closes the active WebSocket connection.
send(requestType, action, params, version)
Sends a message through the WebSocket connection.
- Parameters:
requestType(string): The type of the request.action(string): The specific action to perform.params(Object): The parameters for the request.version(number, optional): The payload version (default is2).
Predefined Methods
These methods are shortcuts for sending specific types of messages.
customerInteraction(params): Sends acustomerinteractionmessage.assistant(params): Sends anassistantmessage. Available from SDK version 3.6.0.elevate(params): Sends anelevatemessage.adjust(params): Sends anadjustmessage.summarize(params): Sends asummarizemessage.translate(params): Sends atranslatemessage.recommend(params): Sends arecommendmessage.insights(params): Sends aninsightsmessage.
EventEmitter Methods
Since OptaveJavaScriptSDK extends EventEmitter, you can use all standard EventEmitter methods such as on, once, emit, etc.