Reputation: 16792
I was having some Twilio connectivity issues and thought I'd write a standalone script to reproduce the problem so that I could submit a ticket with Twilio. Unfortunately, I'm having some difficulty doing so.
Here's what I have:
<script src="https://sdk.twilio.com/js/taskrouter/v1.21/taskrouter.min.js"></script>
<script>
var worker = new Twilio.TaskRouter.Worker('...', true);
worker.on('error', function(error) {
alert(error.code + ' ' + error.length);
});
</script>
When I run this code I get a Uncaught Error: Wrong number of segments
error in the JS console.
I prob need to pass the API Token, Account SID, Auth token and app sid to Twilio but it's not clear to me how to do that. Are the Twilio PHP API libraries supposed to generate some JS that'll authenticate against Twilio?
Upvotes: 1
Views: 390
Reputation: 73027
When you initialize a Twilio.TaskRouter.Worker
the first argument you need to supply is a Capability Token. A Capability Token is a JSON Web Token (JWT) that you generate on your server and sign it with your Auth Token.
The instructions for how to construct a Capability Token for a TaskRouter Worker are in the documentation. Each of the Twilio server side helper libraries have functions for generating these tokens. You can see examples of generating a token on this page about managing workers in the browser.
Upvotes: 1