Hamsa Voice Agent Web SDK
Hamsa Voice Agents Web SDK is a JavaScript library for integrating voice agents from https://dashboard.tryhamsa.com. This SDK provides a seamless way to incorporate voice interactions into your web applications.Features
- Easy Integration: Utilize WebSocket for real-time communication.
- Audio Support: Record and playback audio effortlessly.
- Low Latency: Optimized for quick voice interactions.
- Compatibility: Works in both Node.js and browser environments.
Installation
Install the SDK via npm:HamsaVoiceAgent Class And Functionality
The core of the SDK is theHamsaVoiceAgent
class, which extends the EventEmitter
class from Node.js. This design allows the SDK to easily handle and emit events, enabling developers to respond to various states of the voice interaction process.
Usage
First, import the package in your code:Start a Conversation with an Existing Agent
Start a conversation with an existing agent by calling the “start” function. You can create and manage agents in our Dashboard or using our API here:"Hello {{name}}, how can I help you today?"
and pass the "name"
as a parameter to use the correct name of the user.
Pause/Resume a Conversation
To pause the conversation, call the"pause"
function. This will prevent the SDK from sending or receiving new data until you resume the conversation:
End a Conversation
To end a conversation, simply call the"end"
function:
Events
During the conversation, the SDK emits events to update your application about the conversation status.Conversation Status Events
Agent Status Events
Conversation Script Events
Error Events
Usage Example
To use the SDK effectively, developers should follow these steps:- Initialize the SDK: Create an instance of
HamsaVoiceAgent
with the API key. - Set Up Event Listeners: Listen for events like
callStarted
,callEnded
,callPaused
, andcallResumed
to manage the call lifecycle. - Start a Voice Call: Invoke the
start()
method to begin the interaction. - Manage the Call: Use
pause()
,resume()
, andend()
methods as needed to control the flow of the conversation.
Conclusion
The Hamsa Voice Agent Web SDK simplifies the integration of voice capabilities into web applications, offering powerful features for real-time communication. By leveraging the functionalities of theHamsaVoiceAgent
class, developers can create engaging voice-enabled experiences with ease.