WebSocket Communication
Real-time bidirectional communication with automatic reconnection and exponential backoff for reliability.
TypeScript-first SDK for eGain's AI Agent platform with WebSocket communication, automatic reconnection, and comprehensive message handling.
The example below uses the pre-auth option — your server obtains an access token and passes it to the SDK. To generate one, follow the instructions for Generating An Access Token using PKCE.
Required scopes:
core.aiservices.readknowledge.portalmgr.managecore.customermgr.read (required for AI Agent for Customer Self Service only)npm install @egain/ai-agent-sdkimport { AiAgent } from "@egain/ai-agent-sdk";
const agent = new AiAgent({
id: "your-agent-id",
endpoint: "https://your-endpoint.com",
auth: { type: "pre-auth", accessToken: "your-access-token" },
autoConnect: true
});
await agent.initialize();
agent.on("agentMessage", (event) => {
console.log("Agent:", event.payload.message?.content);
});
await agent.send("Hello, agent!");Built for production use with comprehensive logging, error handling, and connection management.
TypeScript-first design with excellent IDE support, autocomplete, and inline documentation.
Extensible message handlers, pluggable cache adapters, and customizable authentication strategies.
Tree-shakable with zero framework dependencies. Use only what you need.