class ConversationThread
ConversationThread represents a collection of posts in a group conversation, providing methods to reply to threads and access thread metadata like recipients and attachments.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/conversation_thread.py
10 - 56
moderate
Purpose
This class models a conversation thread in Microsoft Outlook/Office 365, allowing users to interact with group conversation threads by replying to them and accessing thread properties such as recipients (To/Cc), posts, and attachment status. It inherits from Entity and integrates with the Office 365 API context for executing operations.
Source Code
class ConversationThread(Entity):
"""A conversationThread is a collection of posts."""
def reply(self, post):
"""Reply to a thread in a group conversation and add a new post to it. You can specify the parent conversation
in the request, or, you can specify just the thread without the parent conversation.
:param Post post: A comment to include. Can be an empty string.
"""
payload = {"post": post}
qry = ServiceOperationQuery(self, "reply", None, payload)
self.context.add_query(qry)
return self
@property
def cc_recipients(self):
"""The Cc: recipients for the thread."""
return self.properties.get("ccRecipients", ClientValueCollection(Recipient))
@property
def has_attachments(self):
"""Indicates whether any of the posts within this thread has at least one attachment."""
return self.properties.get("hasAttachments", None)
@property
def to_recipients(self):
"""The To: recipients for the thread."""
return self.properties.get("toRecipients", ClientValueCollection(Recipient))
@property
def posts(self):
""""""
return self.properties.get(
"posts",
EntityCollection(
self.context, Post, ResourcePath("posts", self.resource_path)
),
)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"ccRecipients": self.cc_recipients,
"toRecipients": self.to_recipients,
}
default_value = property_mapping.get(name, None)
return super(ConversationThread, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: The Office 365 API context object that manages authentication and API communication. Inherited from Entity base class.
resource_path: The resource path identifying this conversation thread in the Office 365 API hierarchy. Inherited from Entity base class.
Return Value
Instantiation returns a ConversationThread object that represents a specific conversation thread. The reply() method returns self for method chaining. Properties return various types: cc_recipients and to_recipients return ClientValueCollection of Recipient objects, has_attachments returns a boolean, posts returns an EntityCollection of Post objects, and get_property() returns the requested property value or default_value.
Class Interface
Methods
reply(post: Post) -> ConversationThread
Purpose: Reply to the conversation thread by adding a new post to it
Parameters:
post: A Post object containing the reply content. Can include an empty string for the body.
Returns: Returns self (the ConversationThread instance) for method chaining
@property cc_recipients -> ClientValueCollection[Recipient]
property
Purpose: Get the Cc: recipients for the thread
Returns: ClientValueCollection of Recipient objects representing the Cc recipients
@property has_attachments -> bool
property
Purpose: Check if any post within this thread has at least one attachment
Returns: Boolean indicating whether the thread contains any attachments
@property to_recipients -> ClientValueCollection[Recipient]
property
Purpose: Get the To: recipients for the thread
Returns: ClientValueCollection of Recipient objects representing the To recipients
@property posts -> EntityCollection[Post]
property
Purpose: Get the collection of posts in this conversation thread
Returns: EntityCollection of Post objects representing all posts in the thread
get_property(name: str, default_value: Any = None) -> Any
Purpose: Get a property value by name with optional default value, providing special handling for recipient properties
Parameters:
name: The name of the property to retrievedefault_value: Optional default value to return if property is not found. If None, uses internal property mapping for ccRecipients and toRecipients.
Returns: The property value if found, otherwise the default_value or mapped property
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The Office 365 API context object for executing queries and managing authentication (inherited from Entity) | instance |
resource_path |
ResourcePath | The resource path identifying this conversation thread in the API hierarchy (inherited from Entity) | instance |
properties |
dict | Dictionary storing the thread's properties loaded from the API (inherited from Entity) | instance |
Dependencies
office365
Required Imports
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.outlook.mail.post import Post
from office365.outlook.mail.recipient import Recipient
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
from office365.graph_client import GraphClient
from office365.outlook.mail.post import Post
# Authenticate and get context
client = GraphClient.with_credentials('client_id', 'client_secret', 'tenant_id')
# Get a conversation thread
group_id = 'group-id-here'
conversation_id = 'conversation-id-here'
thread_id = 'thread-id-here'
thread = client.groups[group_id].conversations[conversation_id].threads[thread_id].get().execute_query()
# Access thread properties
to_recipients = thread.to_recipients
cc_recipients = thread.cc_recipients
has_attachments = thread.has_attachments
# Reply to the thread
new_post = Post()
new_post.body = {'contentType': 'text', 'content': 'This is my reply'}
thread.reply(new_post).execute_query()
# Access posts in the thread
posts = thread.posts
for post in posts:
print(post.body)
Best Practices
- Always ensure the context object is properly authenticated before instantiating or using ConversationThread
- Call execute_query() on the context after operations like reply() to actually execute the API request
- Use method chaining with reply() since it returns self for fluent API usage
- Access properties lazily - they are loaded from the API only when accessed
- Check has_attachments before attempting to process attachments to avoid unnecessary API calls
- The posts property returns an EntityCollection that may require additional queries to load all posts
- Handle API rate limits and errors when working with multiple threads or frequent replies
- Use get_property() method for dynamic property access with fallback values
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Conversation 90.8% similar
-
class Post 77.2% similar
-
class SocialThread 66.5% similar
-
class SocialRestThread 62.9% similar
-
class MicrofeedThreadCollection 61.3% similar