Skip to content

Commit 1c08163

Browse files
posting, editing, deleting stories(needs testing)
1 parent 1713909 commit 1c08163

4 files changed

Lines changed: 329 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6664,7 +6664,126 @@ def transfer_gift(
66646664
new_owner_chat_id=new_owner_chat_id,
66656665
star_count=star_count
66666666
)
6667+
6668+
def post_story(
6669+
self, business_connection_id: str, content: types.InputStoryContent,
6670+
active_period: int, caption: Optional[str]=None,
6671+
parse_mode: Optional[str]=None,
6672+
caption_entities: Optional[List[types.MessageEntity]]=None,
6673+
areas: Optional[List[types.StoryArea]]=None,
6674+
post_to_chat_page: Optional[bool]=None,
6675+
protect_content: Optional[bool]=None) -> types.Story:
6676+
6677+
"""
6678+
Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
6679+
6680+
Telegram documentation: https://core.telegram.org/bots/api#poststory
6681+
6682+
:param business_connection_id: Unique identifier of the business connection
6683+
:type business_connection_id: :obj:`str`
6684+
6685+
:param content: Content of the story
6686+
:type content: :class:`telebot.types.InputStoryContent`
6687+
6688+
: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
6689+
:type active_period: :obj:`int`
6690+
6691+
:param caption: Caption of the story, 0-2048 characters after entities parsing
6692+
:type caption: :obj:`str`
6693+
6694+
:param parse_mode: Mode for parsing entities in the story caption. See formatting options for more details.
6695+
:type parse_mode: :obj:`str`
6696+
6697+
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
6698+
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
6699+
6700+
:param areas: A JSON-serialized list of clickable areas to be shown on the story
6701+
:type areas: :obj:`list` of :class:`telebot.types.StoryArea`
6702+
6703+
:param post_to_chat_page: Pass True to keep the story accessible after it expires
6704+
:type post_to_chat_page: :obj:`bool`
6705+
6706+
:param protect_content: Pass True if the content of the story must be protected from forwarding and screenshotting
6707+
:type protect_content: :obj:`bool`
6708+
6709+
:return: On success, a Story object is returned.
6710+
:rtype: :class:`telebot.types.Story`
6711+
"""
6712+
return types.Story.de_json(
6713+
apihelper.post_story(
6714+
self.token, business_connection_id, content,
6715+
active_period, caption=caption,
6716+
parse_mode=parse_mode,
6717+
caption_entities=caption_entities,
6718+
areas=areas,
6719+
post_to_chat_page=post_to_chat_page,
6720+
protect_content=protect_content
6721+
)
6722+
)
6723+
6724+
def edit_story(
6725+
self, business_connection_id: str, story_id: int,
6726+
content: types.InputStoryContent,
6727+
caption: Optional[str]=None,
6728+
parse_mode: Optional[str]=None,
6729+
caption_entities: Optional[List[types.MessageEntity]]=None,
6730+
areas: Optional[List[types.StoryArea]]=None) -> types.Story:
6731+
"""
6732+
Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
66676733
6734+
Telegram documentation: https://core.telegram.org/bots/api#editstory
6735+
6736+
:param business_connection_id: Unique identifier of the business connection
6737+
:type business_connection_id: :obj:`str`
6738+
6739+
:param story_id: Unique identifier of the story to edit
6740+
:type story_id: :obj:`int`
6741+
6742+
:param content: Content of the story
6743+
:type content: :class:`telebot.types.InputStoryContent`
6744+
6745+
:param caption: Caption of the story, 0-2048 characters after entities parsing
6746+
:type caption: :obj:`str`
6747+
6748+
:param parse_mode: Mode for parsing entities in the story caption. See formatting options for more details.
6749+
:type parse_mode: :obj:`str`
6750+
6751+
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
6752+
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
6753+
6754+
:param areas: A JSON-serialized list of clickable areas to be shown on the story
6755+
:type areas: :obj:`list` of :class:`telebot.types.StoryArea`
6756+
6757+
:return: On success, a Story object is returned.
6758+
:rtype: :class:`telebot.types.Story`
6759+
6760+
"""
6761+
return types.Story.de_json(
6762+
apihelper.edit_story(
6763+
self.token, business_connection_id, story_id,
6764+
content, caption=caption,
6765+
parse_mode=parse_mode,
6766+
caption_entities=caption_entities,
6767+
areas=areas
6768+
)
6769+
)
6770+
6771+
def delete_story(self, business_connection_id: str, story_id: int) -> bool:
6772+
"""
6773+
Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns True on success.
6774+
6775+
Telegram documentation: https://core.telegram.org/bots/api#deletestory
6776+
6777+
:param business_connection_id: Unique identifier of the business connection
6778+
:type business_connection_id: :obj:`str`
6779+
6780+
:param story_id: Unique identifier of the story to delete
6781+
:type story_id: :obj:`int`
6782+
6783+
:return: Returns True on success.
6784+
:rtype: :obj:`bool`
6785+
"""
6786+
return apihelper.delete_story(self.token, business_connection_id, story_id)
66686787

