jaidami_21355
09/02/2025, 5:03 PMAI Evy
09/02/2025, 5:03 PMAI Evy
09/02/2025, 5:03 PMjavascript
// install the sdk: <https://docs.retellai.com/get-started/sdk>
import { Retell } from "retell-sdk";
import express, { Request, Response } from "express";
const app = express() ;
app.use(express.json() ) ;
app.post("/webhook", (req: Request, res: Response) => {
const {event, call} = req.body;
switch (event) {
case "call_started":
console.log("Call started event received", call.call_id) ;
break;
case "call_ended":
console.log("Call ended event received", call.call_id) ;
break;
case "call_analyzed":
console.log("Call analyzed event received", call.call_id) ;
break;
default:
console.log("Received an unknown event:", event) ;
}
// Acknowledge the receipt of the event
res.status(204) .send() ;
}) ;
2. Test locally - Test your endpoint on localhost:8080/webhook using this CURL command :
bash
curl --location 'localhost:8080/webhook' \
--header 'Content-Type: application/json' \
--data '{
"event": "call_ended",
"call": {
"call_type": "phone_call",
"from_number": "+12137771234",
"to_number": "+12137771235",
"direction": "inbound",
"call_id": "Jabr9TXYYJHfvl6Syypi88rdAHYHmcq6",
"agent_id": "oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
"call_status": "registered",
"metadata": {},
"retell_llm_dynamic_variables": {
"customer_name": "John Doe"
},
"start_timestamp": 1714608475945,
"end_timestamp": 1714608491736,
"disconnection_reason": "user_hangup",
"transcript": "...",
"opt_out_sensitive_data_storage": false
}
}'
3. Make your endpoint online - Deploy using Ngrok :
bash
brew install ngrok/ngrok/ngrok
bash
ngrok http <http://localhost:8080>AI Evy
09/02/2025, 5:03 PMcall_started, call_ended, and call_analyzed [(2) ]() . The webhook will POST the payload to your endpoint with a 10-second timeout and up to 3 retries .AI Evy
09/02/2025, 5:03 PMAI Evy
09/02/2025, 5:03 PM