Copy URL it should be something like https://xxxx-####.twil.io/capability-token
Paste this Capability token URL in your bubble plugin
Plugin Settings
Make sure you have all the plugin settings filled as shown below. Go to Plugins > Twilio Plugin > Fill out the username, password, accessTokenURL, & App Owner Email
Log Level
The value is a number that corresponds to the different levels of logging available. For best practice only change the log level when needed.
Option
Logging Type
0
TRACE
1
DEBUG
2
INFO
3
WARN
4
ERROR
5
SILENT
If you are using an old version of our plugin you may need to use the following function instead.
Create a quick client functions (capability token and voice function) LEGACY
Click "+" to create a new function, then select "Twilio Client Quickstart".
Then Enter your APP_SID ( you will find it under TwiML Apps, click your app then copy the app SID) and CALLER_ID (Your Twilio phone number formatted as +11231231234)
Under the function configuration code replace const identity = 'the_user_id' with const identity = event.identity
exports.handler = function (context, event, callback) {
const AccessToken = require('twilio').jwt.AccessToken;
const VoiceGrant = AccessToken.VoiceGrant;
// Prepare response
let response = new Twilio.Response();
// Add CORS Headers
let headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Content-Type": "application/json"
};
// Used when generating any kind of tokens
const twilioAccountSid = context.ACCOUNT_SID;
const twilioApiKey = context.TWILIO_API_KEY;
const twilioApiSecret = context.TWILIO_API_SECRET;
// Used specifically for creating Voice tokens
const outgoingApplicationSid = context.TWIML_APP_SID;
const identity = event.identity;
const ttl = 3600; //Time to live for the token, in seconds.
// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
outgoingApplicationSid: outgoingApplicationSid,
incomingAllow: true, // Optional: add to allow incoming calls
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(
twilioAccountSid,
twilioApiKey,
twilioApiSecret,
{ identity: identity,
ttl: ttl
}
);
token.addGrant(voiceGrant);
const jwt = token.toJwt();
console.log(jwt);
response.setHeaders(headers);
response.setStatusCode(200);
// Set body
response.setBody({
'identity': identity,
'token': jwt
});
// Return the response
callback(null, response);
};
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
console.log(event.To)
console.log(event.From)
if(event.To) {
// Wrap the phone number or client name in the appropriate TwiML verb
// if is a valid phone number
const attr = isAValidPhoneNumber(event.To) ? 'number' : 'client';
const dial = twiml.dial({
answerOnBridge: true,
callerId: context.CALLER_ID
});
dial[attr]({}, event.To);
} else {
twiml.say('Sorry unable to make the call!');
}
callback(null, twiml);
};
/**
* Checks if the given value is valid as phone number
* @param {Number|String} number
* @return {Boolean}
*/
function isAValidPhoneNumber(number) {
return /^[\d\+\-\(\) ]+$/.test(number);
};