Manage Phone Numbers
Phone numbers are a central part of the Telephony SDK. Phone numbers from different countries around the world can be provisioned and used to to communicate with other phone numbers.
Provisioning a phone number is a two-step process. First, a search must be performed for an available phone number using a specific country code. After the desired phone number is selected, the phone number can be provisioned to a Sudo.
Get Supported Countries
To get the list of supported countries, use the getSupportedCountries() method. The country code format currently supported is the two-letter format described in ISO 3166-1 alpha-2.
In sandbox mode, the "ZZ" country code is included to allow provisioning simulated phone numbers. Refer to the Telephony Simulator page for details.
try! telephonyClient.getSupportedCountries { result in
switch result {
case .success(let countries):
// countries: list of strings containing the country ISO codes
case .failure(let error):
// error: SudoTelephonyClientError
}
}telephonyClient.getSupportedCountries { result ->
when (result) {
is Result.Success -> {
// result.value.countries: list of strings containing
// the country ISO codes
}
is Result.Error -> {
// result.throwable: telephonysdk.Result.Error
}
}
}Search Available Phone Numbers
A search for a phone number can be performed using either a country code, a country code plus phone number prefix (e.g., in the United States the prefix is called an "area code") or a latitude and longitude. A limit can be provided to ensure a maximum number of results are returned.
By Country Only
To search for a phone number by country code, use the searchAvailablePhoneNumbers() method and provide the two-character ISO country code.
By Country and Prefix
To search for a phone number by country code and prefix, use the searchAvailablePhoneNumbers() method and provide the two-character country code and prefix digits.
By Latitude and Longitude
To search for a phone number by country code and latitude/longitude, use the searchAvailablePhoneNumbers() method and provide the two-character country code and latitude/longitude. This function finds geographically close numbers within miles. Applies to only phone numbers in the US and Canada.
Search Result
Both calls to searchAvailablePhoneNumbers() return a AvailablePhoneNumberResult (iOS) / PhoneNumberSearchResult (Android) on success. The result contains a list of available numbers and the country code / prefix used in the search.
The Telephony SDK uses the E.164 phone number format for all string representations of phone numbers.
Provision Phone Number
After an available phone number is found, it can be provisioned to a Sudo using the provisionPhoneNumber() method. Provisioning a phone number to a Sudo makes it available to communicate with other phone numbers, such as sending and receiving SMS and MMS messages.
The Telephony SDK uses the E.164 phone number format for all string representations of phone numbers and this format is expected when provisioning a number.
Phone Number
The PhoneNumber type is returned when a phone number is provisioned. This type is expected in other places where a phone number is used, such as sending an SMS/MMS message.
Entitlements
Each user is allocated a limited number of phone numbers per Sudo. The current limit is 1 number per Sudo. In the future this value will be configurable from the Admin Console. If an attempt is made to provision a number in excess of the entitlements, and error will be returned from the SDK.
De-Provision Phone Number
A previously provisioned phone number can be de-provisioned by using the deletePhoneNumber() method. This method expects an E.164 phone number format formatted phone number string. The phone number must have already been provisioned for this to succeed.
Retrieving Existing Phone Numbers
Previously provisioned numbers can be retrieved using a phone number identifier or by retrieving all provisioned numbers.
Using Phone Number ID
You can retrieve a previously provisioned phone numbers by using the getPhoneNumber() method.
All Provisioned Phone Numbers
To retrieve all provisioned phone numbers, use the listPhoneNumbers() method. This method supports paging using the limit and nextToken parameters, and optionally filters by sudo id.
The result of the listPhoneNumbers() call is a TelephonyListToken as described below.
Retrieve Multiple Phone Numbers Result
When multiple phone numbers are retrieved, for example through the getPhoneNumbers() method, a list token object is returned which includes a list of phone numbers and a paging token used to retrieve the next set of results.
Last updated