Skip to main content

InworldClient

Module: Inworld.AI. Namespace: Inworld. Inherited from: MonoBehavior

This is the base class for sending and receiving data from the server.

Inspector Variables

VariableDescription
Server ConfigThe current server to which this client is connected.
Scene Full NameThe full name of the current scene.
API KeyThe API key used to load scenes. Note that if InworldGameData in InworldController has a value, this API Key setting is invalid.
API SecretThe API Secret used to load scenes. Note that if InworldGameData in InworldController has a value, this API Secret setting is invalid.
Auto SceneIf checked, we'll automatically find the first scene containing the characters.
Max Waiting List SizeSets the max size of the cached outgoing packets.
100 by default.
ContinuationFor the new Session Continuation state to load.
Enable Group ChatChecked to enable group chat (Need studio feature enabled first.)
Custom TokenThe JSON token string used to load scenes. You can obtain the token from the Inworld Web SDK.
Public WorkspaceThe string of the public workspace, used for workspace sharing.
Game Session IDThe string for saving the game session by deverlopers.

Events

EventDescription
OnStatusChangedTriggered when the status of this component changes.
OnErrorReceivedTriggered when any error received.
OnPacketSentTriggered when any InworldPackets are sent.
OnGlobalPacketReceivedTriggered when the InworldPackets are received with a source of WORLD.
OnPacketReceivedTriggered when any InworldPackets from the server are received.

Properties

PropertyDescription
CurrentGets the current LiveInfo.
LiveSessionDataGets the live session data.
Key by character's Character ID (aka brainName) value by its agent ID.
EnableGroupChatGets if group chat is enabled.
This feature is still under development. If you'd like to test it, please contact support@inworld.ai.
SessionHistoryGet/Set the session history.
AutoSceneSearchGet/Set if the client will automatically search for a scene for the selected characters.
By default it's disabled.
ServerGets/Sets the current Inworld server this client is connecting.
TokenGets or sets the token used to log in to the Runtime server of Inworld.
CurrentSceneGets/Sets the current full name of the Inworld scene.
IsTokenValidGets if the current token is valid.
StatusGets or sets the current status of the Inworld client.
If set, it will invoke the OnStatusChanged events.
ErrorMessageGets or sets the error message.
ErrorGets/Sets the InworldError.
If the error is no retry, it'll also set the status of this client to be error.

API

FunctionDescriptionParameters
GetCharacterDataByFullNameGet the InworldCharacterData by character's full name."characterFullName": the request characters' Brain ID.
GetCharacterDataByFullNamesGet the InworldCharacterData by characters' full name."characterFullNames": the list of the characters' Brain ID.
GetCharacterDataByIDGets the InworldCharacterData corresponding to the given agentID.
Usually used when processing packets, but don't know it's sender/receiver of characters.
agentID: target ID to search.
GetSceneNameByCharacterGets the scene name by the given target characters.
PrepareSessionPrepare the session. If the session is freshly established. Please call this.loadHistory: check if you're trying to load the history.
gameSessionID: Add your customized gameSessionID for better user data control.
SendFeedbackAsyncSend Feedback data to server.interactionID: The feedback bubble's interactionID
correlationID:The feedback bubble's correlationID
feedback: The actual feedback content.
GetHistoryAsyncGet the session history data. Stored at property SessionHistory.
By default, it'll be stored in the memory only, Please store it to your local storage for future use.
sceneFullName: the full name of the target scene.
SendPacketsA generalized function to send packets.
Will automatically be called in outgoing queue.

