Reputation: 69
Hi everyone Im using twilio voice javascript sdk with ngrok that i found their repository in GitHub the installation went good when i try to click on start up the device to get the client name from my name generator js an error has showed and i can not get the client client name or make any calls
i have set up my index js with all my account sid and phone number and twiml app sid and Twilio api secret key
cmd error
Error: identity is required to be specified in options
at new AccessToken (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\twilio\lib\jwt\AccessToken.js:202:19)
at tokenGenerator (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\src\handler.js:13:23)
at C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\src\router.js:7:12
at Layer.handle [as handle_request] (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\layer.js:95:5) at next (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\layer.js:95:5) at C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:284:15
at Function.process_params (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:346:12)
at next (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:280:10)
ngrok error when i click on start up the device
HTTP Requests
-------------
GET /quickstart.js 200 OK
GET /twilio.min.js 200 OK
GET /site.css 200 OK
GET / 200 OK
GET / 502 Bad Gateway
config.js
const dotenv = require("dotenv");
const cfg = {};
if (process.env.NODE_ENV !== "test") {
dotenv.config({ path: ".env" });
} else {
dotenv.config({ path: ".env.example", silent: true });
}
// HTTP Port to run our web application
cfg.port = process.env.PORT || 3000;
// Your Twilio account SID and auth token, both found at:
// https://www.twilio.com/user/account
//
// A good practice is to store these string values as system environment
// variables, and load them from there as we are doing below. Alternately,
// you could hard code these values here as strings.
cfg.accountSid = process.env.TWILIO_ACCOUNT_SID;
cfg.twimlAppSid = process.env.TWILIO_TWIML_APP_SID;
cfg.callerId = process.env.TWILIO_CALLER_ID;
cfg.apiKey = process.env.TWILIO_API_KEY;
cfg.apiSecret = process.env.TWILIO_API_SECRET;
// Export configuration object
module.exports = cfg;
Upvotes: 3
Views: 767
Reputation: 17372
For twilio-cli
if you're getting
twilio-cli encountered an unexpected error. ... execute the command with the "-l debug" flag etc
and
[DEBUG] identity is required to be specified in options
when passing --identity=Dave
Update the code in accessToken.js
-> ~/.twilio-cli/node_modules/@twilio-labs/plugin-token/src/helpers/accessToken.js
from:
const accessToken = new Twilio.jwt.AccessToken(
this.twilioClient.accountSid,
this.twilioClient.username,
this.twilioClient.password,
);
to:
const accessToken = new Twilio.jwt.AccessToken(
this.twilioClient.accountSid,
this.twilioClient.username,
this.twilioClient.password,
{ identity: this.flags['identity'] }
);
Upvotes: 2
Reputation: 3816
Better late than never, I just ran in a similar issue and wanted to leave a hint here.
With version 4 of the Node.js client twilio
, you now need to supply a identity
property in the config.
const token = new AccessToken(
TWILIO_ACCOUNT_SID,
TWILIO_API_KEY,
TWILIO_API_SECRET,
{ identity },
);
If this is missing, you get the error you mentioned above. You can fix it by adding the identify or by downgrading the twilio dependency if you can't edit the code.
Upvotes: 1
Reputation: 3816
Have you tried logging the cfg
object to see whether it contains all the expected values?
You can do this when you end the config.js
file as follows:
console.log(cfg);
// Export configuration object
module.exports = cfg;
Upvotes: 0