Skip to content

Commit

Permalink
Merge pull request subzeroid#1521 from Yessirskiy/master
Browse files Browse the repository at this point in the history
direct_message_search() method added
  • Loading branch information
adw0rd authored Aug 9, 2023
2 parents 2ee902b + 3ea57d1 commit 7538239
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions instagrapi/mixins/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
extract_direct_response,
extract_user_short,
extract_direct_thread,
extract_direct_short_thread,
)
from instagrapi.types import (
DirectMessage,
Expand Down Expand Up @@ -567,6 +568,39 @@ def direct_search(
!= "" # Check to exclude suggestions from FB
]

def direct_message_search(self, query: str) -> List[Tuple[DirectMessage, DirectThread]]:
'''
Search query mentions in direct messages
Parameters
----------
query: str
Text query
Returns
-------
List[Tuple[DirectMessage, DirectThread]]
List of Tuples with DirectMessage (matched query) and its DirectThread
'''
params = {
"offsets" : '{"message_content":"0","reshared_content":""}',
"query" : query,
"result_types" : '["message_content","reshared_content"]'
}
result = self.private_request(
"direct_v2/search_secondary/",
params=params,
)
assert result.get("status", "") == "ok"
search_results = result.get("message_search_results", {})

data = []
for item in search_results.get("message_search_result_items", []):
message = item.get("matched_message_info", {})
thread = item.get("thread", {})
data.append((extract_direct_message(message.get("item_info", {})), extract_direct_short_thread(thread)))
return data

def direct_thread_by_participants(self, user_ids: List[int]) -> Dict:
"""
Get direct thread by participants
Expand Down

0 comments on commit 7538239

Please sign in to comment.