Skip to content

Commit 913ff95

Browse files
Added the method repostStory, allowing bots to repost stories across different business accounts they manage.
1 parent 8d61448 commit 913ff95

4 files changed

Lines changed: 114 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7283,6 +7283,50 @@ def post_story(
72837283
)
72847284
)
72857285

7286+
def repost_story(
7287+
self, business_connection_id: str,
7288+
from_chat_id: int, from_story_id: int,
7289+
active_period: int,
7290+
post_to_chat_page: Optional[bool]=None,
7291+
protect_content: Optional[bool]=None) -> types.Story:
7292+
"""
7293+
Reposts a story on behalf of a business account from another business account. Both business accounts
7294+
must be managed by the same bot, and the story on the source account must have been posted (or reposted)
7295+
by the bot. Requires the can_manage_stories business bot right for both business accounts. Returns Story on success.
7296+
7297+
Telegram documentation: https://core.telegram.org/bots/api#repoststory
7298+
7299+
:param business_connection_id: Unique identifier of the business connection
7300+
:type business_connection_id: :obj:`str`
7301+
7302+
:param from_chat_id: Unique identifier of the chat which posted the story that should be reposted
7303+
:type from_chat_id: :obj:`int`
7304+
7305+
:param from_story_id: Unique identifier of the story that should be reposted
7306+
:type from_story_id: :obj:`int`
7307+
7308+
:param active_period: Period after which the story is moved to the archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400
7309+
:type active_period: :obj:`int`
7310+
7311+
:param post_to_chat_page: Pass True to keep the story accessible after it expires
7312+
:type post_to_chat_page: :obj:`bool`
7313+
7314+
:param protect_content: Pass True if the content of the story must be protected from forwarding and screenshotting
7315+
:type protect_content: :obj:`bool`
7316+
7317+
:return: On success, a Story object is returned.
7318+
:rtype: :class:`telebot.types.Story`
7319+
"""
7320+
return types.Story.de_json(
7321+
apihelper.repost_story(
7322+
self.token, business_connection_id,
7323+
from_chat_id, from_story_id,
7324+
active_period,
7325+
post_to_chat_page=post_to_chat_page,
7326+
protect_content=protect_content
7327+
)
7328+
)
7329+
72867330
def edit_story(
72877331
self, business_connection_id: str, story_id: int,
72887332
content: types.InputStoryContent,

telebot/apihelper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,20 @@ def post_story(token, business_connection_id, content, active_period, caption=No
23142314
payload['protect_content'] = protect_content
23152315
return _make_request(token, method_url, params=payload, files=files, method='post')
23162316

2317+
2318+
def repost_story(token, business_connection_id, from_chat_id, from_story_id, active_period,
2319+
post_to_chat_page=None, protect_content=None):
2320+
method_url = 'repostStory'
2321+
payload = {'business_connection_id': business_connection_id, 'from_chat_id': from_chat_id,
2322+
'from_story_id': from_story_id, 'active_period': active_period}
2323+
2324+
if post_to_chat_page is not None:
2325+
payload['post_to_chat_page'] = post_to_chat_page
2326+
if protect_content is not None:
2327+
payload['protect_content'] = protect_content
2328+
return _make_request(token, method_url, params=payload, method='post')
2329+
2330+
23172331
def edit_story(token, business_connection_id, story_id, content, caption=None, parse_mode=None,
23182332
caption_entities=None, areas=None):
23192333
method_url = 'editStory'

telebot/async_telebot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8742,6 +8742,50 @@ async def post_story(
87428742
)
87438743
)
87448744

8745+
async def repost_story(
8746+
self, business_connection_id: str,
8747+
from_chat_id: int, from_story_id: int,
8748+
active_period: int,
8749+
post_to_chat_page: Optional[bool]=None,
8750+
protect_content: Optional[bool]=None) -> types.Story:
8751+
"""
8752+
Reposts a story on behalf of a business account from another business account. Both business accounts
8753+
must be managed by the same bot, and the story on the source account must have been posted (or reposted)
8754+
by the bot. Requires the can_manage_stories business bot right for both business accounts. Returns Story on success.
8755+
8756+
Telegram documentation: https://core.telegram.org/bots/api#repoststory
8757+
8758+
:param business_connection_id: Unique identifier of the business connection
8759+
:type business_connection_id: :obj:`str`
8760+
8761+
:param from_chat_id: Unique identifier of the chat which posted the story that should be reposted
8762+
:type from_chat_id: :obj:`int`
8763+
8764+
:param from_story_id: Unique identifier of the story that should be reposted
8765+
:type from_story_id: :obj:`int`
8766+
8767+
:param active_period: Period after which the story is moved to the archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400
8768+
:type active_period: :obj:`int`
8769+
8770+
:param post_to_chat_page: Pass True to keep the story accessible after it expires
8771+
:type post_to_chat_page: :obj:`bool`
8772+
8773+
:param protect_content: Pass True if the content of the story must be protected from forwarding and screenshotting
8774+
:type protect_content: :obj:`bool`
8775+
8776+
:return: On success, a Story object is returned.
8777+
:rtype: :class:`telebot.types.Story`
8778+
"""
8779+
return types.Story.de_json(
8780+
await asyncio_helper.repost_story(
8781+
self.token, business_connection_id,
8782+
from_chat_id, from_story_id,
8783+
active_period,
8784+
post_to_chat_page=post_to_chat_page,
8785+
protect_content=protect_content
8786+
)
8787+
)
8788+
87458789
async def edit_story(
87468790
self, business_connection_id: str, story_id: int,
87478791
content: types.InputStoryContent,

telebot/asyncio_helper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,18 @@ async def post_story(token, business_connection_id, content, active_period, capt
22822282
payload['protect_content'] = protect_content
22832283
return await _process_request(token, method_url, params=payload, files=files, method='post')
22842284

2285+
async def repost_story(token, business_connection_id, from_chat_id, from_story_id, active_period,
2286+
post_to_chat_page=None, protect_content=None):
2287+
method_url = 'repostStory'
2288+
payload = {'business_connection_id': business_connection_id, 'from_chat_id': from_chat_id,
2289+
'from_story_id': from_story_id, 'active_period': active_period}
2290+
2291+
if post_to_chat_page is not None:
2292+
payload['post_to_chat_page'] = post_to_chat_page
2293+
if protect_content is not None:
2294+
payload['protect_content'] = protect_content
2295+
return await _process_request(token, method_url, params=payload, method='post')
2296+
22852297
async def edit_story(token, business_connection_id, story_id, content, caption=None, parse_mode=None,
22862298
caption_entities=None, areas=None):
22872299
method_url = 'editStory'

0 commit comments

Comments
 (0)