跳转到主要内容

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

先决条件

客户端初始化

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

from azure.communication.rooms import RoomsClient

client = RoomsClient.from_connection_string(conn_str='<connection_str>' )

示例

关键参数

  • valid_from:一个datetime对象,从该对象开始房间将存在
  • valid_until:一个datetime对象,在该对象之后房间会议将结束
  • participants:一个包含邀请人MRI以及可选的ParticipantRoleRoomParticipant列表。如果未指定ParticipantRole,则默认为Attendee。所有上述属性都是可选的。如果缺少valid_until和valid_from,服务将提供默认值。对于valid_from,默认值为当前日期时间;对于valid_until,默认值为valid_from + 180天
  • pstn_dial_out_enabled:如果调用时在特定房间中启用通过PSTN号码拨出,请将此标志设置为true。此标志是可选的。

创建房间

要创建房间,请从RoomsClient调用create_room函数。valid_fromvalid_untilparticipants参数都是可选的。从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_fromvalid_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 (62.6 kB 查看散列)

上传时间

构建分发

azure_communication_rooms-1.1.0-py3-none-any.whl (65.6 kB 查看散列)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面