0

Can anyone please guide me how do I integrate/require twilio.js file in the my application? I have to do it with angular.js app. I can't require/include it and can't get the Twilio object to call it's methods. I'm really new to it!

By just adding following script tag do not makes me able to use Twilio object:

<script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.4/twilio.js"></script>

Results:

enter image description here

Update:

As per @philnash help I've resolved the previous error and now this is how my code looks like is:

<script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.4/twilio.js"></script>
<script>
Twilio.Device.setup(@token, { debug: true, region: "ie1" });
Twilio.Device.ready(function(device) {
    // The device is now ready
    alert("Twilio.Device is now ready for connections");
});
</script>

But I'm getting the below error:

enter image description here

Any help will be appreciated!

hmd
  • 960
  • 2
  • 9
  • 13

1 Answers1

1

Twilio developer evangelist here.

When using the Twilio Client JavaScript, there is no Twilio.setup function.

Instead, you should use Twilio.Device.setup.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • thanks for your response! But after using `Twilio.Device.setup('token')`, now its giving me an error in console `TypeError: Cannot read property 'length' of undefined at objectize (twilio.js:6055)` and the code at mentioned line is `var scopes = (jwt.scope.length === 0 ? [] : jwt.scope.split(' '));`. I'm using [v1.4](//media.twiliocdn.com/sdk/js/client/v1.4/twilio.js). – hmd Dec 05 '17 at 22:47
  • Not entirely sure what's going on there. Can you share the code you're using? It's best to update your question and then let me know in the comments when you've done so. Cheers! – philnash Dec 06 '17 at 07:07
  • 1
    Ok, cool. So what is `@token` in this case? You should be generating a [capability token](https://www.twilio.com/docs/api/client/capability-tokens) that you generate on your server and fetch from the front end. – philnash Dec 06 '17 at 20:05
  • that's the point! I need to use [capability-tokens](https://www.twilio.com/docs/api/client/capability-tokens) and I was using the token for voice at this place. Its working now! Thanks a lot for your great help! – hmd Dec 07 '17 at 10:51