record

View as Markdown

record

Generic method to record a call.

Please use recordAudio.

Parameters

params
objectRequired

Object containing the parameters for recording the call.

audio
objectRequired

Audio recording configuration. See the parameters for recordAudio.

listen
object

Callback to listen for events. List of recording events can be found here. Example event: onStarted.

Returns

Promise<CallRecording>

A promise that resolves to a CallRecording object that you can use to view the current state and results of the recording session.

Example

In this example, we dial a phone number and record the call audio. During the recording, we play a TTS message. Once the TTS message is finished, we hangup the call and print the URL of the recording to console.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7// Listen for incoming calls
8await voiceClient.listen({
9
10 topics: ["office"],
11 onCallReceived: async (call) => {
12 console.log("Call received");
13 // Answer the call
14 call.answer();
15
16 await call.record({
17 audio: {
18 format: "mp3",
19 direction: "both",
20 stereo: true,
21 beep: true,
22 terminators: "#",
23 endSilenceTimeout: 0,
24 initialTimeout: 0
25 },
26 listen: {
27 onStarted: async (recording) => {
28 console.log("Recording started");
29 await call.playTTS({
30 text: "This is a call recording test."
31 });
32 recording.stop();
33 },
34 onFailed: () => console.log("Recording failed"),
35 onUpdated: (event) => console.log("Recording updated", event.state),
36 onEnded: (event) => {
37 console.log("Recording ended", event.url, event.state)
38 call.hangup();
39 }
40 }
41 }).onStarted();
42 }
43});