def get_new_phonenumber(connection_string):
    try:
        phone_numbers_client = PhoneNumbersClient.from_connection_string(
            connection_string)
        capabilities = PhoneNumberCapabilities(
            calling=PhoneNumberCapabilityType.INBOUND,
            sms=PhoneNumberCapabilityType.INBOUND_OUTBOUND
        )
        search_poller = phone_numbers_client.begin_search_available_phone_numbers(
            "US",
            PhoneNumberType.TOLL_FREE,
            PhoneNumberAssignmentType.APPLICATION,
            capabilities,
            area_code="833",
            polling=True
        )
        search_result = search_poller.result()

        purchase_poller = phone_numbers_client.begin_purchase_phone_numbers(
            search_result.search_id, polling=True)
        purchase_poller.result()
        if(purchase_poller.status() == 'succeeded'):
            phone_number_list = search_result.phone_numbers
            for phone_number in phone_number_list:
                return phone_number

    except Exception as ex:
        return TEST_RECIPIENT_PHONENUMBER_DEFAULT
Exemple #2
0
def cf_communication_phonenumbers(cli_ctx, kwargs):
    from azure.communication.phonenumbers import PhoneNumbersClient

    connection_string = kwargs.pop('connection_string', None)
    if connection_string is None:
        error_msg = 'Please specify --connection-string, or set AZURE_COMMUNICATION_CONNECTION_STRING.'
        raise RequiredArgumentMissingError(error_msg)

    client = PhoneNumbersClient.from_connection_string(connection_string)
    return client
 def setUp(self):
     super(PhoneNumbersClientTest, self).setUp()
     if self.is_playback():
         self.phone_number = "sanitized"
         self.country_code = "US"
     else:
         self.phone_number = os.getenv("AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER")
         self.country_code = os.getenv("AZURE_COMMUNICATION_SERVICE_COUNTRY_CODE", "US")
     self.phone_number_client = PhoneNumbersClient.from_connection_string(self.connection_str)
     self.recording_processors.extend([
         BodyReplacerProcessor(
             keys=["id", "token", "phoneNumber"]
         ),
         PhoneNumberUriReplacer(),
         ResponseReplacerProcessor()])
    python update_phone_number_capabilities_sample.py
    Set the environment variables with your own values before running the sample:
    1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The connection string including your endpoint and 
        access key of your Azure Communication Service
    2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER - The phone number you want to update
"""

import os
from azure.communication.phonenumbers import (PhoneNumbersClient,
                                              PhoneNumberCapabilityType)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_to_update = os.getenv(
    "AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER"  # e.g. "+15551234567"
)
phone_numbers_client = PhoneNumbersClient.from_connection_string(
    connection_str)


def update_phone_number_capabilities():
    poller = phone_numbers_client.begin_update_phone_number_capabilities(
        phone_number_to_update,
        PhoneNumberCapabilityType.INBOUND_OUTBOUND,
        PhoneNumberCapabilityType.INBOUND,
        polling=True)
    poller.result()
    print('Status of the operation: ' + poller.status())


if __name__ == '__main__':
    update_phone_number_capabilities()
Exemple #5
0
def cf_communication_phonenumbers(cli_ctx, kwargs):
    from azure.communication.phonenumbers import PhoneNumbersClient
    connection_string = kwargs.pop('connection_string', None)
    client = PhoneNumbersClient.from_connection_string(connection_string)
    return client