This quick start places a phone call from a web page in three steps: your server mints a token with your API key, the page loads the Edesy SDK and calls connect() with that token, then device.call() dials the number. You need an Edesy account at webrtc.edesy.in and the API key from its Developers page.
Steps at a glance#
| Step | Where | What |
|---|---|---|
| 1 | Your server | POSThttps://webrtc.edesy.in/api/v1/token with x-api-key and an identity |
| 2 | Your server | Expose that JSON on your own URL, for example /edesy-token |
| 3 | Browser | EdesyVoice.connect("/edesy-token"), then device.call(number) |
1. Mint a token (server)#
curl -X POST https://webrtc.edesy.in/api/v1/token \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"identity": "agent-42"}'
The response holds the connection config the browser needs (server, username, password, callerId, viaTransport, iceServers, identity, expiresIn). Field details are on Token Endpoint.
2. Expose it on your own URL (server)#
A minimal Node.js (Express) route. Check that the user is signed in to your app before you mint a token for them.
app.post("/edesy-token", async (req, res) => {
// Use your own session: only signed-in users get a token.
const identity = req.user.id; // letters, digits, . _ @ - (max 64)
const r = await fetch("https://webrtc.edesy.in/api/v1/token", {
method: "POST",
headers: {
"x-api-key": process.env.EDESY_WEBRTC_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({ identity }),
});
res.status(r.status).json(await r.json());
});
3. Connect and call (browser)#
<script src="https://webrtc.edesy.in/sdk/edesy-voice.js"></script>
<button id="call">Call</button>
<script>
document.getElementById("call").onclick = async () => {
// connect() POSTs to your URL and resolves once registered
const device = await EdesyVoice.connect("/edesy-token");
const call = device.call("919876543210");
call.on("ringing", () => console.log("ringing"));
call.on("answered", () => console.log("answered"));
call.on("ended", () => console.log("ended"));
call.on("failed", (e) => console.error("failed", e));
};
</script>
The browser asks for microphone access on the first call. The page must be on HTTPS or localhost.
Prefer no code?#
Paste the drop-in dialer script tag instead of steps 3 onwards.
FAQ#
Why does the token have to come from my server?#
The token endpoint needs your API key. If the key were in browser code, anyone could read it and place calls on your account.
What should I use as the identity?#
A stable ID for the user in your system, such as a user ID or email. It must be 1 to 64 characters of letters, digits, ., _, @ or -.
Can I use npm instead of the hosted script?#
The package name is @edesy/voice-sdk and it exports the same connect(). The hosted bundle at https://webrtc.edesy.in/sdk/edesy-voice.js needs no build step.
What number format does call() take?#
The number with its country code and no plus sign, for example 919876543210.
The call fails straight away. What should I check?#
Check that connect() resolved (it rejects if the token URL returns an error), that the user allowed the microphone, and that the page is on HTTPS. Listen for the device error event and the call failed event to see the reason.
Which caller ID does the called person see?#
The caller ID set for your account, returned as callerId in the token response.