Does Twilio support lookup request using a subAccountSID instead of the accountSID?
I want this in order to organize the invoices for my clients and don't have to rely on creating my own log for that.
Twilio developer evangelist here.
If you want to use the subaccount details, you just need the subaccount sid and auth token. Then you can setup the lookups client like this:
const string subAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string subAuthToken = "subaccount_auth_token";
var lookupsClient = new LookupsClient(subAccountSid, subAuthToken);
// Look up a phone number in E.164 format
var phoneNumber = lookupsClient.GetPhoneNumber("+15108675309", true);
Related
How can I find available Twilio numbers based on the US state?
When we are in the Twilio console, there is a criteria where we can add a number and select "match to = first part of number", which I guess works with regex conditions / patterns.
I am aware we can extract the state prefixes and to use the prefix for the state which we want to search and use it as some pattern.
In addition, I need to check for the voice capabilities.
I am referring to this API: https://www.twilio.com/docs/phone-numbers/api but I have a hard tome to understand the proper fields that needs to be used. Also, I found many StackOverflow questons pointing to a links to Twilio doc, that are no longer valid.
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
const statePrefix = '823';
const voiceCapabilty = true;
client.availablePhoneNumbers('US')
.then(/* do something */);
I am trying to use Twilio Video for which I need to obtain access tokens(jwt) from my app server.
Below is the NodeJS app server code that generates an Access token. In the below credentials, API_KEY_SECRET is required, I thought this is same as Twilio Auth token that can be found in the Twilio console.
Is my understanding correct ? if not, where can I find the API_KEY_SECRET ?
var AccessToken = require('twilio').AccessToken;
// Substitute your Twilio AccountSid and ApiKey details
var ACCOUNT_SID = 'accountSid';
var API_KEY_SID = 'apiKeySid';
var API_KEY_SECRET = 'apiKeySecret';
// Create an Access Token
var accessToken = new AccessToken(
ACCOUNT_SID,
API_KEY_SID,
API_KEY_SECRET
);
// Set the Identity of this token
accessToken.identity = 'example-user';
// Grant access to Conversations
var grant = new AccessToken.ConversationsGrant();
grant.configurationProfileSid = 'configurationProfileSid';
accessToken.addGrant(grant);
// Serialize the token as a JWT
var jwt = accessToken.toJwt();
console.log(jwt);
When you create API Key(API_KEY_SID) - you'll be shown the Key's secret(API_KEY_SECRET),
You'll use the the secret(API_KEY_SECRET) of the API Key(API_KEY_SID) you created in step 1 to generate an access-token(ACCESS_TOKEN) using the Twilio Helper Library
Detailed Explanation here - Twilio Authorization - Refer the step 1,2,3, Its explained with example in different languages, including Nodejs.
How do I search for phone number by prefix using the API? The Twilio "Buy A Number" tool lets you search for begins with term, but I don't see a way to do it using the API.
You can do:
AvailablePhoneNumbers/US/Local?Contains=703%
But that still finds numbers with 703 anywhere, not just the prefix. Only way I can see to do this is using the * single number search, a la:
AvailablePhoneNumbers/US/Local?Contains=703*******
But then how do I make that generic to any country? Have a lookup table of phone number lengths for every country so I can add the appropriate number of *'s?
Twilio provides this information in their API docs (Find phone numbers by number pattern).
For example using PHP:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACde6f132a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
"Contains" => "510555****"
));
foreach($numbers->available_phone_numbers as $number) {
echo $number->phone_number;
}
I have a subaccount S1 with one phone number S1N1. I have another Subaccount S2 with 100 phone numbers. I want to add all these 100 phone numbers in subaccount S2 as verified callerIds for subaccount S1.
How do I add all these 100 phone numbers as callerIDs for subaccount S2 without going through the entire process mentioned here 100 times. Is there a way I can verify all these numbers without having to repeat the process 100 times ?
You can use the REST API OutgoingCallerIds List Resource to write a script to do it for you. I'm not sure what language you're working in but an example in PHP would be:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACCOUNT_SID";
$token = "AUTH_TOKEN";
$client = new Services_Twilio($sid, $token);
// Loop over the list of caller_ids and echo a property for each one
foreach ($client->account->outgoing_caller_ids as $caller_id) {
// Verify CallerID for subaccount2
}
twilio javascript client set from number , Also how I can get the call sid after connect?
I tried to set the from Number in the call options like the next lines before connect and still the same issue in the javascript
$(document).ready(function () {
Twilio.Device.setup(token);
var connection = null;
$("#call").click(function () {
var params = { "Phone": $('#Phone').val(), "from":$('#Phone').val() };
connection = Twilio.Device.connect(params);
return false;
});
});
-- and inside the server side code vbnet when I am generating the token I added the next code but this doesn't solve the from number issue
Dim options As New CallOptions()
options.Record = True
options.From = model.FromNumber
Dim cap = New TwilioCapability(_settings.AccountSID, _settings.AuthToken)
cap.AllowClientOutgoing(_settings.ClientCallApplicationSID, options)
dim token = cap.GenerateToken()
Twilio evangelist here.
The params collection that you pass into the connect function is just a dictionary of key/value pairs. Those key/values simply get passed as parameters to the Voice URL that Twilio requests when Client makes its connection to Twilio, and you can use those parameters to dynamically generate some TwiML markup. Twilio does not do anything with them.
For example, if this is a PHP application, in the Voice URL you could do something like:
<Response>
<Dial>$_REQUEST['From']</Dial>
</Response>
One note of caution, Twilio already adds a parameter called from (which in the case of Client will be the client identifier set when you made your capability token) to the parameters sent to the Voice URL, so you might want to choose a different key name for your dictionary entry. I normally use a name like target for the key that holds the number that I want to dial.
Hope that helps.
To get the call sid, you can get it in connect event.
Please note that I am using Twilio JS v1.9.7
device.on('connect', function (conn) {
log('Successfully established call!');
//Get the CallSid for this call
callUUID = conn.outboundConnectionId;
console.log('CallSid: ' + callUUID);
});