From b94fbb8cdfee1e7d516cd8a893eb3fde06e7fdad Mon Sep 17 00:00:00 2001 From: KolyaDobrydnev Date: Tue, 18 Jul 2023 16:05:57 +0300 Subject: [PATCH 1/3] General or Primary box parameter --- instagrapi/mixins/direct.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/instagrapi/mixins/direct.py b/instagrapi/mixins/direct.py index eb680567..97445630 100644 --- a/instagrapi/mixins/direct.py +++ b/instagrapi/mixins/direct.py @@ -1,5 +1,6 @@ import random import re +from sre_constants import LITERAL import time from pathlib import Path from typing import List, Optional, Tuple @@ -22,14 +23,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 +45,7 @@ def direct_threads( self, amount: int = 20, selected_filter: SELECTED_FILTER = "", + box: BOX = "", thread_message_limit: Optional[int] = None, ) -> List[DirectThread]: """ @@ -78,6 +83,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]: @@ -116,6 +122,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: From 94abedb77d7cb23f5f92179c03364eb45fa733b7 Mon Sep 17 00:00:00 2001 From: KolyaDobrydnev Date: Tue, 18 Jul 2023 16:11:06 +0300 Subject: [PATCH 2/3] Passing Box parameter to chunk method. Docs --- instagrapi/mixins/direct.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/instagrapi/mixins/direct.py b/instagrapi/mixins/direct.py index 97445630..287aa380 100644 --- a/instagrapi/mixins/direct.py +++ b/instagrapi/mixins/direct.py @@ -57,6 +57,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 @@ -70,7 +72,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) @@ -96,6 +98,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 From 64c6454f5c667ca697646fcf53e75e3cfdb6a77e Mon Sep 17 00:00:00 2001 From: KolyaDobrydnev Date: Tue, 18 Jul 2023 16:14:29 +0300 Subject: [PATCH 3/3] Wrong import fix --- instagrapi/mixins/direct.py | 1 - 1 file changed, 1 deletion(-) diff --git a/instagrapi/mixins/direct.py b/instagrapi/mixins/direct.py index 287aa380..75f41435 100644 --- a/instagrapi/mixins/direct.py +++ b/instagrapi/mixins/direct.py @@ -1,6 +1,5 @@ import random import re -from sre_constants import LITERAL import time from pathlib import Path from typing import List, Optional, Tuple