🔍 Code Extractor

class Conversation

Maturity: 51

Represents a conversation entity containing a collection of threads, where each thread contains posts sharing the same subject. Provides access to conversation metadata and thread collections.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/conversation.py
Lines:
11 - 74
Complexity:
moderate

Purpose

The Conversation class models a conversation object from Microsoft Office 365/Outlook, providing read-only access to conversation properties such as attachments status, delivery time, preview text, topic, and unique senders. It manages a collection of ConversationThread objects and inherits from Entity to provide base entity functionality. This class is primarily used for retrieving and inspecting conversation data from Office 365 services.

Source Code

class Conversation(Entity):
    """
    A conversation is a collection of threads, and a thread contains posts to that thread.
    All threads and posts in a conversation share the same subject.
    """

    @property
    def has_attachments(self):
        # type: () -> Optional[bool]
        """
        Indicates whether any of the posts within this Conversation has at least one attachment.
        Supports $filter (eq, ne) and $search.
        """
        return self.properties.get("hasAttachments", None)

    @property
    def last_delivered_datetime(self):
        # type: () -> Optional[datetime.datetime]
        """The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time."""
        return self.properties.get("lastDeliveredDateTime", datetime.datetime.min)

    @property
    def preview(self):
        # type: () -> Optional[str]
        """
        A short summary from the body of the latest post in this conversation.
        Supports $filter (eq, ne, le, ge).
        """
        return self.properties.get("preview", None)

    @property
    def topic(self):
        # type: () -> Optional[str]
        """
        The topic of the conversation. This property can be set when the conversation is created, but it cannot be
        updated.
        """
        return self.properties.get("topic", None)

    @property
    def unique_senders(self):
        """
        All the users that sent a message to this Conversation.
        """
        return self.properties.get("uniqueSenders", StringCollection())

    @property
    def threads(self):
        # type: () -> EntityCollection[ConversationThread]
        """A collection of all the conversation threads in the conversation."""
        return self.properties.get(
            "threads",
            EntityCollection(
                self.context,
                ConversationThread,
                ResourcePath("threads", self.resource_path),
            ),
        )

    def get_property(self, name, default_value=None):
        if default_value is None:
            property_mapping = {"lastDeliveredDateTime": self.last_delivered_datetime}
            default_value = property_mapping.get(name, None)
        return super(Conversation, self).get_property(name, default_value)

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

__init__: Inherits constructor from Entity base class. The Entity constructor typically accepts a context object for API communication and optional properties dictionary for initializing the entity state.

Return Value

Instantiation returns a Conversation object that provides property-based access to conversation metadata. Properties return typed values: has_attachments (Optional[bool]), last_delivered_datetime (Optional[datetime.datetime]), preview (Optional[str]), topic (Optional[str]), unique_senders (StringCollection), and threads (EntityCollection[ConversationThread]). The get_property method returns the requested property value or a default value.

Class Interface

Methods

@property has_attachments() -> Optional[bool] property

Purpose: Indicates whether any posts within this conversation have at least one attachment

Returns: Optional[bool] - True if any post has attachments, False otherwise, or None if not set. Supports $filter (eq, ne) and $search operations.

@property last_delivered_datetime() -> Optional[datetime.datetime] property

Purpose: Gets the timestamp of when the conversation was last delivered

Returns: Optional[datetime.datetime] - ISO 8601 formatted datetime in UTC, or datetime.datetime.min if not set

@property preview() -> Optional[str] property

Purpose: Gets a short summary from the body of the latest post in the conversation

Returns: Optional[str] - Preview text of the latest post, or None if not available. Supports $filter (eq, ne, le, ge) operations.

@property topic() -> Optional[str] property

Purpose: Gets the topic/subject of the conversation

Returns: Optional[str] - The conversation topic, or None if not set. This property can be set during creation but cannot be updated afterward.

@property unique_senders() -> StringCollection property

Purpose: Gets all users who sent a message to this conversation

Returns: StringCollection - Collection of unique sender identifiers/names

@property threads() -> EntityCollection[ConversationThread] property

Purpose: Gets the collection of all conversation threads in this conversation

Returns: EntityCollection[ConversationThread] - Collection of ConversationThread objects that can be iterated

get_property(name: str, default_value=None) -> Any

Purpose: Retrieves a property value by name with optional default value, with special handling for lastDeliveredDateTime

Parameters:

  • name: The name of the property to retrieve
  • default_value: Optional default value to return if property is not found. If None, uses internal property mapping for special properties like lastDeliveredDateTime

Returns: The property value if found, otherwise the default_value or mapped default. Overrides parent Entity.get_property method.

Attributes

Name Type Description Scope
properties dict Inherited from Entity base class. Internal dictionary storing all conversation property values retrieved from the API instance
context ClientContext Inherited from Entity base class. The Office 365 API context object used for making API calls and managing authentication instance
resource_path ResourcePath Inherited from Entity base class. The API resource path for this conversation entity instance

Dependencies

  • datetime
  • typing
  • office365

Required Imports

import datetime
from typing import Optional
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.outlook.mail.conversation_thread import ConversationThread
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.types.collections import StringCollection

Usage Example

# Assuming you have an authenticated Office 365 context
from office365.entity import Entity
from office365.outlook.mail.conversation import Conversation

# Typically obtained from an API call, not directly instantiated
# conversation = context.get_conversation(conversation_id)

# Access conversation properties
if conversation.has_attachments:
    print(f"Conversation has attachments")

print(f"Topic: {conversation.topic}")
print(f"Preview: {conversation.preview}")
print(f"Last delivered: {conversation.last_delivered_datetime}")
print(f"Unique senders: {conversation.unique_senders}")

# Access threads collection
threads = conversation.threads
for thread in threads:
    # Process each thread
    pass

# Get property with default value
last_delivered = conversation.get_property('lastDeliveredDateTime', datetime.datetime.now())

Best Practices

  • Do not instantiate Conversation objects directly; obtain them through Office 365 API context methods
  • All properties are read-only and lazily loaded from the internal properties dictionary
  • The topic property can only be set during conversation creation and cannot be updated afterward
  • Use the threads property to access the EntityCollection of ConversationThread objects for iterating through conversation threads
  • The last_delivered_datetime property returns datetime.datetime.min if not set, rather than None
  • The class inherits from Entity, so ensure the context object is properly configured before accessing properties
  • Properties use lazy evaluation and may trigger API calls when accessed for the first time
  • Use get_property method when you need to provide custom default values for properties

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ConversationThread 90.8% similar

    ConversationThread represents a collection of posts in a group conversation, providing methods to reply to threads and access thread metadata like recipients and attachments.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/conversation_thread.py
  • class Post 75.9% similar

    Represents an individual Post item within a conversationThread entity in the Office 365 API, inheriting from the Entity base class.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/post.py
  • class SocialThread 59.2% similar

    SocialThread represents a social media thread object containing a root post, replies, actors, and metadata for SharePoint social features.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/thread.py
  • class MicrofeedThreadCollection 59.2% similar

    MicrofeedThreadCollection is a data model class that represents a collection of microfeed threads in the Office 365 API, inheriting from ClientValue to provide serialization capabilities.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/microfeed/thread_collection.py
  • class MessageCollection 57.6% similar

    A collection class for managing Microsoft Outlook email messages, extending DeltaCollection to provide message-specific operations like creating draft messages.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/collection.py
← Back to Browse