Microsoft Azure Communication Administration Service客户端库(Python版)
项目描述
Azure Communication Administration Package客户端库(Python版)
此包已弃用。请使用azure-communication-identity和azure-communication-phonenumbers。
新库实现了请求的功能。有关更多详细信息,请参阅变更日志。
入门
先决条件
- 使用此包需要Python 2.7或3.5或更高版本。
- 您必须拥有Azure订阅
安装包
使用pip安装Azure Communication Administration客户端库(Python版)
pip install azure-communication-administration
关键概念
CommunicationIdentityClient
CommunicationIdentityClient
提供以下操作:
-
创建/删除用于Azure Communication Services的标识。这些标识可用于使用Azure Communication服务,并通过令牌作用域限制其能力。
-
创建/撤销具有特定范围的用户访问令牌,以访问聊天、通话和短信等服务。令牌针对有效的Azure通信身份发行,并且可以随时撤销。
CommunicationPhoneNumberClient
初始化电话号码客户端
# You can find your endpoint and access token from your resource in the Azure Portal
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)
电话计划概述
电话计划分为两种类型:地理型和免长途费型。地理型电话计划是与地理位置关联的电话计划,其电话号码的区号与地理位置的区号相关联。免长途费型电话计划与地理位置不关联。例如,在美国,免长途费号码可以带有800或888等区号。
同一国家的所有地理型电话计划将组合成一个具有地理型电话号码类型的电话计划组。同一国家的所有免长途费型电话计划将组合成一个电话计划组。
搜索和获取号码
可以通过搜索创建API通过提供电话计划ID、区号和电话号码数量来搜索电话号码。提供的电话号码数量将保留十分钟。此电话号码搜索可以是取消或购买。如果搜索被取消,则电话号码将可供其他人使用。如果搜索被购买,则电话号码将用于Azure资源。
配置/分配号码
可以通过配置号码API将电话号码分配给回调URL。作为配置的一部分,您需要已获取的电话号码、回调URL和应用程序ID。
示例
以下部分提供了几个代码片段,涵盖了一些最常见的Azure通信服务任务,包括
通信电话号码
获取国家
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
supported_countries = phone_number_administration_client.list_all_supported_countries()
for supported_country in supported_countries:
print(supported_country)
获取电话计划组
电话计划组有两种类型,地理型和免长途费型。
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups(
country_code='<country code>'
)
for phone_plan_group in phone_plan_groups_response:
print(phone_plan_group)
获取电话计划
与免长途费型电话计划不同,地理型电话计划的区号是空的。区号可以在区号API中找到。
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
phone_plans_response = phone_number_administration_client.list_phone_plans(
country_code='<country code>',
phone_plan_group_id='<phone plan group id>'
)
for phone_plan in phone_plans_response:
print(phone_plan)
获取位置选项
对于地理型电话计划,您可以查询可用的地理位置。位置选项的结构类似于国家的地理层次结构。例如,美国有州,每个州内都有城市。
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
location_options_response = phone_number_administration_client.get_phone_plan_location_options(
country_code='<country code>',
phone_plan_group_id='<phone plan group id>',
phone_plan_id='<phone plan id>'
)
print(location_options_response)
获取区号
获取地理型电话计划的区号需要设置位置选项查询。您必须包含GetLocationOptions API返回的位置选项对象中遍历的地理位置链。
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
all_area_codes = phone_number_administration_client.get_all_area_codes(
location_type="NotRequired",
country_code='<country code>',
phone_plan_id='<phone plan id>'
)
print(all_area_codes)
创建搜索
from azure.communication.administration import CreateSearchOptions
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
searchOptions = CreateSearchOptions(
area_code='<area code>',
description="testsearch20200014",
display_name="testsearch20200014",
phone_plan_ids=['<phone plan id>'],
quantity=1
)
search_response = phone_number_administration_client.create_search(
body=searchOptions
)
print(search_response)
通过ID获取搜索
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
phone_number_search_response = phone_number_administration_client.get_search_by_id(
search_id='<search id>'
)
print(phone_number_search_response)
购买搜索
phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str)
phone_number_administration_client.purchase_search(
search_id='<search id to purchase>'
)
故障排除
Azure通信服务身份客户端将引发在Azure Core中定义的异常。
下一步操作
更多示例代码
请查看示例目录,以获取如何使用此库管理身份和令牌的详细示例。
提供反馈
如果您遇到任何错误或有建议,请在此项目的问题部分提交问题。
贡献
此项目欢迎贡献和建议。大多数贡献需要您同意贡献者许可协议(CLA),声明您有权并且确实授予我们使用您的贡献的权利。有关详细信息,请访问https://cla.microsoft.com。
当您提交拉取请求时,CLA机器人会自动判断您是否需要提供CLA并相应地装饰PR(例如,标签、注释)。只需按照机器人提供的说明操作。您只需在整个使用我们CLA的仓库中执行此操作一次。
本项目已采用微软开源行为准则。更多信息请参阅行为准则FAQ或联系opencode@microsoft.com提出任何额外问题或评论。
项目详情
azure-communication-administration-1.0.0b4.zip的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a9190d2aa70c34147f7a978ceac1b41d5bcae7a79e84918b90da1a37981c7068 |
|
MD5 | 19aa7cb66ea7e78b06ec487888fdbff1 |
|
BLAKE2b-256 | 7bdc5fe62594f83f5ec72d36147eaa5f3982cd94ac7c44df9e885176665a457a |
azure_communication_administration-1.0.0b4-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 58f10b5782e4d023dd66f20f6814a1eae24d95160526de346ba76d25b267c574 |
|
MD5 | 2e2136f5393a7ba5d725bc7877464139 |
|
BLAKE2b-256 | 2ff469f05e3b803db928e4ae3dab3fa1d6c0b74d825ed6003f0716575b5bdfa4 |