cagrik_8
11/05/2024, 11:49 AMAI Evy
11/05/2024, 11:49 AMAI Evy
11/05/2024, 11:50 AMbash
pip install retell-sdk
Initialize the client:
python
from retell import Retell
retell_client = Retell(
# Find the key in dashboard
api_key="YOUR_API_KEY",
)
Frontend Setup (JavaScript)
Install the Retell Web SDK [(2)]() :
bash
npm install retell-client-js-sdk
Set up the SDK class:
javascript
import { RetellWebClient } from "retell-client-js-sdk";
const retellWebClient = new RetellWebClient();
Starting the Call
After getting the access token from your backend, start the call:
javascript
await retellWebClient.startCall({
accessToken: createCallResponse.access_token,
});
You can also configure additional options:
javascript
await retellWebClient.startCall({
accessToken: createCallResponse.access_token,
sampleRate: 24000, // (Optional) set sample rate of the audio capture and playback
// (Optional) device id of the mic.
captureDeviceId: "default",
// (Optional) device id of the speaker
playbackDeviceId: "0ec1807fd0fe6e51b990660ec4e2ebb78sdfcba51e279815d00c423ce03407ff",
// (Optional) Whether to emit "audio" events that contain raw pcm audio bytes represented by Float32Array
emitRawAudioSamples: false,
});
Event Listeners
Set up event listeners for call status:AI Evy
11/05/2024, 11:50 AMjavascript
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);
// Stop the call
retellWebClient.stopCall();
});AI Evy
11/05/2024, 11:50 AMcagrik_8
11/05/2024, 11:51 AMAI Evy
11/05/2024, 11:51 AMAI Evy
11/05/2024, 11:52 AMbash
pip install retell-sdk
[(1)]()
Step 2: Install Frontend SDK
bash
npm install retell-client-js-sdk
[(2)]()
Step 3: Set up Python backend server with the following code:
python
from retell import Retell
retell_client = Retell(
# Find the key in dashboard
api_key="YOUR_API_KEY",
)
[(1)]()
Step 4: Set up Frontend JavaScript with:
javascript
import { RetellWebClient } from "retell-client-js-sdk";
const retellWebClient = new RetellWebClient();
[(2)]()
Step 5: Set up event listeners:
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);
// Stop the call
retellWebClient.stopCall();
});
For complete working examples and troubleshooting, you can check out the React demo repository [(3)]() . Based on the Discord discussions, there may be additional configurations needed for a fully working implementation.
I recommend checking out these resources for more detailed implementation help:
- [Contact Sales]()
- [Discord]()
- [https://github.com/RetellAI/]()AI Evy
11/05/2024, 11:52 AMcagrik_8
11/05/2024, 11:52 AMAI Evy
11/05/2024, 11:53 AMAI Evy
11/05/2024, 11:53 AMAI Evy
11/05/2024, 11:53 AM