Send and Receive DTMF
Dual Tone Multi Frequency (DTMF), is a form of signalling used by phone systems to transmit the digits 0-9 and the * and # characters. Typically a caller presses these buttons on their telephone keypad and the phone then generates a tone made up of two frequencies played simultaneously (hence Dual Tone).
DTMF is used both for dialing a destination on a landline telephone and also for signalling to the remote end once a call is answered. Typically this is used to implement an Interactive Voice Response (IVR) system, or to enter information like a PIN number or conference call pin.
This guide covers how you can send and receive DTMF input with the Client SDK. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS) and you are able to make or receive calls.
Send DTMF
You can send DTMF tones in to an ongoing call.
// After creating a session
client.sendDTMF(callId, "1234")
.then(() => {
console.log("Success sending DTMF.");
})
.catch(error => {
console.error("Error sending DTMF: ", error);
});
client.sendDTMF(callID, "1234") {
error ->
when {
error != null -> {
// Handle DTMF error
}
}
}
During an ongoing call, where your backend implemented an NCCO with an Input action, sending a DTMF will trigger the defined "eventUrl".
Receive DTMF
Whenever a member in a call sends a DTMF event, all of the other call members are notified about that event.
// After creating a session
client.on("dtmf", (callId, legId, digits) => {
console.log(`leg: ${legId}: has received DTMF digits ${digits}`);
});
client.setOnDTMFListener { callId, legId, digits ->
...
}
Add the current ViewController, or similar, as a delegate for the voice client:
ViewController will now have to conform to VGVoiceClientDelegate, the DTMF events will be received on the didReceiveDTMFForCall delegate method: