class Call
Represents a call resource in Microsoft Graph Communications API, managing both incoming and outgoing calls for applications with capabilities for call control, media operations, and participant management.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/communications/calls/call.py
21 - 149
complex
Purpose
The Call class provides a comprehensive interface for managing voice/video calls in Microsoft Teams/Skype for Business applications. It handles call lifecycle operations (reject, delete/hangup), media processing (cancel operations), recording status updates, muting controls, and provides access to call participants and operations. This class is used by bots and applications to programmatically control calls, manage IVR operations, and interact with call participants.
Source Code
class Call(Entity):
"""
The call resource is created when there is an incoming call for the application or the application creates a
new outgoing call via a POST on app/calls.
"""
def cancel_media_processing(self, client_context=None):
"""
Cancels processing for any in-progress media operations.
Media operations refer to the IVR operations playPrompt and recordResponse, which are by default queued
to process in order. The cancelMediaProcessing method cancels any operation that is in-process as well as
operations that are queued. For example, this method can be used to clean up the IVR operation queue for
a new media operation. However, it will not cancel a subscribeToTone operation because it operates independent
of any operation queue.
:param str client_context: The client context.
"""
return_type = CancelMediaProcessingOperation(self.context)
payload = {
"clientContext": client_context,
}
qry = ServiceOperationQuery(
self, "cancelMediaProcessing", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def reject(self, reason=None, callback_uri=None):
"""
Enable a bot to reject an incoming call. The incoming call request can be an invite from a participant in
a group call or a peer-to-peer call. If an invite to a group call is received, the notification will contain
the chatInfo and meetingInfo parameters.
The bot is expected to answer or reject the call before the call times out. The current timeout value is
15 seconds.
This API does not end existing calls that have already been answered. Use delete call to end a call.
:param str reason: The rejection reason. Possible values are None, Busy and Forbidden
:param str callback_uri: This allows bots to provide a specific callback URI for the current call to receive
later notifications. If this property has not been set, the bot's global callback URI will be used instead.
This must be https.
"""
payload = {"reason": reason, "callbackUri": callback_uri}
qry = ServiceOperationQuery(self, "reject", None, payload)
self.context.add_query(qry)
return self
def delete(self):
"""
Delete or hang up an active call. For group calls, this will only delete your call leg and the underlying
group call will still continue."""
return super(Call, self).delete_object()
def update_recording_status(self, status, client_context):
"""
Update the application's recording status associated with a call.
This requires the use of the Teams policy-based recording solution.
:param str status: The recording status. Possible values are: notRecording, recording, or failed.
:param str client_context: Unique client context string. Max limit is 256 chars.
"""
return_type = UpdateRecordingStatusOperation(self.context)
payload = {"status": status, "clientContext": client_context}
qry = ServiceOperationQuery(
self, "updateRecordingStatus", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def unmute(self, client_context):
"""
Allow the application to unmute itself.
This is a server unmute, meaning that the server will start sending audio packets for this participant
to other participants again.
:param str client_context: Unique Client Context string. Max limit is 256 chars.
"""
return_type = UnmuteParticipantOperation(self.context)
payload = {"clientContext": client_context}
qry = ServiceOperationQuery(self, "unmute", None, payload, None, return_type)
self.context.add_query(qry)
return return_type
@property
def callback_uri(self):
"""The callback URL on which callbacks will be delivered. Must be https."""
return self.properties.get("callbackUri", None)
@property
def call_routes(self):
"""The routing information on how the call was retargeted. Read-only."""
return self.properties.get("callRoutes", ClientValueCollection(CallRoute))
@property
def incoming_context(self):
"""Call context associated with an incoming call."""
return self.properties.get("incomingContext", IncomingContext())
@property
def participants(self):
"""
Participant collection
"""
return self.properties.get(
"participants",
EntityCollection(
self.context,
Participant,
ResourcePath("participants", self.resource_path),
),
)
@property
def operations(self):
"""
CommsOperation collection
"""
return self.properties.get(
"operations",
EntityCollection(
self.context,
CommsOperation,
ResourcePath("operations", self.resource_path),
),
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: Inherited from Entity base class - the client context object that manages API communication and query execution for this call resource
properties: Inherited from Entity base class - dictionary containing the call's properties and state data returned from the API
Return Value
Instantiation returns a Call object representing a specific call resource. Methods return various types: cancel_media_processing returns CancelMediaProcessingOperation, reject returns self (Call) for chaining, delete returns result from parent delete_object, update_recording_status returns UpdateRecordingStatusOperation, unmute returns UnmuteParticipantOperation. Properties return specific types like string (callback_uri), ClientValueCollection (call_routes), IncomingContext (incoming_context), or EntityCollection (participants, operations).
Class Interface
Methods
cancel_media_processing(client_context: str = None) -> CancelMediaProcessingOperation
Purpose: Cancels any in-progress or queued IVR media operations (playPrompt, recordResponse) for this call
Parameters:
client_context: Optional unique client context string for tracking this operation (max 256 characters)
Returns: CancelMediaProcessingOperation object representing the cancellation operation
reject(reason: str = None, callback_uri: str = None) -> Call
Purpose: Rejects an incoming call before it is answered, must be called within 15 seconds of receiving the call
Parameters:
reason: Optional rejection reason - possible values: None, 'Busy', 'Forbidden'callback_uri: Optional HTTPS callback URI for receiving notifications about this call, overrides global callback URI
Returns: Self (Call object) for method chaining
delete() -> Any
Purpose: Deletes or hangs up an active call; for group calls only removes the application's call leg
Returns: Result from parent Entity.delete_object() method
update_recording_status(status: str, client_context: str) -> UpdateRecordingStatusOperation
Purpose: Updates the application's recording status for this call, requires Teams policy-based recording solution
Parameters:
status: Recording status - possible values: 'notRecording', 'recording', or 'failed'client_context: Required unique client context string for tracking (max 256 characters)
Returns: UpdateRecordingStatusOperation object representing the status update operation
unmute(client_context: str) -> UnmuteParticipantOperation
Purpose: Unmutes the application on the call, allowing audio packets to be sent to other participants
Parameters:
client_context: Required unique client context string for tracking (max 256 characters)
Returns: UnmuteParticipantOperation object representing the unmute operation
@property callback_uri -> str
property
Purpose: Gets the HTTPS callback URL where call notifications will be delivered
Returns: String containing the callback URI or None if not set
@property call_routes -> ClientValueCollection
property
Purpose: Gets the routing information showing how the call was retargeted (read-only)
Returns: ClientValueCollection of CallRoute objects containing routing information
@property incoming_context -> IncomingContext
property
Purpose: Gets the call context associated with an incoming call
Returns: IncomingContext object containing context information for incoming calls
@property participants -> EntityCollection
property
Purpose: Gets the collection of participants in this call
Returns: EntityCollection of Participant objects representing all call participants
@property operations -> EntityCollection
property
Purpose: Gets the collection of communications operations associated with this call
Returns: EntityCollection of CommsOperation objects representing call operations
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | Inherited from Entity - the client context managing API communication and query execution | instance |
properties |
dict | Inherited from Entity - dictionary storing the call's properties and state data from the API | instance |
resource_path |
ResourcePath | Inherited from Entity - the resource path identifying this call in the API hierarchy | instance |
Dependencies
office365
Required Imports
from office365.communications.calls.call import Call
from office365.communications.calls.incoming_context import IncomingContext
from office365.communications.calls.participant import Participant
from office365.communications.calls.route import CallRoute
from office365.communications.operations.cancel_media_processing import CancelMediaProcessingOperation
from office365.communications.operations.comms import CommsOperation
from office365.communications.operations.unmute_participant import UnmuteParticipantOperation
from office365.communications.operations.update_recording_status import UpdateRecordingStatusOperation
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
Usage Example
# Assuming you have a GraphClient instance and a call_id
from office365.graph_client import GraphClient
# Initialize client with credentials
client = GraphClient.with_client_secret(tenant_id, client_id, client_secret)
# Get an existing call
call = client.communications.calls[call_id].get().execute_query()
# Reject an incoming call
call.reject(reason='Busy', callback_uri='https://myapp.com/callback')
client.execute_query()
# Cancel any in-progress media operations
cancel_op = call.cancel_media_processing(client_context='operation-123')
client.execute_query()
# Update recording status
recording_op = call.update_recording_status(status='recording', client_context='rec-456')
client.execute_query()
# Unmute the application
unmute_op = call.unmute(client_context='unmute-789')
client.execute_query()
# Access participants
participants = call.participants.get().execute_query()
for participant in participants:
print(participant.info.identity.user.display_name)
# Delete/hang up the call
call.delete()
client.execute_query()
Best Practices
- Always call execute_query() on the context after queuing operations to actually execute them against the API
- For incoming calls, respond with answer or reject within 15 seconds to avoid timeout
- Use client_context parameters (max 256 chars) to track operations and correlate with callbacks
- Callback URIs must use HTTPS protocol for security
- The delete() method only removes your application's call leg in group calls; the group call continues for other participants
- cancelMediaProcessing affects playPrompt and recordResponse operations but not subscribeToTone operations
- Recording operations require Teams policy-based recording solution to be properly configured
- Access nested collections (participants, operations) through properties which return EntityCollection objects
- Chain operations by queuing multiple queries before calling execute_query() for better performance
- Handle the returned operation objects (CancelMediaProcessingOperation, UpdateRecordingStatusOperation, etc.) to track operation status
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class CallCollection 77.0% similar
-
class CallRecord 70.1% similar
-
class CloudCommunications 66.2% similar
-
class Participant 63.2% similar
-
class CallOptions 57.8% similar