你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 Python 的 Azure 通信室客户端库 - 版本 1.0.0

此包包含用于会议室Azure 通信服务的 Python SDK。 在此处阅读有关Azure 通信服务的详细信息

免责声明

对 Python 2.7 的 Azure SDK Python 包支持已于 2022 年 1 月 1 日结束。 有关详细信息和问题,请参阅 https://github.com/Azure/azure-sdk-for-python/issues/20691

关键概念

Azure 通信室包用于执行以下操作:

  • 创建计划会议
  • 为其参与者创建具有托管权限的会议

入门

安装包

python -m pip install azure-communication-rooms

先决条件

客户端初始化

若要初始化会议室客户端,可以使用连接字符串进行实例化。

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_untilvalid_from + 180 days

创建房间

若要创建聊天室,请从 RoomsClient调用 create_room 函数。 valid_fromvalid_untilparticipants 参数都是可选的。

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

client = RoomsClient.from_connection_string(conn_str='<connection_str>')
valid_from = datetime.now()
valid_until = valid_from + relativedelta(months=+1)
participants = []
participants.append(RoomParticipant(CommunicationUserIdentifier("<ACS User MRI identity 1>")))
participants.append(RoomParticipant(CommunicationUserIdentifier("<ACS User MRI identity 2>"), ParticipantRole.CONSUMER))
participants.append(RoomParticipant(CommunicationUserIdentifier("<ACS User MRI identity 3>"), ParticipantRole.PRESENTER))

try:
    create_room_response = client.create_room(
        valid_from=valid_from,
        valid_until=valid_until,
        participants=participants
    )
except HttpResponseError as ex:
    print(ex)

更新会议室

valid_from可以通过从 RoomsClient调用 update_room 函数来更新所创建房间的 和 valid_until 属性。

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)
    )
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)

删除房间

若要删除会议室,请 delete_room 从 RoomsClient 调用 函数。

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(CommunicationUserIdentifier("<ACS User MRI identity 1>")))
participants.append(RoomParticipant(CommunicationUserIdentifier("<ACS User MRI identity 2>"), ParticipantRole.ATTENDEE))
participants.append(RoomParticipant(CommunicationUserIdentifier("<ACS User MRI identity 3>"), 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=room_id,
        participants=communication_identifiers
    )
except HttpResponseError as ex:
    print(ex)

列出参与者

通过引用 检索现有聊天室的 room_id参与者列表:

try:
    participants = self.rooms_client.list_participants(room_id)
except HttpResponseError as ex:
    print(ex)

疑难解答

如果对服务器的请求失败,会议室操作将引发异常。 会议室客户端将引发 Azure Core 中定义的异常。

后续步骤

更多示例代码

请查看 示例 目录,获取有关如何使用此库创建和管理会议室的详细示例。

提供反馈

如果遇到任何 bug 或有建议,请在项目的“ 问题 ”部分中提出问题

贡献

本项目欢迎贡献和建议。 大多数贡献要求你同意贡献者许可协议 (CLA),并声明你有权(并且确实有权)授予我们使用你的贡献的权利。 有关详细信息,请访问 https://cla.microsoft.com

提交拉取请求时,CLA 机器人将自动确定你是否需要提供 CLA,并相应地修饰 PR(例如标签、注释)。 直接按机器人提供的说明操作。 只需使用 CLA 对所有存储库执行一次这样的操作。

本项目采用 Microsoft 开源行为准则。 有关详细信息,请参阅“行为准则常见问题解答”,如有其他任何问题或意见,请联系 opencode@microsoft.com。