forked from simliai/simli-retell-frontend-reactjs-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 1.04 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors'); // Import CORS module
const Retell = require('retell-sdk');
require('dotenv').config();
const app = express();
const port = 8080;
app.use(cors()); // Enable CORS for all routes
app.use(bodyParser.json());
const retell = new Retell({apiKey:process.env.REACT_APP_RETELL_KEY});
app.post('/register-call-on-your-server', async (req, res) => {
try {
const agentId = req.body.agentId;
const registerCallResponse = await retell.call.register({
agent_id: agentId,
audio_encoding: 's16le',
audio_websocket_protocol: 'web',
sample_rate: 16000,
end_call_after_silence_ms: 20000,
});
res.json({
callId: registerCallResponse.call_id,
sampleRate: 16000,
});
} catch (error) {
console.error("Failed to register call:", error);
res.status(500).json({ error: "Failed to register call" });
}
});
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});