Skip to main content

Update context

Event session:context:update

The session:context:update event allows you to modify the context

of an existing session. This is useful when you need to update user information or add new context data after the initial session creation.

Use cases

  • Updating user information after initial form submission
  • Adding new context data during the conversation
  • Modifying user preferences or settings
  • Updating user location or device information
  • Adding or modifying custom context fields

Payload example

{
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"context": {
"user": {
"display_name": "John Doe",
"phone": "+1234567890",
"email": "john.doe@example.com"
},
"custom_fields": {
"preferred_language": "en",
"subscription_tier": "premium"
}
},
"timestamp": 1635789600000
}

Payload fields

FieldTypeRequiredDescription
session_idStringYesThe unique identifier of the session to update. Check this page for more information.
contextObjectYesA ContextObject containing the updated context information. Must contain a user object.
timestampIntegerYesUnix timestamp in milliseconds representing when the context update was initiated.

Server responses

Success: session:context:updated

On successful context update, the server responds with a session:context:updated event containing the updated context:

{
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"context": {
"user": {
"display_name": "John Doe",
"phone": "***",
"email": "john.doe@example.com"
},
"custom_fields": {
"preferred_language": "en",
"subscription_tier": "premium"
}
}
}
warning

Moveo controls certain fields in the context object. As these are likely to be sensitive, moveo will obfuscate these fields in the response shwing them as ***.

Error: session:context:update:error

If the context update fails, the server responds with an error event:

{
"error_code": "invalid_session",
"description": "The provided session ID is invalid or the session has expired"
}

Example usage

// Initialize socket connection
const socket = io(URL, socketOptions);

// Update context payload
const contextUpdatePayload = {
session_id: "123e4567-e89b-12d3-a456-426614174000",
context: {
user: {
display_name: "Jane Smith",
email: "jane.smith@example.com",
phone: "+1987654321",
},
custom_fields: {
preferred_language: "en",
subscription_tier: "premium",
},
},
timestamp: Date.now(),
};

// Send context update event
socket.emit("session:context:update", contextUpdatePayload);

// Handle success response
socket.on("session:context:updated", (data) => {
console.log("Context updated successfully:", data.context);
});

// Handle error response
socket.on("session:context:update:error", (error) => {
console.error("Error updating context:", error.description);
});
note

The context update will merge with the existing context, meaning you only need to include the fields you want to update. Any fields not included in the update will retain their previous values.