I am trying to send a DTMF Numeric value in Twilio with the code below but it seems that the string interpolation is not working:
<sendDTMF digits="variable"/>
I was able to hard code it to <sendDTMF digits="123456"/> and it worked for testing .
I've tried the following but it's also not working:
<sendDTMF digits="{variable}"/>
<sendDTMF digits=$"{variable}"/>
Twilio developer evangelist here.
As Alan has said in a comment, there are 3 ways to send DTMF over a phone call. I'll go into each of them in a bit of depth here.
Firstly, while on a call you can use the
<Play>TwiML element to send DTMF. To do so, you use thedigitsattribute, like this:You can add spaces between the numbers using
w, eachwadds 0.5 seconds gap between other digits.Also, on a call, when making dialling on to a new number using the
<Number>element you can send DTMF tones that will be played when the call is picked up before connecting the dialler using thesendDigitsattribute. That looks like this:Using
<Number>to dial and send digits is useful when you have an incoming call that you are connecting to another number. When you are making an outbound call you can also pass theSendDigitsparameter along with the rest of the call parameters. Like with<Number>, the digits will be played down the call and then it will connect.That looks like this: