Skip to content

Commit

Permalink
No "response_to_comment" method [#365] Added replied_to_comment_id fo…
Browse files Browse the repository at this point in the history
…r cl.media_comment
  • Loading branch information
adw0rd committed Dec 2, 2021
1 parent 8a0ae70 commit 5989e37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
29 changes: 22 additions & 7 deletions docs/usage-guide/comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Post comment, viewing, like and unlike comments

| Method | Return | Description
| ---------------------------------------------------------- | ------------------ | --------------------------
| media_comment(media_id: str, message: str) | Comment | Add new comment to media
| media_comments(media_id: str, amount: int = 0) | List\[Comment] | Get a list comments for media (amount=0 - fetch all comments)
| comment_like(comment_pk: int) | bool | Like a comment
| comment_unlike(comment_pk: int) | bool | Unlike a comment
| comment_bulk_delete(media_id: str, comment_pks: List[int]) | bool | Delete a comment
| Method | Return | Description
| --------------------------------------------------------------------------------------- | ------------------ | --------------------------
| media_comment(media_id: str, message: str, replied_to_comment_id: Optional[int] = None) | Comment | Add new comment to media
| media_comments(media_id: str, amount: int = 0) | List\[Comment] | Get a list comments for media (amount=0 - all comments)
| comment_like(comment_pk: int) | bool | Like a comment
| comment_unlike(comment_pk: int) | bool | Unlike a comment
| comment_bulk_delete(media_id: str, comment_pks: List[int]) | bool | Delete a comment


Example:
Expand Down Expand Up @@ -36,6 +36,21 @@ Example:
'has_liked': None,
'like_count': None}

>>> comment = cl.media_comment(media_id, "Test comment 2", replied_to_comment_id=comment.pk)
>>> comment.dict()
{'pk': 17926777897585109,
'text': 'Test comment 2',
'user': {'pk': 1903424587,
'username': 'adw0rd',
'full_name': 'Mikhail Andreev',
'profile_pic_url': HttpUrl('https://scontent-hel3-1.cdninstagram.com/v/t51.2885-19/s150x150/156689363_269505058076642_6448820957073669709_n.jpg?tp=1&_nc_ht=scontent-hel3-1.cdninstagram.com&_nc_ohc=EtzrL0pAdg8AX9pE_wN&edm=ABQSlwABAAAA&ccb=7-4&oh=e04d45b7651140e7fef61b1f67f1f408&oe=60C65AD1&_nc_sid=b2b2bd', scheme='https', host='scontent-hel3-1.cdninstagram.com', tld='com', host_type='domain', path='/v/t51.2885-19/s150x150/156689363_269505058076642_6448820957073669709_n.jpg', query='tp=1&_nc_ht=scontent-hel3-1.cdninstagram.com&_nc_ohc=EtzrL0pAdg8AX9pE_wN&edm=ABQSlwABAAAA&ccb=7-4&oh=e04d45b7651140e7fef61b1f67f1f408&oe=60C65AD1&_nc_sid=b2b2bd'),
'stories': []},
'created_at_utc': datetime.datetime(2021, 5, 15, 14, 50, 3, tzinfo=datetime.timezone.utc),
'content_type': 'comment',
'status': 'Active',
'has_liked': None,
'like_count': None}

>>> comments = cl.media_comments(media_id)
>>> comments[0].dict()
{'pk': 17926777897585108,
Expand Down
25 changes: 13 additions & 12 deletions instagrapi/mixins/comment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import List
from typing import List, Optional

from instagrapi.exceptions import ClientError, ClientNotFoundError, MediaNotFound
from instagrapi.extractors import extract_comment
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_comments():
comments = comments[:amount]
return comments

def media_comment(self, media_id: str, text: str) -> Comment:
def media_comment(self, media_id: str, text: str, replied_to_comment_id: Optional[int] = None) -> Comment:
"""
Post a comment on a media
Expand All @@ -83,18 +83,19 @@ def media_comment(self, media_id: str, text: str) -> Comment:
"""
assert self.user_id, "Login required"
media_id = self.media_id(media_id)
data = {
"delivery_class": "organic",
"feed_position": "0",
"container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2",
"user_breadcrumb": self.gen_user_breadcrumb(len(text)),
"idempotence_token": self.generate_uuid(),
"comment_text": text,
}
if replied_to_comment_id:
data["replied_to_comment_id"] = int(replied_to_comment_id)
result = self.private_request(
f"media/{media_id}/comment/",
self.with_action_data(
{
"delivery_class": "organic",
"feed_position": "0",
"container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2",
"user_breadcrumb": self.gen_user_breadcrumb(len(text)),
"idempotence_token": self.generate_uuid(),
"comment_text": text,
}
),
self.with_action_data(data),
)
return extract_comment(result["comment"])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

setup(
name='instagrapi',
version='1.15.19',
version='1.15.20',
author='Mikhail Andreev',
author_email='[email protected]',
license='MIT',
Expand Down

0 comments on commit 5989e37

Please sign in to comment.