Skip to main content
Version: 3.6.0

Sending Messages

The SDK provides several methods to send different types of messages through the WebSocket connection. Each method corresponds to a specific action type.

Available Methods​

  • customerInteraction(params) ⚠️ Deprecated
  • interaction(params)
  • reception(params)
  • assistant(params)
  • elevate(params)
  • adjust(params)
  • summarize(params)
  • translate(params)
  • recommend(params)
  • insights(params)

Example: Sending an Interaction Message​

Note: The customerInteraction method is deprecated. Please use the interaction method instead for new implementations.

## Example: Sending an Interaction Message

> **Note**: The `customerInteraction` method is deprecated. Please use the `interaction` method instead for new implementations.

```javascript
const interactionParams = {
session: {
sessionId: "a1b2c3e6-e5f6-7890-1234-56789abcdef0",
channel: {
browser: "Safari 17.0",
deviceInfo: "iOS/18.2, iPhone15,3",
deviceType: "mobile",
language: "en-US",
location: "40.7128,-74.0060",
medium: "chat",
section: "support_page"
},
interface: {
appVersion: "2.1.0",
category: "crm",
language: "en-US",
name: "my_support_app",
type: "custom_components"
},
network: {
latencyMs: 120
},
},
request: {
requestId: "a1b2c3d4-e5f6-7890-1234-56789ab2345",
attributes: {
variant: "A"
},
connections: {
threadId: "9e8d7c6b-5a49-3827-1605-948372615abc"
},
context: {
organizationId: "f7e8d9c0-b1a2-3456-7890-123456789abc",
tenantId: "a1b2c3d4-e5f6-7890-1234-56789abcdef0"
},
settings: {
disableSearch: false,
disableStream: false,
disableSources: false,
disableTools: false,
disableBrowsing: false,
maxResponseLength: 2000,
overrideOutputLanguage: "en-US",
overrideInterfaceLanguage: "en-US",
overrideChannelMedium: "voice"
},
scope: {
resources: {
links: [
{
id: "20382320302",
type: "payment_link",
url: "https://checkout.stripe.com/pay/cs_test...",
label: "Complete Payment",
html: false,
expiresAt: "2025-08-06T00:00:00Z"
}
],
codes: [
{
id: "328123-123812312-13023f08asdxjfw0e",
type: "order_number",
value: "ORD-12345",
label: "Order Number"
}
]
},
conversations: [
{
conversationId: "",
participants: [
{
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
displayName: "John Doe",
role: "user"
},
{
participantId: "5b8c9d0e-2f4a-6b1c-9d8e-123456789xyz",
displayName: "Sarah Smith",
role: "operator"
}
],
messages: [
{
content: "Hi, can you help me?",
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
timestamp: "2024-01-15T10:30:00.000Z"
},
{
content: "Hello! I'd be happy to assist you today. What can I help you with?",
participantId: "5b8c9d0e-2f4a-6b1c-9d8e-123456789xyz",
timestamp: "2024-01-15T10:30:15.000Z"
}
],
metadata: {}
}
],
interactions: [
{
content: "Support ticket T12345 has been created for user John Doe",
id: "1",
name: "ticket_created",
role: "System",
timestamp: "2024-01-15T10:29:45.000Z"
}
]
}
}
};

client.interaction(interactionParams);

Example: Sending a Reception Message​

const receptionParams = {
sessionId: "a1b2c3e6-e5f6-7890-1234-56789abcdef0",
request: {
requestId: "a1b2c3d4-e5f6-7890-1234-56789ab2345",
attributes: {
variant: "A"
},
connections: {
threadId: "9e8d7c6b-5a49-3827-1605-948372615abc"
},
context: {
organizationId: "f7e8d9c0-b1a2-3456-7890-123456789abc"
},
scope: {
conversations: [
{
content: "Hi, I need help with my account",
displayName: "Jane Smith",
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
role: "EndUser",
timestamp: "2024-01-15T10:30:00.000Z"
}
]
}
}
};

client.reception(receptionParams);

Example: Sending an Assistant Message​

Available from SDK version 3.6.0. See the Assistant message reference for the path decisions this message returns.

const assistantParams = {
headers: {
timestamp: "2024-01-15T10:30:00.000Z",
networkLatencyMs: 120
},
session: {
sessionId: "a1b2c3e6-e5f6-7890-1234-56789abcdef1",
channel: {
deviceType: "mobile",
language: "en-US",
medium: "chat",
section: "support_page"
},
interface: {
appVersion: "2.1.0",
category: "crm",
language: "en-US",
name: "my_support_app",
type: "custom_components"
}
},
request: {
requestId: "a1b2c3d4-e5f6-7890-1234-56789ab2346",
attributes: {
variant: "A"
},
connections: {
threadId: "9e8d7c6b-5a49-3827-1605-948372615abd"
},
context: {
organizationId: "f7e8d9c0-b1a2-3456-7890-123456789abc"
},
scope: {
products: [
{ id: "PRD-4821" }
],
conversations: [
{
conversationId: "conv-789",
participants: [
{
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
displayName: "John Doe",
role: "user"
},
{
participantId: "7d9e0f1a-3b5c-7d9e-1f0a-987654321abc",
displayName: "AI Assistant",
role: "assistant"
}
],
messages: [
{
content: "Hi, can you help me?",
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
timestamp: "2024-01-15T10:30:00.000Z"
}
]
}
]
}
}
};

client.assistant(assistantParams);

Legacy Example: Customer Interaction (Deprecated)​

⚠️ Deprecated: This method will be removed in a future version. Please migrate to the interaction method.

const customerInteractionParams = {
sessionId: "a1b2c3e6-e5f6-7890-1234-56789abcdef0",
session: {
channel: {
browser: "Safari 17.0",
deviceInfo: "iOS/18.2, iPhone15,3",
deviceType: "mobile",
language: "en-US",
location: "40.7128,-74.0060",
medium: "chat",
section: "support_page"
},
interface: {
appVersion: "2.1.0",
category: "crm",
language: "en-US",
name: "my_support_app",
type: "custom_components"
},
network: {
latencyMs: 120
},
},
request: {
requestId: "a1b2c3d4-e5f6-7890-1234-56789ab2345",
attributes: {
variant: "A"
},
connections: {
threadId: "9e8d7c6b-5a49-3827-1605-948372615abc"
},
context: {
organizationId: "f7e8d9c0-b1a2-3456-7890-123456789abc",
tenantId: "a1b2c3d4-e5f6-7890-1234-56789abcdef0"
},
settings: {
disableSearch: false,
disableStream: false,
disableSources: false,
disableTools: false,
disableBrowsing: false,
maxResponseLength: 2000,
overrideOutputLanguage: "en-US",
overrideInterfaceLanguage: "en-US",
overrideChannelMedium: "voice"
},
scope: {
resources: {
links: [
{
id: "20382320302",
type: "payment_link",
url: "https://checkout.stripe.com/pay/cs_test...",
label: "Complete Payment",
html: false,
expiresAt: "2025-08-06T00:00:00Z"
}
],
codes: [
{
id: "328123-123812312-13023f08asdxjfw0e",
type: "order_number",
value: "ORD-12345",
label: "Order Number"
}
]
},
conversations: [
{
content: "Hi, can you help me?",
displayName: "John Doe",
participantId: "2c4f8a9b-1d3e-5f70-8293-456789012def",
role: "EndUser",
timestamp: "2024-01-15T10:30:00.000Z"
},
{
content: "Hello! I'd be happy to assist you today. What can I help you with?",
displayName: "Sarah Smith",
participantId: "5b8c9d0e-2f4a-6b1c-9d8e-123456789xyz",
role: "Agent",
timestamp: "2024-01-15T10:30:15.000Z"
}
],
interactions: [
{
content: "Support ticket T12345 has been created for user John Doe",
id: "1",
name: "ticket_created",
role: "System",
timestamp: "2024-01-15T10:29:45.000Z"
}
]
}
}
};

client.customerInteraction(customerInteractionParams);

Payload Structure​

The SDK manages a default payload structure that encapsulates session information, user details, agent information, requests, and more. When sending a message, you provide a params object that is merged with the default payload to form the final payload sent over the WebSocket.

Default Payload Overview​

  • sessionId: Custom identifier that lasts for the duration of a chat session or a call
  • session: Contains session-related data including:
    • channel: Channel information (medium, section, language, location, device details, browser)
    • interface: Interface details (app version, type, category, name, language)
    • network: Network information (latency measurements)
  • request: Contains the main request structure with:
    • requestId: Unique identifier for the request
    • attributes: Optional attributes like variant information
    • connections: Connection details such as threadId (should remain unique across all requests related to the same ticket/case/conversation)
    • context: Generated by Optave, includes tenantId and organizationId
    • settings: Configuration options for response behavior (disable flags, length limits, language overrides)
    • scope: Contains:
      • resources: Resource data like links and codes
      • conversations: Array of conversation messages with participant details
      • interactions: Array of system interactions and events

Merging Strategy​

The SDK merges the user-provided params on top of the default payload, replacing existing default values.