Microsoft Communication Rooms Python客户端库
项目描述
Azure Communication Rooms Python客户端库
此包包含用于Azure Communication Services for Rooms的Python SDK。有关Azure Communication Services的更多信息,请参阅此处
免责声明
Azure SDK Python包对Python 2.7的支持已于2022年1月1日结束。有关更多信息及问题,请参阅https://github.com/Azure/azure-sdk-for-python/issues/20691
关键概念
Azure Communication Rooms包用于以下操作
- 创建计划会议
- 创建具有管理权限的参与者会议
入门
安装包
python -m pip install azure-communication-rooms
先决条件
- 使用此包需要Python 3.7或更高版本。
- 使用此软件包需要Azure订阅。
- 已部署的通信服务资源。您可以使用Azure门户或Azure PowerShell来设置它。
客户端初始化
要初始化会议室客户端,可以使用连接字符串进行实例化。
from azure.communication.rooms import RoomsClient
client = RoomsClient.from_connection_string(conn_str='<connection_str>' )
示例
关键参数
valid_from
:一个datetime对象,从该对象开始房间将存在valid_until
:一个datetime对象,在该对象之后房间会议将结束participants
:一个包含邀请人MRI以及可选的ParticipantRole
的RoomParticipant
列表。如果未指定ParticipantRole
,则默认为Attendee
。所有上述属性都是可选的。如果缺少valid_until和valid_from,服务将提供默认值。对于valid_from
,默认值为当前日期时间;对于valid_until
,默认值为valid_from + 180天
。pstn_dial_out_enabled
:如果调用时在特定房间中启用通过PSTN号码拨出,请将此标志设置为true。此标志是可选的。
创建房间
要创建房间,请从RoomsClient
调用create_room
函数。valid_from
、valid_until
和participants
参数都是可选的。从1.1.0版本开始,ACS房间支持PSTN拨出功能。要创建具有PSTN拨出属性的房间,请调用create_room
函数并将pstn_dial_out_enabled
设置为true或false。如果未提供pstn_dial_out_enabled
,则pstn_dial_out_enabled
的默认值为false。
from azure.core.exceptions import HttpResponseError
from datetime import datetime, timedelta
from azure.communication.rooms import (
RoomsClient,
RoomParticipant,
ParticipantRole
)
from azure.communication.identity import CommunicationUserIdentifier
from dateutil.relativedelta import relativedelta
client = RoomsClient.from_connection_string(conn_str='<connection_str>')
valid_from = datetime.now()
valid_until = valid_from + relativedelta(months=+1)
participants = []
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 1>")))
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 2>"), role=ParticipantRole.CONSUMER))
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 3>"), role=ParticipantRole.PRESENTER))
try:
create_room_response = client.create_room(
valid_from=valid_from,
valid_until=valid_until,
participants=participants,
pstn_dial_out_enabled=false
)
except HttpResponseError as ex:
print(ex)
更新房间
可以通过从RoomsClient
调用update_room
函数来更新已创建的房间的valid_from
和valid_until
属性。从1.1.0版本开始,ACS房间支持PSTN拨出功能。要更新具有PSTN拨出属性的房间,请调用update_room
并将pstn_dial_out_enabled
设置为true或false。如果未提供pstn_dial_out_enabled
,则房间中的PstnDialOutEnabled属性不会发生变化。
try:
update_room_response = client.update_room(
room_id="id of the room to be updated",
valid_from=datetime.now(),
valid_until=valid_from + timedelta(weeks=4),
pstn_dial_out_enabled=false
)
except HttpResponseError as e:
print('service responds error: {}'.format(e))
获取房间
可以通过从RoomsClient
调用get_room
函数并传入关联的room_id
来检索已创建的房间。
try:
get_room_response = client.get_room(room_id="id of the room to get")
except HttpResponseError as ex:
print(ex)
列出房间
通过从RoomsClient
调用list_rooms
函数可以检索使用ACS资源创建的所有有效房间。
try:
list_room_response = client.list_rooms()
except HttpResponseError as ex:
print(ex)
删除房间
要删除房间,请从RoomsClient调用delete_room
函数。
try:
client.delete_room(
room_id="id of the room to be deleted")
except HttpResponseError as e:
print('service responds error: {}'.format(e))
在房间中添加或更新参与者
要插入新参与者或更新现有参与者,请从RoomsClient调用add_or_update_participants
函数。
participants = []
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 1>")))
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 2>"), role=ParticipantRole.ATTENDEE))
participants.append(RoomParticipant(communication_identifier=CommunicationUserIdentifier("<ACS User MRI identity 3>"), role=ParticipantRole.CONSUMER))
try:
response = client.add_or_update_participants(
room_id="id of the room to be updated",
participants=participants
)
except HttpResponseError as e:
print('service responds error: {}'.format(e))
移除参与者
通过从RoomsClient调用remove_participants
函数来从房间中移除参与者。
communication_identifiers = [CommunicationUserIdentifier("<ACS User MRI identity 2>")]
try:
remove_participants_response = client.remove_participants(
room_id="id of the room to remove participants",
participants=communication_identifiers
)
except HttpResponseError as ex:
print(ex)
列出参与者
通过引用room_id
检索现有房间的参与者列表。
try:
participants = client.list_participants(room_id="id of the room to list participants")
except HttpResponseError as ex:
print(ex)
故障排除
如果对服务器的请求失败,房间操作将抛出异常。房间客户端将引发定义在Azure Core中的异常。
下一步
更多示例代码
请查看samples目录,以获取如何使用此库创建和管理房间的详细示例。
提供反馈
如果您遇到任何错误或有所建议,请在项目的问题部分提交问题。
贡献
本项目欢迎贡献和建议。大多数贡献都需要您同意贡献者许可协议(CLA),声明您有权并且实际上已授予我们使用您的贡献的权利。有关详细信息,请访问https://cla.microsoft.com。
当您提交拉取请求时,CLA机器人将自动确定您是否需要提供CLA,并适当装饰PR(例如,标签,注释)。只需遵循机器人提供的说明。您只需在整个使用我们的CLA的仓库中进行一次操作。
本项目采用了微软开源行为准则。有关更多信息,请参阅行为准则FAQ或通过opencode@microsoft.com联系,以提出任何额外的问题或评论。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分发
构建分发
azure-communication-rooms-1.1.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 851616f35a54ea11909f84012db8f95dcd5f2efbcc875ca6830601dace1c231d |
|
MD5 | 7ff0122c1422da64002470b5e50bab28 |
|
BLAKE2b-256 | f1d5687680b4a9cb741656f4a43f779d2c31a13b8b213cf764bd8c7b5d451f00 |
azure_communication_rooms-1.1.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 6646e529c667b14699619488dc3ba7807b63097499f3899139538842f0bbc9b7 |
|
MD5 | ea54a5789105203f7c51cd6d7bd2d5a0 |
|
BLAKE2b-256 | 3967b9e82328410c622aef6737341975988a205750a2efc187cec70c3f6c0ae1 |