Skip to content

Commit b47c73f

Browse files
Added InputStoryContent
1 parent 817f2ad commit b47c73f

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9651,3 +9651,4 @@ def _notify_command_handlers(self, handlers, new_messages, update_type):
96519651
handlers=handlers,
96529652
middlewares=middlewares,
96539653
update_type=update_type)
9654+

telebot/types.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11773,6 +11773,96 @@ def de_json(cls, json_string):
1177311773
obj = cls.check_json(json_string)
1177411774
obj['colors'] = UniqueGiftBackdropColors.de_json(obj['colors'])
1177511775
return cls(**obj)
11776+
11777+
class InputStoryContent(JsonSerializable):
11778+
"""
11779+
This object describes the content of a story to post. Currently, it can be one of
11780+
InputStoryContentPhoto
11781+
InputStoryContentVideo
11782+
11783+
Telegram documentation: https://core.telegram.org/bots/api#inputstorycontent
11784+
11785+
"""
11786+
11787+
11788+
class InputStoryContentPhoto(InputStoryContent):
11789+
"""
11790+
This object describes a photo to post as a story.
11791+
11792+
Telegram documentation: https://core.telegram.org/bots/api#inputstorycontentphoto
11793+
11794+
:param photo: The photo to post as a story. The photo must be of the size 1080x1920 and must not exceed 10 MB. The photo can't be reused and can only be uploaded as a new file, so you can pass “attach://<file_attach_name>” if the photo was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files
11795+
:type photo: :obj:`str`
11796+
11797+
:return: Instance of the class
11798+
:rtype: :class:`InputStoryContentPhoto`
11799+
"""
11800+
def __init__(self, photo: InputFile, **kwargs):
11801+
self.type: str = "photo"
11802+
self.photo: InputFile = photo
11803+
self._photo_name = service_utils.generate_random_token()
11804+
self._photo_dic = "attach://{}".format(self._photo_name)
11805+
11806+
def to_json(self):
11807+
return json.dumps(self.to_dict())
11808+
11809+
def to_dict(self):
11810+
data = {
11811+
'type': self.type,
11812+
'photo': self._photo_dic
11813+
}
11814+
return data
11815+
11816+
def convert_input_story(self):
11817+
return self.to_json(), {self._photo_name: self.photo}
1177611818

1177711819

11820+
class InputStoryContentVideo(InputStoryContent):
11821+
"""
11822+
This object describes a video to post as a story.
11823+
11824+
Telegram documentation: https://core.telegram.org/bots/api#inputstorycontentvideo
11825+
11826+
:param video: The video to post as a story. The video must be of the size 720x1280, streamable, encoded with H.265 codec, with key frames added each second in the MPEG4 format, and must not exceed 30 MB. The video can't be reused and can only be uploaded as a new file, so you can pass “attach://<file_attach_name>” if the video was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files
11827+
:type video: :obj:`str`
11828+
11829+
:param duration: Optional. Precise duration of the video in seconds; 0-60
11830+
:type duration: :obj:`float`
11831+
11832+
:param cover_frame_timestamp: Optional. Timestamp in seconds of the frame that will be used as the static cover for the story. Defaults to 0.0.
11833+
:type cover_frame_timestamp: :obj:`float`
11834+
11835+
:param is_animation: Optional. Pass True if the video has no sound
11836+
:type is_animation: :obj:`bool`
11837+
11838+
:return: Instance of the class
11839+
:rtype: :class:`InputStoryContentVideo`
11840+
"""
11841+
def __init__(self, video: InputFile, duration: Optional[float] = None, cover_frame_timestamp: Optional[float] = None,
11842+
is_animation: Optional[bool] = None, **kwargs):
11843+
self.type: str = "video"
11844+
self.video: InputFile = video
11845+
self._video_name = service_utils.generate_random_token()
11846+
self._video_dic = "attach://{}".format(self._video_name)
11847+
self.duration: Optional[float] = duration
11848+
self.cover_frame_timestamp: Optional[float] = cover_frame_timestamp
11849+
self.is_animation: Optional[bool] = is_animation
11850+
def to_json(self):
11851+
return json.dumps(self.to_dict())
11852+
11853+
def to_dict(self):
11854+
data = {
11855+
'type': self.type,
11856+
'video': self._video_dic
11857+
}
11858+
if self.duration is not None:
11859+
data['duration'] = self.duration
11860+
if self.cover_frame_timestamp is not None:
11861+
data['cover_frame_timestamp'] = self.cover_frame_timestamp
11862+
if self.is_animation is not None:
11863+
data['is_animation'] = self.is_animation
11864+
return data
11865+
def convert_input_story(self):
11866+
return self.to_json(), {self._video_name: self.video}
11867+
1177811868

0 commit comments

Comments
 (0)