Twilio javascript SDK .sendDigits example needed -

180 views Asked by At

I have tried a dozen ways to make a button on a webpage that's got a connected Twilio client voice call perform .sendDigits. This is the most recent try.

const dtmf_1 = document.getElementById('DTMF1');
dtmf_1.onclick = function(){call.sendDigits('1')};

This returns

Uncaught ReferenceError: call is not defined at dtmf_1.onclick (quickstart.js:46:79)

Frankly, I have no idea if fixing the reference is even going to work. Does anyone have an example of working code that will play a DTMF tone on a live call with the Twilio JavaScript SDK?

1

There are 1 answers

0
Sully1570 On

Thanks to a timely comment by Tristan Blackwell (see above), I was able to fix this issue which was indeed a scoping problem.

The fix was to put the line

dtmf_1.onclick = function(){call.sendDigits('1')};

right under the line where the call is connected.

const call = await device.connect({ params });

Like so

      const call = await device.connect({ params });
      dtmf_1.onclick = function(){call.sendDigits('1')};