0

I am trying to make an outbound call with Twilio Voice SDK in HTML.

I am getting the following error when I instantiate Twilio.Call function

const device = new Device(token);
 params = {
        params: {
            To: phone
        }
    };
const call = device.connect(params);
var callTemp = new Twilio.Call(call);

Error

Uncaught TypeError: Cannot read properties of undefined (reading 'info')
at Object.Call (twilio.min.js:1:26960)
at HTMLDivElement.eval (eval at <anonymous> (jquery.min.js:4:4994), <anonymous>:501:20)
at HTMLDivElement.dispatch (jquery.min.js:5:14129)
at v.handle (jquery.min.js:5:10866)

What is the correct way to instantiate the Twilio.Call?

Piyush Bansal
  • 1,635
  • 4
  • 16
  • 39

1 Answers1

1

You should not instantiate a Twilio.Call object yourself. The method device.connect returns a promise that resolves to a Twilio.Call object.

const device = new Device(token);
device.connect().then(call => {
  // Now you have the Twilio.Call object
})

Or with async/await:

const device = new Device(token);
const call = await device.connect();
philnash
  • 70,667
  • 10
  • 60
  • 88
  • How to use "const call = await device.connect();" this call instance to invoice sendDigit() function? The example you posted is a nodeJS example. I am using HTML and JS. – Piyush Bansal Aug 30 '22 at 05:06
  • My example is JS, not Node. You don’t have to use await if you don’t want to though, you can use the promise like in the first example. – philnash Aug 30 '22 at 14:41