Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Communication Service - Phone Number Administration - Samples #14162

Merged
merged 6 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
USAGE:
phone_number_area_codes_sample.py
ytyeason marked this conversation as resolved.
Show resolved Hide resolved
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from
3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES - The phone plan id you want to get area codes from
"""

import os
from azure.communication.administration import (
PhoneNumberAdministrationClient
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US")
phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id")


def get_all_area_codes():
# [START get_all_area_codes]
all_area_codes = phone_number_administration_client.get_all_area_codes(
location_type="NotRequired",
country_code=country_code,
phone_plan_id=phone_plan_id_area_codes
)
# [END get_all_area_codes]
print('all_area_codes:')
print(all_area_codes)


if __name__ == '__main__':
get_all_area_codes()
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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_async.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
USAGE:
phone_number_area_codes_sample_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from
3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES - The phone plan id you want to get area codes from
"""

import os
import asyncio
from azure.communication.administration.aio import PhoneNumberAdministrationClient

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US")
phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id")


async def get_all_area_codes():
# [START get_all_area_codes]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(
connection_str)
async with phone_number_administration_client:
all_area_codes = await phone_number_administration_client.get_all_area_codes(
location_type="NotRequired",
country_code=country_code,
phone_plan_id=phone_plan_id_area_codes
)
# [END get_all_area_codes]
print('all_area_codes:')
print(all_area_codes)


async def main():
await get_all_area_codes()

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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:
This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities.
USAGE:
phone_number_capabilities_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get
3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES - The phone number you want to update capabilities to
"""

import os
from azure.communication.administration import (
PhoneNumberAdministrationClient,
NumberUpdateCapabilities
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID', "capabilities-id")
phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES', "+17771234567")


def list_all_phone_numbers():
# [START list_all_phone_numbers]
list_all_phone_numbers_response = phone_number_administration_client.list_all_phone_numbers()
# [END 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():
# [START get_capabilities_update]
capabilities_response = phone_number_administration_client.get_capabilities_update(
capabilities_update_id=capabilities_id
)
# [END get_capabilities_update]
print('capabilities_response:')
print(capabilities_response)


def update_capabilities():
# [START update_capabilities]
update = NumberUpdateCapabilities(add=iter(["InboundCalling"]))

phone_number_capabilities_update = {
phonenumber_for_capabilities: update
}

capabilities_response = phone_number_administration_client.update_capabilities(
phone_number_capabilities_update=phone_number_capabilities_update
)
# [END update_capabilities]
print('capabilities_response:')
print(capabilities_response)


if __name__ == '__main__':
list_all_phone_numbers()
get_capabilities_update()
update_capabilities()
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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_async.py
DESCRIPTION:
This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities.
USAGE:
phone_number_capabilities_sample_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get
3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES - The phone number you want to update capabilities to
"""

import asyncio
import os
from azure.communication.administration.aio import PhoneNumberAdministrationClient
from azure.communication.administration import NumberUpdateCapabilities


connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID', "capabilities-id")
phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES',
"phone-number-for-capabilities")


async def list_all_phone_numbers():
# [START list_all_phone_numbers]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
async with phone_number_administration_client:
list_all_phone_numbers_response = 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)
# [END list_all_phone_numbers]


async def get_capabilities_update():
# [START get_capabilities_update]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
async with phone_number_administration_client:
capabilities_response = await phone_number_administration_client.get_capabilities_update(
capabilities_update_id=capabilities_id
)
print('capabilities_response:')
print(capabilities_response)
# [END get_capabilities_update]


async def update_capabilities():
# [START update_capabilities]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
update = NumberUpdateCapabilities(add=iter(["InboundCalling"]))

phone_number_capabilities_update = {
phonenumber_for_capabilities: update
}

async with phone_number_administration_client:
capabilities_response = await phone_number_administration_client.update_capabilities(
phone_number_capabilities_update=phone_number_capabilities_update
)
print('capabilities_response:')
print(capabilities_response)
# [END update_capabilities]


async def main():
await list_all_phone_numbers()
await get_capabilities_update()
await update_capabilities()


if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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:
This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure
USAGE:
phone_number_configuration_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure
"""


import os
from azure.communication.administration import (
PhoneNumberAdministrationClient,
PstnConfiguration
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE',
"phonenumber_to_configure")


def get_number_configuration():
# [START get_number_configuration]
phone_number_configuration_response = phone_number_administration_client.get_number_configuration(
phone_number=phonenumber_to_configure
)
# [END get_number_configuration]
print('phone_number_configuration_response:')
print(phone_number_configuration_response)


def configure_number():
# [START configure_number]
pstn_config = PstnConfiguration(
callback_url="https://callbackurl",
application_id="ApplicationId",
azure_pstn_target_id="AzurePstnTargetId"
)
phone_number_administration_client.configure_number(
pstn_configuration=pstn_config,
phone_number=phonenumber_to_configure
)
# [END configure_number]


if __name__ == '__main__':
get_number_configuration()
configure_number()
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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:
This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure
USAGE:
phone_number_configuration_sample_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure
"""

import os
import asyncio
from azure.communication.administration.aio import PhoneNumberAdministrationClient
from azure.communication.administration import PstnConfiguration

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE',
"phonenumber_to_configure")


async def get_number_configuration():
# [START get_number_configuration]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
async with phone_number_administration_client:
phone_number_configuration_response = await phone_number_administration_client.get_number_configuration(
phone_number=phonenumber_to_configure
)
print('phone_number_configuration_response:')
print(phone_number_configuration_response)
# [END get_number_configuration]


async def configure_number():
# [START configure_number]
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
pstn_config = PstnConfiguration(
callback_url="https://callbackurl",
application_id="ApplicationId",
azure_pstn_target_id="AzurePstnTargetId"
)
async with phone_number_administration_client:
await phone_number_administration_client.configure_number(
pstn_configuration=pstn_config,
phone_number=phonenumber_to_configure
)
# [END configure_number]


async def main():
await get_number_configuration()
await configure_number()

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Loading