CallDetect
Represents a current or past detecting session in a call.
Obtain instances of this class by starting a Detect session with one of the following methods:
Example
Detecting answering machines and handling the result:
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
const call = await client.voice.dialPhone({
from: "+1xxxxxxxxxx",
to: "+1yyyyyyyyyy",
timeout: 30
});
// Start answering machine detection with event listeners
const detect = await call.detectAnsweringMachine({
timeout: 30,
initialTimeout: 4,
endSilenceTimeout: 1,
machineReadyTimeout: 3,
waitForBeep: true,
listen: {
onStarted: () => console.log("AMD detection started"),
onUpdated: (detect) => {
console.log("Detection update:", detect.result);
if (detect.result === "HUMAN") {
console.log("Human answered - connecting to agent");
} else if (detect.result === "MACHINE") {
console.log("Machine detected - waiting for beep");
} else if (detect.result === "READY") {
console.log("Machine ready for message - leaving voicemail");
call.playTTS({ text: "Hello, this is a message from SignalWire." });
}
},
onEnded: (detect) => {
console.log("Detection ended with result:", detect.result);
}
}
}).onStarted();
// Wait for detection to complete
await detect.ended();
console.log("Final result:", detect.result, "Type:", detect.type);
Detecting DTMF digits:
// Detect specific digits pressed during a call
const detect = await call.detectDigit({
digits: "0123456789#*",
timeout: 30,
listen: {
onUpdated: (detect) => {
console.log("Digit detected:", detect.result);
}
}
}).onStarted();
Detecting fax tones:
// Detect if the call is a fax machine
const detect = await call.detectFax({
tone: "CED", // or "CNG"
timeout: 30,
listen: {
onUpdated: (detect) => {
console.log("Fax tone detected:", detect.result);
}
}
}).onStarted();
Properties
The result of the detecting session. The possible values depend on the detection type:
| Detect Type | Event Values |
|---|---|
amd | detectAnsweringMachine | MACHINE: Machine detected, HUMAN: Human detected (final event), UNKNOWN: Unknown detection, READY: Machine is ready for voicemail delivery (final event if detect_interruptions=false or beep=true), NOT_READY: Machine voicemail has restarted, interrupting voicemail delivery (only fired if detect_interruptions=true) |
detectDigit | Possible digits detected: 0 1 2 3 4 5 6 7 8 9 # * |
detectFax | CED: called station fax tone, CNG: calling station fax tone |
Methods
ended
▸ ended(): Promise<CallDetect>
Returns a promise which will get resolved only after the detecting session is completed.
Returns
Promise<CallDetect> - See CallDetect for more details.
Example
const detect = await call.detectDigit();
const result = await detect.ended();
console.log("Detect result:", result.type);
stop
▸ stop(): Promise<CallDetect>
Stops the detect session.
Returns
Promise<CallDetect> - See CallDetect for more details.
Example
const detect = await call.detectDigit();
await detect.stop();
Events
onStarted
▸ CallDetect.listen({ onStarted: Callback }})
Emitted when the detecting session has started. Your event handler will be called with an instance of CallDetect.
Parameters
The detecting session that has started. See CallDetect.
onUpdated
▸ CallDetect.listen({ onUpdated: Callback }})
Emitted when the detecting session has been updated. Your event handler will be called with an instance of CallDetect.
Parameters
The detecting session that has updated. See CallDetect.
onEnded
▸ CallDetect.listen({ onEnded: Callback }})
Emitted when the detecting session has ended. Your event handler will be called with an instance of CallDetect.
Parameters
The detecting session that has ended. See CallDetect.