Skip to content

Commit

Permalink
Merge pull request #1950 from Revisto/master
Browse files Browse the repository at this point in the history
Add Reply to Message Functionality in Instagram Direct Messages
  • Loading branch information
subzeroid committed Jun 17, 2024
2 parents 73cf7ee + 19d429e commit c5b67ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions instagrapi/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def extract_direct_message(data):
int(data["timestamp"]) // 1_000_000
)
data["user_id"] = str(data.get("user_id", ""))
data["client_context"] = data.get("client_context", "")

return DirectMessage(**data)

Expand Down
5 changes: 5 additions & 0 deletions instagrapi/mixins/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def direct_send(
user_ids: List[int] = [],
thread_ids: List[int] = [],
send_attribute: SEND_ATTRIBUTE = "message_button",
reply_to_message: Optional[DirectMessage] = None,
) -> DirectMessage:
"""
Send a direct message to list of users or threads
Expand Down Expand Up @@ -450,6 +451,10 @@ def direct_send(
kwargs["thread_ids"] = dumps([int(tid) for tid in thread_ids])
if user_ids:
kwargs["recipient_users"] = dumps([[int(uid) for uid in user_ids]])
if reply_to_message:
kwargs["replied_to_action_source"] = "swipe"
kwargs["replied_to_item_id"] = reply_to_message.id
kwargs["replied_to_client_context"] = reply_to_message.client_context
result = self.private_request(
f"direct_v2/threads/broadcast/{method}/",
data=self.with_default_data(kwargs),
Expand Down
1 change: 1 addition & 0 deletions instagrapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class DirectMessage(TypesBaseModel):
xma_share: Optional[MediaXma] = None
clip: Optional[Media] = None
placeholder: Optional[dict] = None
client_context: Optional[str] = None


class DirectResponse(TypesBaseModel):
Expand Down

0 comments on commit c5b67ac

Please sign in to comment.