66696788
def get_available_gifts(self) -> types.Gifts:
66706789
"""

telebot/apihelper.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,51 @@ def transfer_gift(token, business_connection_id, owned_gift_id, new_owner_chat_i
20902090
payload['star_count'] = star_count
20912091
return _make_request(token, method_url, params=payload, method='post')
20922092

2093+
def post_story(token, business_connection_id, content, active_period, caption=None, parse_mode=None,
2094+
caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None):
2095+
method_url = 'postStory'
2096+
payload = {'business_connection_id': business_connection_id, 'active_period': active_period}
2097+
2098+
content_json, files = content.convert_input_story()
2099+
payload['content'] = content_json
2100+
2101+
if caption:
2102+
payload['caption'] = caption
2103+
if parse_mode:
2104+
payload['parse_mode'] = parse_mode
2105+
if caption_entities:
2106+
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
2107+
if areas:
2108+
payload['areas'] = json.dumps([area.to_json() for area in areas])
2109+
if post_to_chat_page is not None:
2110+
payload['post_to_chat_page'] = post_to_chat_page
2111+
if protect_content is not None:
2112+
payload['protect_content'] = protect_content
2113+
return _make_request(token, method_url, params=payload, files=files, method='post')
2114+
2115+
def edit_story(token, business_connection_id, story_id, content, caption=None, parse_mode=None,
2116+
caption_entities=None, areas=None):
2117+
method_url = 'editStory'
2118+
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
2119+
2120+
content_json, files = content.convert_input_story()
2121+
payload['content'] = content_json
2122+
2123+
if caption:
2124+
payload['caption'] = caption
2125+
if parse_mode:
2126+
payload['parse_mode'] = parse_mode
2127+
if caption_entities:
2128+
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
2129+
if areas:
2130+
payload['areas'] = json.dumps([area.to_json() for area in areas])
2131+
return _make_request(token, method_url, params=payload, files=files, method='post')
2132+
2133+
def delete_story(token, business_connection_id, story_id):
2134+
method_url = 'deleteStory'
2135+
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
2136+
return _make_request(token, method_url, params=payload, method='post')
2137+
20932138
def create_new_sticker_set(
20942139
token, user_id, name, title, stickers, sticker_type=None, needs_repainting=None):
20952140
method_url = 'createNewStickerSet'

telebot/async_telebot.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8120,6 +8120,126 @@ async def transfer_gift(
81208120
new_owner_chat_id=new_owner_chat_id,
81218121
star_count=star_count
81228122
)
8123+
8124+
async def post_story(
8125+
self, business_connection_id: str, content: types.InputStoryContent,
8126+
active_period: int, caption: Optional[str]=None,
8127+
parse_mode: Optional[str]=None,
8128+
caption_entities: Optional[List[types.MessageEntity]]=None,
8129+
areas: Optional[List[types.StoryArea]]=None,
8130+
post_to_chat_page: Optional[bool]=None,
8131+
protect_content: Optional[bool]=None) -> types.Story:
8132+
8133+
"""
8134+
Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
8135+
8136+
Telegram documentation: https://core.telegram.org/bots/api#poststory
8137+
8138+
:param business_connection_id: Unique identifier of the business connection
8139+
:type business_connection_id: :obj:`str`
8140+
8141+
:param content: Content of the story
8142+
:type content: :class:`telebot.types.InputStoryContent`
8143+
8144+
: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
8145+
:type active_period: :obj:`int`
8146+
8147+
:param caption: Caption of the story, 0-2048 characters after entities parsing
8148+
:type caption: :obj:`str`
8149+
8150+
:param parse_mode: Mode for parsing entities in the story caption. See formatting options for more details.
8151+
:type parse_mode: :obj:`str`
8152+
8153+
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
8154+
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
8155+
8156+
:param areas: A JSON-serialized list of clickable areas to be shown on the story
8157+
:type areas: :obj:`list` of :class:`telebot.types.StoryArea`
8158+
8159+
:param post_to_chat_page: Pass True to keep the story accessible after it expires
8160+
:type post_to_chat_page: :obj:`bool`
8161+
8162+
:param protect_content: Pass True if the content of the story must be protected from forwarding and screenshotting
8163+
:type protect_content: :obj:`bool`
8164+
8165+
:return: On success, a Story object is returned.
8166+
:rtype: :class:`telebot.types.Story`
8167+
"""
8168+
return types.Story.de_json(
8169+
await asyncio_helper.post_story(
8170+
self.token, business_connection_id, content,
8171+
active_period, caption=caption,
8172+
parse_mode=parse_mode,
8173+
caption_entities=caption_entities,
8174+
areas=areas,
8175+
post_to_chat_page=post_to_chat_page,
8176+
protect_content=protect_content
8177+
)
8178+
)
8179+
8180+
async def edit_story(
8181+
self, business_connection_id: str, story_id: int,
8182+
content: types.InputStoryContent,
8183+
caption: Optional[str]=None,
8184+
parse_mode: Optional[str]=None,
8185+
caption_entities: Optional[List[types.MessageEntity]]=None,
8186+
areas: Optional[List[types.StoryArea]]=None) -> types.Story:
8187+
"""
8188+
Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
8189+
8190+
Telegram documentation: https://core.telegram.org/bots/api#editstory
8191+
8192+
:param business_connection_id: Unique identifier of the business connection
8193+
:type business_connection_id: :obj:`str`
8194+
8195+
:param story_id: Unique identifier of the story to edit
8196+
:type story_id: :obj:`int`
8197+
8198+
:param content: Content of the story
8199+
:type content: :class:`telebot.types.InputStoryContent`
8200+
8201+
:param caption: Caption of the story, 0-2048 characters after entities parsing
8202+
:type caption: :obj:`str`
8203+
8204+
:param parse_mode: Mode for parsing entities in the story caption. See formatting options for more details.
8205+
:type parse_mode: :obj:`str`
8206+
8207+
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
8208+
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
8209+
8210+
:param areas: A JSON-serialized list of clickable areas to be shown on the story
8211+
:type areas: :obj:`list` of :class:`telebot.types.StoryArea`
8212+
8213+
:return: On success, a Story object is returned.
8214+
:rtype: :class:`telebot.types.Story`
8215+
8216+
"""
8217+
return types.Story.de_json(
8218+
await asyncio_helper.edit_story(
8219+
self.token, business_connection_id, story_id,
8220+
content, caption=caption,
8221+
parse_mode=parse_mode,
8222+
caption_entities=caption_entities,
8223+
areas=areas
8224+
)
8225+
)
8226+
8227+
async def delete_story(self, business_connection_id: str, story_id: int) -> bool:
8228+
"""
8229+
Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns True on success.
8230+
8231+
Telegram documentation: https://core.telegram.org/bots/api#deletestory
8232+
8233+
:param business_connection_id: Unique identifier of the business connection
8234+
:type business_connection_id: :obj:`str`
8235+
8236+
:param story_id: Unique identifier of the story to delete
8237+
:type story_id: :obj:`int`
8238+
8239+
:return: Returns True on success.
8240+
:rtype: :obj:`bool`
8241+
"""
8242+
return await asyncio_helper.delete_story(self.token, business_connection_id, story_id)
81238243

81248244
async def get_available_gifts(self) -> types.Gifts:
81258245
"""

