agentphone-web-sdk
v0.1.0
Published
Browser SDK for AgentPhone web calls
Maintainers
Readme
agentphone-web-sdk
Browser SDK for AgentPhone web calls. Lets your users talk to an AgentPhone agent directly from the browser — no phone number required.
Install
npm install agentphone-web-sdkQuick start
1. Get an access token (server-side)
const res = await fetch("https://api.agentphone.ai/v1/calls/web", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.AGENTPHONE_API_KEY,
},
body: JSON.stringify({ agentId: "your-agent-id" }),
});
const { accessToken } = await res.json();2. Start the call (client-side)
import { AgentPhoneWebClient } from "agentphone-web-sdk";
const client = new AgentPhoneWebClient();
await client.startCall({ accessToken });
client.on("call_started", () => console.log("Call started"));
client.on("call_ended", () => console.log("Call ended"));
client.on("error", (err) => {
console.error(err);
client.stopCall();
});API
new AgentPhoneWebClient()
Creates a new client instance.
client.startCall(config)
Start a web call. config accepts:
| Option | Type | Required | Description |
|---|---|---|---|
| accessToken | string | Yes | Token from POST /v1/calls/web |
| sampleRate | number | No | Audio capture/playback sample rate |
| captureDeviceId | string | No | Input device ID |
| playbackDeviceId | string | No | Output device ID |
| emitRawAudioSamples | boolean | No | Emit raw audio via the audio event |
client.stopCall()
End the call and clean up.
client.mute() / client.unmute()
Toggle microphone.
client.startAudioPlayback()
Manually start audio playback. Call inside a user gesture handler for browsers that block autoplay.
client.isAgentTalking
boolean — whether the agent is currently speaking.
Events
| Event | Payload | Description |
|---|---|---|
| call_started | — | Call connected |
| call_ended | — | Call disconnected |
| call_ready | — | Agent audio track ready |
| agent_start_talking | — | Agent started speaking |
| agent_stop_talking | — | Agent stopped speaking |
| update | transcript object | Real-time transcript |
| metadata | metadata object | Call metadata |
| node_transition | transition object | Conversation node changed |
| audio | Float32Array | Raw audio samples |
| error | error message | Error occurred |
License
MIT
