diff --git a/instagrapi/mixins/direct.py b/instagrapi/mixins/direct.py index eb680567..75f41435 100644 --- a/instagrapi/mixins/direct.py +++ b/instagrapi/mixins/direct.py @@ -22,14 +22,17 @@ from instagrapi.utils import dumps SELECTED_FILTERS = ("flagged", "unread") +BOXES = ("general", "primary") try: from typing import Literal SELECTED_FILTER = Literal[SELECTED_FILTERS] + BOX = Literal[BOXES] except ImportError: # python <= 3.8 SELECTED_FILTER = str + BOX = str class DirectMixin: @@ -41,6 +44,7 @@ def direct_threads( self, amount: int = 20, selected_filter: SELECTED_FILTER = "", + box: BOX = "", thread_message_limit: Optional[int] = None, ) -> List[DirectThread]: """ @@ -52,6 +56,8 @@ def direct_threads( Maximum number of media to return, default is 20 selected_filter: str, optional Filter to apply to threads (flagged or unread) + box: str, optional + Box to gather threads from (primary or general) (business accounts only) thread_message_limit: int, optional Thread message limit, deafult is 10 @@ -65,7 +71,7 @@ def direct_threads( threads = [] # self.private_request("direct_v2/get_presence/") while True: - threads_chunk, cursor = self.direct_threads_chunk(selected_filter, thread_message_limit, cursor) + threads_chunk, cursor = self.direct_threads_chunk(selected_filter, box, thread_message_limit, cursor) for thread in threads_chunk: threads.append(thread) @@ -78,6 +84,7 @@ def direct_threads( def direct_threads_chunk( self, selected_filter: SELECTED_FILTER = "", + box: BOX = "", thread_message_limit: Optional[int] = None, cursor: str = None ) -> Tuple[List[DirectThread], str]: @@ -90,6 +97,8 @@ def direct_threads_chunk( Filter to apply to threads (flagged or unread) thread_message_limit: int, optional Thread message limit, deafult is 10 + box: str, optional + Box to gather threads from (primary or general) (business accounts only) cursor: str, optional Cursor from the previous chunk request @@ -116,6 +125,15 @@ def direct_threads_chunk( "selected_filter": selected_filter } ) + if box: + assert ( + box in BOXES + ), f'Unsupported box="{box}" {BOXES}' + params.update( + { + "folder" : '1' if box == "general" else '0' + } + ) if thread_message_limit: params.update({"thread_message_limit": thread_message_limit}) if cursor: