class CloudCommunications
CloudCommunications is a class that provides access to Microsoft Graph API cloud communications resources including calls, call records, online meetings, and user presence information.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/communications/cloud_communications.py
11 - 74
moderate
Purpose
This class serves as a wrapper for Microsoft Graph API's cloud communications endpoints, enabling management and retrieval of communication-related data such as user presence status, call records, active calls, and online meetings. It inherits from Entity and provides lazy-loaded collections for various communication resources along with methods to query presence information for multiple users.
Source Code
class CloudCommunications(Entity):
def get_presences_by_user_id(self, ids):
"""
Get the presence information for multiple users.
:param list[str] ids: The user object IDs.
"""
return_type = EntityCollection(
self.context, Presence, ResourcePath("presences", self.resource_path)
)
qry = ServiceOperationQuery(
self, "getPresencesByUserId", None, {"ids": ids}, None, return_type
)
self.context.add_query(qry)
return return_type
@property
def calls(self):
""" " """
return self.properties.get(
"calls",
CallCollection(self.context, ResourcePath("calls", self.resource_path)),
)
@property
def call_records(self):
""" " """
return self.properties.get(
"callRecords",
EntityCollection(
self.context,
CallRecord,
ResourcePath("callRecords", self.resource_path),
),
)
@property
def online_meetings(self):
""" " """
return self.properties.get(
"onlineMeetings",
OnlineMeetingCollection(
self.context, ResourcePath("onlineMeetings", self.resource_path)
),
)
@property
def presences(self):
""" " """
return self.properties.get(
"presences",
EntityCollection(
self.context, Presence, ResourcePath("presences", self.resource_path)
),
)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"callRecords": self.call_records,
"onlineMeetings": self.online_meetings,
}
default_value = property_mapping.get(name, None)
return super(CloudCommunications, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: The execution context object that manages API requests and responses, inherited from Entity base class
resource_path: The API resource path for this CloudCommunications entity, inherited from Entity base class
Return Value
Instantiation returns a CloudCommunications object that provides access to communication resources. The get_presences_by_user_id method returns an EntityCollection of Presence objects. Properties return specialized collections (CallCollection, EntityCollection, OnlineMeetingCollection) that can be used to query and manipulate the respective resources.
Class Interface
Methods
get_presences_by_user_id(self, ids: list[str]) -> EntityCollection
Purpose: Retrieves presence information for multiple users in a single API call
Parameters:
ids: List of user object IDs (GUIDs) for which to retrieve presence information
Returns: EntityCollection containing Presence objects for the requested users
@property calls(self) -> CallCollection
property
Purpose: Provides access to the collection of active calls
Returns: CallCollection object representing the calls resource endpoint
@property call_records(self) -> EntityCollection
property
Purpose: Provides access to the collection of call records (historical call data)
Returns: EntityCollection of CallRecord objects representing historical call information
@property online_meetings(self) -> OnlineMeetingCollection
property
Purpose: Provides access to the collection of online meetings
Returns: OnlineMeetingCollection object for managing online meetings
@property presences(self) -> EntityCollection
property
Purpose: Provides access to the collection of user presence information
Returns: EntityCollection of Presence objects representing user presence states
get_property(self, name: str, default_value=None) -> Any
Purpose: Retrieves a property value by name with custom mapping for communication-specific properties
Parameters:
name: The name of the property to retrievedefault_value: Default value to return if property is not found (optional)
Returns: The property value, or the mapped collection object for known properties, or default_value if not found
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The execution context for API operations, inherited from Entity | instance |
resource_path |
ResourcePath | The API resource path for this entity, inherited from Entity | instance |
properties |
dict | Dictionary storing cached property values and collections, inherited from Entity | instance |
Dependencies
office365
Required Imports
from office365.communications.callrecords.call_record import CallRecord
from office365.communications.calls.collection import CallCollection
from office365.communications.onlinemeetings.collection import OnlineMeetingCollection
from office365.communications.presences.presence import Presence
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
Usage Example
# Assuming you have a configured context object
from office365.graph_client import GraphClient
# Initialize Graph client with credentials
client = GraphClient.with_token(lambda: 'your_access_token')
# Access cloud communications
cloud_comms = client.communications
# Get presence information for multiple users
user_ids = ['user1-id', 'user2-id', 'user3-id']
presences = cloud_comms.get_presences_by_user_id(user_ids)
client.execute_query()
# Access the presence data
for presence in presences:
print(f"User: {presence.id}, Status: {presence.availability}")
# Access online meetings
meetings = cloud_comms.online_meetings
client.load(meetings)
client.execute_query()
# Access call records
call_records = cloud_comms.call_records
client.load(call_records)
client.execute_query()
# Access active calls
calls = cloud_comms.calls
client.load(calls)
client.execute_query()
Best Practices
- Always call context.execute_query() after querying collections or calling methods to actually execute the API request
- Use lazy-loaded properties (calls, call_records, online_meetings, presences) efficiently - they are only instantiated when first accessed
- Ensure proper authentication and permissions are configured before accessing communication resources
- When using get_presences_by_user_id, provide valid user object IDs (GUIDs) in the ids list
- The class uses a property caching mechanism - once a property is accessed, it's stored in self.properties dictionary
- Collections returned are EntityCollection or specialized collection types that support further querying and filtering
- Method calls are queued via context.add_query() and executed in batch when execute_query() is called
- This class is typically accessed through a GraphClient instance rather than instantiated directly
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Call 66.2% similar
-
class CallCollection 64.3% similar
-
class CallRecord 61.8% similar
-
class Participant 60.3% similar
-
class Session 59.7% similar