-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eason Yang
committed
Oct 1, 2020
1 parent
2702269
commit 3a18889
Showing
13 changed files
with
762 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ommunication/azure-communication-administration/samples/phone_number_area_codes_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_area_codes_sample.py | ||
DESCRIPTION: | ||
These samples demonstrate area codes samples. | ||
///getting all area codes via a connection string, country code and phone plan id | ||
USAGE: | ||
python phone_number_area_codes_sample.py | ||
""" | ||
import os | ||
from azure.communication.administration import ( | ||
PhoneNumberAdministrationClient | ||
) | ||
|
||
class CommunicationAreaCodesSamples(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") | ||
self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") | ||
|
||
def get_all_area_codes(self): | ||
all_area_codes = self._phone_number_administration_client.get_all_area_codes( | ||
location_type="NotRequired", | ||
country_code=self.country_code, | ||
phone_plan_id=self.phone_plan_id_area_codes | ||
) | ||
print('all_area_codes:') | ||
print(all_area_codes) | ||
|
||
if __name__ == '__main__': | ||
sample = CommunicationAreaCodesSamples() | ||
sample.get_all_area_codes() |
47 changes: 47 additions & 0 deletions
47
...cation/azure-communication-administration/samples/phone_number_area_codes_sample_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_area_codes_sample.py | ||
DESCRIPTION: | ||
These samples demonstrate area codes samples. | ||
///getting all area codes via a connection string, country code and phone plan id | ||
USAGE: | ||
python phone_number_area_codes_sample.py | ||
""" | ||
import os | ||
import asyncio | ||
from azure.communication.administration.aio import PhoneNumberAdministrationClient | ||
|
||
class CommunicationAreaCodesSamplesAsync(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") | ||
self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") | ||
|
||
async def get_all_area_codes(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
async with self._phone_number_administration_client: | ||
all_area_codes = await self._phone_number_administration_client.get_all_area_codes( | ||
location_type="NotRequired", | ||
country_code=self.country_code, | ||
phone_plan_id=self.phone_plan_id_area_codes | ||
) | ||
print('all_area_codes:') | ||
print(all_area_codes) | ||
|
||
async def main(): | ||
sample = CommunicationAreaCodesSamplesAsync() | ||
await sample.get_all_area_codes() | ||
|
||
if __name__ == '__main__': | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) |
63 changes: 63 additions & 0 deletions
63
...munication/azure-communication-administration/samples/phone_number_capabilities_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_capabilities_sample.py | ||
DESCRIPTION: | ||
These samples demonstrate number capabilities samples. | ||
///getting number capabilities via a connection string, capabilities update id and phone number for capabilities | ||
USAGE: | ||
python phone_number_capabilities_sample.py | ||
""" | ||
import os | ||
from azure.communication.administration import ( | ||
PhoneNumberAdministrationClient, | ||
NumberUpdateCapabilities | ||
) | ||
|
||
class CommunicationNumberCapabilitiesSamples(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") | ||
self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', "+17771234567") | ||
|
||
def list_all_phone_numbers(self): | ||
list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() | ||
print('list_all_phone_numbers_response:') | ||
for phone_number in list_all_phone_numbers_response: | ||
print(phone_number) | ||
|
||
def get_capabilities_update(self): | ||
capabilities_response = self._phone_number_administration_client.get_capabilities_update( | ||
capabilities_update_id=self.capabilities_id | ||
) | ||
print('capabilities_response:') | ||
print(capabilities_response) | ||
|
||
def update_capabilities(self): | ||
update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) | ||
|
||
phone_number_capabilities_update = { | ||
self.phonenumber_for_capabilities: update | ||
} | ||
|
||
capabilities_response = self._phone_number_administration_client.update_capabilities( | ||
phone_number_capabilities_update=phone_number_capabilities_update | ||
) | ||
print('capabilities_response:') | ||
print(capabilities_response) | ||
|
||
if __name__ == '__main__': | ||
sample = CommunicationNumberCapabilitiesSamples() | ||
sample.list_all_phone_numbers() | ||
sample.get_capabilities_update() | ||
sample.update_capabilities() |
77 changes: 77 additions & 0 deletions
77
...tion/azure-communication-administration/samples/phone_number_capabilities_sample_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_capabilities_sample.py | ||
DESCRIPTION: | ||
These samples demonstrate number capabilities samples. | ||
///getting number capabilities via a connection string, capabilities update id and phone number for capabilities | ||
USAGE: | ||
python phone_number_capabilities_sample.py | ||
""" | ||
import asyncio | ||
import os | ||
from azure.communication.administration.aio import PhoneNumberAdministrationClient | ||
from azure.communication.administration import NumberUpdateCapabilities | ||
|
||
|
||
class CommunicationNumberCapabilitiesSamplesAsync(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") | ||
self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', | ||
"phone-number-for-capabilities") | ||
|
||
async def list_all_phone_numbers(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
async with self._phone_number_administration_client: | ||
list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() | ||
print('list_all_phone_numbers_response:') | ||
async for phone_number in list_all_phone_numbers_response: | ||
print(phone_number) | ||
|
||
async def get_capabilities_update(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
async with self._phone_number_administration_client: | ||
capabilities_response = await self._phone_number_administration_client.get_capabilities_update( | ||
capabilities_update_id=self.capabilities_id | ||
) | ||
print('capabilities_response:') | ||
print(capabilities_response) | ||
|
||
async def update_capabilities(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) | ||
|
||
phone_number_capabilities_update = { | ||
self.phonenumber_for_capabilities: update | ||
} | ||
|
||
async with self._phone_number_administration_client: | ||
capabilities_response = await self._phone_number_administration_client.update_capabilities( | ||
phone_number_capabilities_update=phone_number_capabilities_update | ||
) | ||
print('capabilities_response:') | ||
print(capabilities_response) | ||
|
||
|
||
async def main(): | ||
sample = CommunicationNumberCapabilitiesSamplesAsync() | ||
await sample.list_all_phone_numbers() | ||
await sample.get_capabilities_update() | ||
await sample.update_capabilities() | ||
|
||
|
||
if __name__ == '__main__': | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) |
54 changes: 54 additions & 0 deletions
54
...unication/azure-communication-administration/samples/phone_number_configuration_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_configuration_sample.py | ||
DESCRIPTION: | ||
These samples demonstrate phone number configuration samples. | ||
///listing phone plans via a connection string and phone number to configure | ||
USAGE: | ||
python phone_number_configuration_sample.py | ||
""" | ||
import os | ||
from azure.communication.administration import ( | ||
PhoneNumberAdministrationClient, | ||
PstnConfiguration | ||
) | ||
|
||
class CommunicationPhoneNumberConfigurationSamples(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', | ||
"phonenumber_to_configure") | ||
|
||
def get_number_configuration(self): | ||
phone_number_configuration_response = self._phone_number_administration_client.get_number_configuration( | ||
phone_number=self.phonenumber_to_configure | ||
) | ||
print('phone_number_configuration_response:') | ||
print(phone_number_configuration_response) | ||
|
||
def configure_number(self): | ||
pstn_config = PstnConfiguration( | ||
callback_url="https://callbackurl", | ||
application_id="ApplicationId", | ||
azure_pstn_target_id="AzurePstnTargetId" | ||
) | ||
self._phone_number_administration_client.configure_number( | ||
pstn_configuration=pstn_config, | ||
phone_number=self.phonenumber_to_configure | ||
) | ||
|
||
if __name__ == '__main__': | ||
sample = CommunicationPhoneNumberConfigurationSamples() | ||
sample.get_number_configuration() | ||
sample.configure_number() |
62 changes: 62 additions & 0 deletions
62
...ion/azure-communication-administration/samples/phone_number_configuration_sample_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# coding: utf-8 | ||
|
||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
""" | ||
FILE: phone_number_configuration_sample_async.py | ||
DESCRIPTION: | ||
These samples demonstrate phone number configuration samples. | ||
///listing phone plans via a connection string and phone number to configure | ||
USAGE: | ||
python phone_number_configuration_sample_async.py | ||
""" | ||
import os | ||
import asyncio | ||
from azure.communication.administration.aio import PhoneNumberAdministrationClient | ||
from azure.communication.administration import PstnConfiguration | ||
|
||
class CommunicationPhoneNumberConfigurationSamplesAsync(object): | ||
|
||
def __init__(self): | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', | ||
"phonenumber_to_configure") | ||
|
||
async def get_number_configuration(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
async with self._phone_number_administration_client: | ||
phone_number_configuration_response = await self._phone_number_administration_client.get_number_configuration( | ||
phone_number=self.phonenumber_to_configure | ||
) | ||
print('phone_number_configuration_response:') | ||
print(phone_number_configuration_response) | ||
|
||
async def configure_number(self): | ||
self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( | ||
self.connection_str) | ||
pstn_config = PstnConfiguration( | ||
callback_url="https://callbackurl", | ||
application_id="ApplicationId", | ||
azure_pstn_target_id="AzurePstnTargetId" | ||
) | ||
async with self._phone_number_administration_client: | ||
await self._phone_number_administration_client.configure_number( | ||
pstn_configuration=pstn_config, | ||
phone_number=self.phonenumber_to_configure | ||
) | ||
|
||
|
||
async def main(): | ||
sample = CommunicationPhoneNumberConfigurationSamplesAsync() | ||
await sample.get_number_configuration() | ||
await sample.configure_number() | ||
|
||
if __name__ == '__main__': | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) |
Oops, something went wrong.