Skip to content

Commit 5989e37

Browse files
committed
No "response_to_comment" method [#365] Added replied_to_comment_id for cl.media_comment
1 parent 8a0ae70 commit 5989e37

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

docs/usage-guide/comment.md

+22-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Post comment, viewing, like and unlike comments
44

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

1313

1414
Example:
@@ -36,6 +36,21 @@ Example:
3636
'has_liked': None,
3737
'like_count': None}
3838

39+
>>> comment = cl.media_comment(media_id, "Test comment 2", replied_to_comment_id=comment.pk)
40+
>>> comment.dict()
41+
{'pk': 17926777897585109,
42+
'text': 'Test comment 2',
43+
'user': {'pk': 1903424587,
44+
'username': 'adw0rd',
45+
'full_name': 'Mikhail Andreev',
46+
'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'),
47+
'stories': []},
48+
'created_at_utc': datetime.datetime(2021, 5, 15, 14, 50, 3, tzinfo=datetime.timezone.utc),
49+
'content_type': 'comment',
50+
'status': 'Active',
51+
'has_liked': None,
52+
'like_count': None}
53+
3954
>>> comments = cl.media_comments(media_id)
4055
>>> comments[0].dict()
4156
{'pk': 17926777897585108,

instagrapi/mixins/comment.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import random
2-
from typing import List
2+
from typing import List, Optional
33

44
from instagrapi.exceptions import ClientError, ClientNotFoundError, MediaNotFound
55
from instagrapi.extractors import extract_comment
@@ -65,7 +65,7 @@ def get_comments():
6565
comments = comments[:amount]
6666
return comments
6767

68-
def media_comment(self, media_id: str, text: str) -> Comment:
68+
def media_comment(self, media_id: str, text: str, replied_to_comment_id: Optional[int] = None) -> Comment:
6969
"""
7070
Post a comment on a media
7171
@@ -83,18 +83,19 @@ def media_comment(self, media_id: str, text: str) -> Comment:
8383
"""
8484
assert self.user_id, "Login required"
8585
media_id = self.media_id(media_id)
86+
data = {
87+
"delivery_class": "organic",
88+
"feed_position": "0",
89+
"container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2",
90+
"user_breadcrumb": self.gen_user_breadcrumb(len(text)),
91+
"idempotence_token": self.generate_uuid(),
92+
"comment_text": text,
93+
}
94+
if replied_to_comment_id:
95+
data["replied_to_comment_id"] = int(replied_to_comment_id)
8696
result = self.private_request(
8797
f"media/{media_id}/comment/",
88-
self.with_action_data(
89-
{
90-
"delivery_class": "organic",
91-
"feed_position": "0",
92-
"container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2",
93-
"user_breadcrumb": self.gen_user_breadcrumb(len(text)),
94-
"idempotence_token": self.generate_uuid(),
95-
"comment_text": text,
96-
}
97-
),
98+
self.with_action_data(data),
9899
)
99100
return extract_comment(result["comment"])
100101

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
setup(
3232
name='instagrapi',
33-
version='1.15.19',
33+
version='1.15.20',
3434
author='Mikhail Andreev',
3535
author_email='[email protected]',
3636
license='MIT',

0 commit comments

Comments
 (0)