@egain/ai-agent-sdk API Reference - v0.1.1 / AgentMessageHandler
Class: AgentMessageHandler
Handler for agent messages (main chat responses) Processes agent messages and extracts follow-up options, escalation data, sources, and reasoning
Hierarchy
↳
AgentMessageHandler
Table of contents
Constructors
Methods
Constructors
constructor
• new AgentMessageHandler(): AgentMessageHandler
Returns
Inherited from
BaseMessageHandler.constructor
Methods
canHandle
▸ canHandle(message): boolean
Check if this handler can process the given message.
This method is called for each incoming message. Return true if this handler should process the message, false otherwise.
Parameters
| Name | Type | Description |
|---|---|---|
message | Message | The incoming message to check |
Returns
boolean
true if this handler can process the message
Example
canHandle(message: Message): boolean {
// Handle only customer messages
return message.persona === 'customer';
}Overrides
Defined in
core/message/handlers/AgentMessageHandler.ts:11
handle
▸ handle(message): MessageHandlerResult
Process the message.
Called when canHandle returns true. Implement your message processing logic here. Can be synchronous or asynchronous.
Parameters
| Name | Type | Description |
|---|---|---|
message | Message | The message to process |
Returns
Handler result or Promise resolving to result
Example
handle(message: Message): MessageHandlerResult {
return {
type: 'processed',
message,
timestamp: Date.now()
};
}Example
async handle(message: Message): Promise<MessageHandlerResult> {
await saveToDatabase(message);
return {
type: 'saved',
message,
timestamp: Date.now()
};
}