Can be called directly by API.
GetAccessTokenRetrieves the access token. This function should be implemented by the child class.
ReconnectReconnects the session or starts a new session if the current session is invalid.
GetLiveSessionInfoRetrieves the live session information once the scene is loaded.
The returned LoadSceneResponse contains the session ID and all the live session IDs for each InworldCharacter in this InworldScene.
InitWithCustomTokenUses the input JSON string of a token instead of API key/secret to load the scene.
This token can be obtained from other applications, such as the InworldWebSDK.
token: the custom token to initialize.
StartSessionStarts the session using the session ID.
DisconnectDisconnects from the Inworld Server.
UnloadSceneUnload curren scene. Make sure to be called before loading another scene.
LoadSceneSends a LoadScene request to the Inworld Server.sceneFullName: the full string of the scene to load.
SendSessionConfigSend Session Config to Inworld Server.
Including capabilities, game session info, client info, user info, etc.
loadHistory: check if you'd like to load the history. gameSessionID: add your customized game session ID for better user control.
SendCapabilitiesSend Capabilities to Inworld Server.
Obsoleted. Use SendSessionConfig instead.
SendClientConfigSend Client Config to Inworld Server.
Obsoleted. Use SendSessionConfig instead.
SendUserConfigSend User Config to Inworld Server.
Obsoleted. Use SendSessionConfig instead.
SendHistorySend the previous dialog (New version) to specific scene.
Obsoleted. Use SendSessionConfig instead.
SendTextToNew Send messages to an InworldCharacter in this current scene.
NOTE: New method uses brain ID (aka character's full name) instead of live session ID.
textToSend:the message to send.
brainName:the full name of the InworldCharacter. If not set, it'll broadcast to the current chat group.
immediate: check if this packet needs to send immediately without order (Need to make sure client is connected first).
SendTextSends messages to an InworldCharacter in the current scene.characterID: the live session ID of the character to send.
textToSend: the message to send.
SendNarrativeActionToNew Send narrative action to an InworldCharacter in this current scene.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID.
2. New method support broadcasting to multiple characters (Would be implemented in future).
narrativeAction: the narrative action to send.
brainName: the list of the characters full name.
immediate: if this packet needs to send immediately without order (Need to make sure client is connected first).
SendNarrativeActionLegacy Send a narrative action to an InworldCharacter in this current scene.characterID: the live session ID of the character to send.
narrativeAction: the narrative action to send.
SendCancelEventToNew Send the CancelResponse Event to InworldServer to interrupt the character's speaking.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID
2. New method support broadcasting to multiple characters.
interactionID: the handle of the dialog context that needs to be cancelled.
utteranceID:the current utterance ID that needs to be cancelled.
brainName: the full name of the characters in the scene.
immediate: if this packet needs to send immediately without order. By default it's true (Need to make sure client is connected first).
SendCancelEventLegacy Send the CancelResponse Event to InworldServer to interrupt the character's speaking.characterID: the live session ID of the character to send.
utteranceID:the current utterance ID that needs to be cancelled.
interactionID: the handle of the dialog context that needs to be cancelled.
SendRegenerateEventImmediately send regenerate response to the specific interaction.characterID: The live session ID of the character.
interactionID: the interaction you'd like to regenerate.
SendApplyResponseEventSelect a packet from all the responses to continue conversation.
Call it only if you have multiple responses based on the current interaction.
characterID: The live session ID of the character.
regenResponsePid: The packet ID that you want to continue.
SendTriggerToNew Send the trigger to an InworldCharacter in the current scene.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID.
2. New method support broadcasting to multiple characters.
triggerName: the name of the trigger to send.
parameters: the parameters and their values for the triggers.
brainName: the full name of the characters in the scene.
immediate: if this packet needs to send immediately without order. By default it's true (Need to make sure client is connected first).
SendTriggerLegacy Send the trigger to an InworldCharacter in the current scene.charID: the live session ID of the character to send.
triggerName: the name of the trigger to send.
parameters: the parameters and their values for the triggers.
StartAudioToNew Send AUDIO_SESSION_START control events to server.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID
2. New method support broadcasting to multiple characters.
"brainName: the full name of the characters to send.
micMode: If you'd like to enable the character interrupt you, check this option to OPEN_MIC.
immediate: If sending immediately (need to make sure client has connected).
StartAudioLegacy sends AUDIO_SESSION_START control events to the server.
Without sending this message, all the audio data will be discarded by the server.
However, if you send this event twice in a row without sending StopAudio(), the Inworld server will also throw exceptions and terminate the session.
charID: the live session ID of the character to send.
micMode: If you'd like to enable the character interrupt you, check this option to OPEN_MIC.
StopAudioToNew Send AUDIO_SESSION_END control events to server to.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID.
2. New method support broadcasting to multiple characters.
immediate: If immediately send message (needs connected to server first).
StopAudioLegacy Sends AUDIO_SESSION_END control events to the server.charID: the live session ID of the character to send.
SendAudioToNew Send the wav data to server to a specific character.
Need to make sure that AUDIO_SESSION_START control event has been sent to server.
NOTE: 1. New method uses brain ID (aka character's full name) instead of live session ID.
2. New method support broadcasting to multiple characters.
Only the base64 string of the wave data is supported by Inworld server.
Additionally, the sample rate of the wave data has to be 16000, mono channel.
base64:the base64 string of the wave data to send.
brainName: the character's full name. immediate: if you want to send the data immediately (Need connected first).
SendAudioLegacy Send the wav data to server to a specific character. Ensure that the AUDIO_SESSION_START control event has been sent to the server.
Only the base64 string of the wave data is supported by the Inworld server.
Additionally, the sample rate of the wave data must be 16000, mono channel.
charID: the live session ID of the character to send.
base64: the base64 string of the wave data to send.
UpdateConversationUpdate the chat group information to server.
If you're sending packets without specific character, it'll be sent to the entire chat group as broadcasting.
conversationID: The customized conversationID if you'd like to specify.
brainNames: The list of the full names of the characters.