utkarsh_retell_48744
11/04/2024, 7:27 PMAI Evy
11/04/2024, 7:27 PMAI Evy
11/04/2024, 7:27 PMjavascript
npm install retell-client-js-sdk
2. Set up the SDK class:
javascript
import { RetellWebClient } from "retell-client-js-sdk";
const retellWebClient = new RetellWebClient();
3. Call create-web-call API from your server to get an access token. Note: The token expires in 30 seconds if unused.
4. Start the call with the access token:
javascript
await retellWebClient.startCall({
accessToken: createCallResponse.access_token,
});
5. You can listen to events for real-time updates:
javascript
retellWebClient.on("call_started", () => {
console.log("call started");
});
retellWebClient.on("call_ended", () => {
console.log("call ended");
setIsCallActive(false);
});
retellWebClient.on("agent_start_talking", () => {
console.log("agent_start_talking");
});
retellWebClient.on("agent_stop_talking", () => {
console.log("agent_stop_talking");
});
retellWebClient.on("update", (update) => {
// console.log(update);
});
retellWebClient.on("error", (error) => {
console.error("An error occurred:", error);
retellWebClient.stopCall();
});
6. To end the call:
javascript
retellWebClient.stopCall();AI Evy
11/04/2024, 7:27 PM