简体   繁体   中英

can I send DTMF variable in Twilio IVR as in <sendDTMF digits="variable"/> format?

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 the digits attribute , like this:

<Response>
  <Play digits="1234"/><Play>
</Response>

You can add spaces between the numbers using w , each w adds 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 the sendDigits attribute. That looks like this:

<Response>
  <Dial>
    <Number sendDigits="1234"/>NUMBER_TO_DIAL</Number>
  </Dial>
</Response>

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 the SendDigits parameter 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:

curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls.json \
  --data-urlencode "Twiml=<Response><Say>Ahoy there</Say></Response>" \
  --data-urlencode "To=+15558675310" \
  --data-urlencode "From=+15552223214" \
  --data-urlencode "SendDigits=1234" \
  -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM