@egain/ai-agent-sdk API Reference - v0.1.1 / Message
Class: Message
Message class representing both incoming and outgoing messages
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new Message(persona, role, content?, options?): Message
Create a new Message instance
Parameters
| Name | Type |
|---|---|
persona | Persona |
role | Role |
content? | string |
options? | Object |
options.messageId? | string |
options.messageData? | MessageData |
options.timestamp? | number |
options.from? | string |
options.to? | string |
options.agentId? | string |
options.sessionId? | string |
Returns
Defined in
Properties
messageId
• Optional Readonly messageId: string
Defined in
persona
• Readonly persona: Persona
Defined in
role
• Readonly role: Role
Defined in
content
• Optional Readonly content: string
Defined in
messageData
• Optional Readonly messageData: MessageData
Defined in
timestamp
• Readonly timestamp: number
Defined in
from
• Optional Readonly from: string
Defined in
to
• Optional Readonly to: string
Defined in
agentId
• Optional Readonly agentId: any
Defined in
sessionId
• Optional Readonly sessionId: any
Defined in
Methods
validate
▸ validate(): void
Validate message structure
Returns
void
Throws
If message is invalid
Defined in
toPayloadString
▸ toPayloadString(): string
Convert message to payload string (JSON) for transmission Outgoing payload is configured here
Returns
string
JSON string
Defined in
fromJSON
▸ fromJSON(data, sessionContext): Message
Create a Message instance from JSON data (typically from WebSocket)
Parameters
| Name | Type |
|---|---|
data | any |
sessionContext | SessionContext |
Returns
Defined in
isIncoming
▸ isIncoming(): boolean
Check if this is an incoming message Incoming messages come from the server (agent, system, or metadata) Can also be identified by the 'from' field if it's set to an agent ID
Returns
boolean
Defined in
isOutgoing
▸ isOutgoing(): boolean
Check if this is an outgoing message Outgoing messages are sent by the client (customer) Can also be identified by the 'from' field if it's set to a customer/client ID
Returns
boolean
Defined in
clone
▸ clone(updates?): Message
Create a copy of this message with updated fields
Parameters
| Name | Type |
|---|---|
updates? | Partial<{ persona: Persona ; role: Role ; content: string ; messageId: string ; messageData: MessageData ; timestamp: number ; from: string ; to: string }> |