Skip to content

@egain/ai-agent-sdk API Reference - v0.1.1 / ChatHistoryHandler

Class: ChatHistoryHandler

Handler for chat history messages Processes system messages containing chat history data

Hierarchy

Table of contents

Constructors

Methods

Constructors

constructor

new ChatHistoryHandler(): ChatHistoryHandler

Returns

ChatHistoryHandler

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

NameTypeDescription
messageMessageThe incoming message to check

Returns

boolean

true if this handler can process the message

Example

typescript
canHandle(message: Message): boolean {
  // Handle only customer messages
  return message.persona === 'customer';
}

Overrides

BaseMessageHandler.canHandle

Defined in

core/message/handlers/ChatHistoryHandler.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

NameTypeDescription
messageMessageThe message to process

Returns

MessageHandlerResult

Handler result or Promise resolving to result

Example

typescript
handle(message: Message): MessageHandlerResult {
  return {
    type: 'processed',
    message,
    timestamp: Date.now()
  };
}

Example

typescript
async handle(message: Message): Promise<MessageHandlerResult> {
  await saveToDatabase(message);
  return {
    type: 'saved',
    message,
    timestamp: Date.now()
  };
}

Overrides

BaseMessageHandler.handle

Defined in

core/message/handlers/ChatHistoryHandler.ts:18

Released under the MIT License.