Skip to content

@egain/ai-agent-sdk API Reference - v0.3.2 / 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 ​

NameType
personaPersona
roleRole
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 ​

Message

Defined in ​

core/message/Message.ts:21

Properties ​

messageId ​

• Optional Readonly messageId: string

Defined in ​

core/message/Message.ts:7


persona ​

• Readonly persona: Persona

Defined in ​

core/message/Message.ts:8


role ​

• Readonly role: Role

Defined in ​

core/message/Message.ts:9


content ​

• Optional Readonly content: string

Defined in ​

core/message/Message.ts:10


messageData ​

• Optional Readonly messageData: MessageData

Defined in ​

core/message/Message.ts:11


timestamp ​

• Readonly timestamp: number

Defined in ​

core/message/Message.ts:12


from ​

• Optional Readonly from: string

Defined in ​

core/message/Message.ts:13


to ​

• Optional Readonly to: string

Defined in ​

core/message/Message.ts:14


agentId ​

• Optional Readonly agentId: any

Defined in ​

core/message/Message.ts:15


sessionId ​

• Optional Readonly sessionId: any

Defined in ​

core/message/Message.ts:16

Methods ​

validate ​

▸ validate(): void

Validate message structure

Returns ​

void

Throws

If message is invalid

Defined in ​

core/message/Message.ts:51


toPayloadString ​

▸ toPayloadString(): string

Convert message to payload string (JSON) for transmission Outgoing payload is configured here

Returns ​

string

JSON string

Defined in ​

core/message/Message.ts:68


fromJSON ​

▸ fromJSON(data, sessionContext): Message

Create a Message instance from JSON data (typically from WebSocket)

Parameters ​

NameType
dataany
sessionContextSessionContext

Returns ​

Message

Defined in ​

core/message/Message.ts:91


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 ​

core/message/Message.ts:128


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 ​

core/message/Message.ts:146


clone ​

▸ clone(updates?): Message

Create a copy of this message with updated fields

Parameters ​

NameType
updates?Partial<{ persona: Persona ; role: Role ; content: string ; messageId: string ; messageData: MessageData ; timestamp: number ; from: string ; to: string }>

Returns ​

Message

Defined in ​

core/message/Message.ts:164

Released under the MIT License.