@hamsa-ai/voice-agents-sdk) starts calls with your Hamsa agents from a web page: voice calls through the visitor’s microphone, or text chats. You build the interface; the SDK connects the call, plays the agent, and tells your page what happens through events.
If you only need a button on your site, you don’t need the SDK: embed the widget with one script tag.
Before you start
- An agent published to an environment. Calls run what the environment (dev, staging or prod) serves, never the draft. See Environments and releases.
- A public key for that environment. Create it on the API keys page, under Website or app. Limit it to your site with Allowed origins.
- A secure page. Browsers give the microphone only to pages served over
https://, or fromlocalhostwhile you build. - A current browser. Chrome, Edge, Firefox or Safari, on desktop or mobile.
Install
window.HamsaVoiceAgent: the class is HamsaVoiceAgent.HamsaVoiceAgent and the error class is HamsaVoiceAgent.HamsaApiError.
Quickstart: a call button
A button that starts a call, shows what the agent is doing, and ends the call:start()gets a call token with your public key and connects the call.- The browser asks for the microphone the first time.
callStartedfires withjobId, the call’s ID. It’s the same ID you see in Call history and in the agent’s webhook.- The agent says its greeting, and
agentStateChangedfollows the conversation. agent.end(), or the agent ending the call, firescallEnded.
pk_... with your public key and YOUR_AGENT_ID with the agent’s ID (in the editor’s menu, Copy agent ID).
Pass values to the agent
params fill the agent’s variables. An agent whose greeting is “Hello {{customer_name}}” greets Sara by name:
Next steps
Start calls
Public keys or call tokens from your server, the microphone, and why a call can’t start.
During a call
End, pause, mute, volume, keypad digits and the call’s ID.
Chat
Text conversations without a microphone.
Events
Every event, what it sends, and live transcripts.
Audio
Levels, visualizers, and capturing the call’s audio.
Reference
Every option and method, with types.
Good to know
- Leaving the page ends the call. Closing the tab, reloading or going to another site hangs up. In a single-page app, keep the
HamsaVoiceAgentoutside the views that come and go. - The screen stays on during a call, on devices that support it. It can sleep again while the call is paused.
- Website calls count like phone calls. They use credits, count against your plan’s concurrent calls, show in Call history, and send the agent’s webhook.
- Page tools. The agent can call functions in your page, such as reading the cart. See Web tools.
- Debugging.
new HamsaVoiceAgent({ publicKey: "pk_...", debug: true })logs what the SDK does to the browser console.