telebot/asyncio_helper.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,51 @@ async def transfer_gift(token, business_connection_id, owned_gift_id, new_owner_
20632063
payload['star_count'] = star_count
20642064
return await _process_request(token, method_url, params=payload, method='post')
20652065

2066+
async def post_story(token, business_connection_id, content, active_period, caption=None, parse_mode=None,
2067+
caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None):
2068+
method_url = 'postStory'
2069+
payload = {'business_connection_id': business_connection_id, 'active_period': active_period}
2070+
2071+
content_json, files = content.convert_input_story()
2072+
payload['content'] = content_json
2073+
2074+
if caption:
2075+
payload['caption'] = caption
2076+
if parse_mode:
2077+
payload['parse_mode'] = parse_mode
2078+
if caption_entities:
2079+
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
2080+
if areas:
2081+
payload['areas'] = json.dumps([area.to_json() for area in areas])
2082+
if post_to_chat_page is not None:
2083+
payload['post_to_chat_page'] = post_to_chat_page
2084+
if protect_content is not None:
2085+
payload['protect_content'] = protect_content
2086+
return await _process_request(token, method_url, params=payload, files=files, method='post')
2087+
2088+
async def edit_story(token, business_connection_id, story_id, content, caption=None, parse_mode=None,
2089+
caption_entities=None, areas=None):
2090+
method_url = 'editStory'
2091+
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
2092+
2093+
content_json, files = content.convert_input_story()
2094+
payload['content'] = content_json
2095+
2096+
if caption:
2097+
payload['caption'] = caption
2098+
if parse_mode:
2099+
payload['parse_mode'] = parse_mode
2100+
if caption_entities:
2101+
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
2102+
if areas:
2103+
payload['areas'] = json.dumps([area.to_json() for area in areas])
2104+
return await _process_request(token, method_url, params=payload, files=files, method='post')
2105+
2106+
async def delete_story(token, business_connection_id, story_id):
2107+
method_url = 'deleteStory'
2108+
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
2109+
return await _process_request(token, method_url, params=payload, method='post')
2110+
20662111
async def get_available_gifts(token):
20672112
method_url = 'getAvailableGifts'
20682113
return await _process_request(token, method_url)

0 commit comments

Comments
 (0)