Skip to content

Commit 4f5e95a

Browse files
author
Pietro Albini
committed
Add support for sending videos
Added and documented the following methods: * botogram.Bot.send_video * botogram.User.send_video * botogram.Chat.send_video * botogram.Message.reply_with_video
1 parent 584e9e0 commit 4f5e95a

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

botogram/frozenbot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ def send_voice(self, chat, path, duration=None, reply_to=None, extra=None):
154154
obj = objects.Chat({"id": chat, "type": ""}, self.api)
155155
obj.send_voice(path, duration, reply_to, extra)
156156

157+
def send_video(self, chat, path, duration=None, caption=None,
158+
reply_to=None, extra=None):
159+
"""Send a video in a chat"""
160+
obj = objects.Chat({"id": chat, "type": ""}, self.api)
161+
obj.send_video(path, duration, caption, reply_to, extra)
162+
157163
def send_file(self, chat, path, reply_to=None, extra=None):
158164
"""Send a generic file in a chat"""
159165
obj = objects.Chat({"id": chat, "type": ""}, self.api)

botogram/objects/mixins.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ def send_voice(self, path, duration=None, title=None, reply_to=None,
9494
files = {"voice": open(path, "rb")}
9595
self._api.call("sendVoice", args, files)
9696

97+
@_require_api
98+
def send_video(self, path, duration=None, caption=None, reply_to=None,
99+
extra=None):
100+
"""Send a video"""
101+
args = self._get_call_args(reply_to, extra)
102+
if duration is not None:
103+
args["duration"] = duration
104+
if caption is not None:
105+
args["caption"] = caption
106+
107+
files = {"video": open(path, "rb")}
108+
self._api.call("sendVideo", args, files)
109+
97110
@_require_api
98111
def send_file(self, path, reply_to=None, extra=None):
99112
"""Send a generic file"""
@@ -149,6 +162,11 @@ def reply_with_voice(self, path, duration=None, extra=None):
149162
"""Reply with a voice message to the current message"""
150163
self.chat.send_voice(path, duration, self.message_id, extra)
151164

165+
@_require_api
166+
def reply_with_video(self, path, duration=None, caption=None, extra=None):
167+
"""Reply with a video to the current message"""
168+
self.chat.send_video(path, duration, caption, self.message_id, extra)
169+
152170
@_require_api
153171
def reply_with_file(self, path, extra=None):
154172
"""Reply with a generic file to the current chat"""

docs/api/bot.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,31 @@ components.
378378
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
379379
:param object extra: An extra reply interface object to attach
380380

381+
.. py:method:: send_video(chat, path, [duration=None, caption=None, reply_to=None, extra=None])
382+
383+
This method sends a video to a specific chat. The chat must be identified
384+
by its ID, and Telegram applies some restrictions on the chats allowed to
385+
receive your photo: only users who sent you a message in the past are
386+
allowed, and also the group chats your bot is currently in.
387+
388+
You must provide the *path* to the video, and you may optionally specify
389+
the *duration* and the *caption* of the video. If the video you're
390+
sending is in reply to another message, set *reply_to* to the ID of the
391+
other :py:class:`~botogram.Message`. *extra* is an optional object which
392+
specifies additional reply interface options on the recipient's end, and
393+
can be one of the following types:
394+
395+
* :py:class:`botogram.ReplyKeyboardMarkup`
396+
* :py:class:`botogram.ReplyKeyboardHide`
397+
* :py:class:`botogram.ForceReply`
398+
399+
:param int chat: The ID of the chat which should receive the video
400+
:param str path: The path to the video
401+
:param int duration: The video duration, in seconds
402+
:param str caption The caption of the video
403+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
404+
:param object extra: An extra reply interface object to attach
405+
381406
.. py:method:: send_file(chat, path, [reply_to=None, extra=None])
382407
383408
This method sends a generic file to a specific chat. The chat must be

docs/api/telegram.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ Available Classes
139139
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
140140
:param object extra: An extra reply interface object to attach
141141

142+
.. py:method:: send_video(path, [duration=None, caption=None, reply_to=None, extra=None])
143+
144+
Send the video found in the *path* to the user. You may optionally
145+
specify the *duration* and the *caption* of the video. If the audio track
146+
you're sending is in reply to another message, set *reply_to* to the ID
147+
of the other :py:class:`~botogram.Message`. *extra* is an optional
148+
object which specifies additional reply interface options on the
149+
recipient's end, and can be one of the following types:
150+
151+
* :py:class:`botogram.ReplyKeyboardMarkup`
152+
* :py:class:`botogram.ReplyKeyboardHide`
153+
* :py:class:`botogram.ForceReply`
154+
155+
:param str path: The path to the video
156+
:param int duration: The video duration, in seconds
157+
:param str caption: The caption of the video
158+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
159+
:param object extra: An extra reply interface object to attach
160+
142161
.. py:method:: send_file(path, [reply_to=None, extra=None])
143162
144163
Send the generic file found in the *path* to the user. If the file you're
@@ -289,6 +308,25 @@ Available Classes
289308
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
290309
:param object extra: An extra reply interface object to attach
291310

311+
.. py:method:: send_video(path, [duration=None, caption=None, reply_to=None, extra=None])
312+
313+
Send the video found in the *path* to the chat. You may optionally
314+
specify the *duration* and the *caption* of the video. If the audio track
315+
you're sending is in reply to another message, set *reply_to* to the ID
316+
of the other :py:class:`~botogram.Message`. *extra* is an optional
317+
object which specifies additional reply interface options on the
318+
recipient's end, and can be one of the following types:
319+
320+
* :py:class:`botogram.ReplyKeyboardMarkup`
321+
* :py:class:`botogram.ReplyKeyboardHide`
322+
* :py:class:`botogram.ForceReply`
323+
324+
:param str path: The path to the video
325+
:param int duration: The video duration, in seconds
326+
:param str caption: The caption of the video
327+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
328+
:param object extra: An extra reply interface object to attach
329+
292330
.. py:method:: send_file(path, [reply_to=None, extra=None])
293331
294332
Send the generic file found in the *path* to the chat. If the file you're
@@ -582,6 +620,22 @@ Available Classes
582620
:param int duration: The message duration, in seconds
583621
:param object extra: An extra reply interface object to attach
584622

623+
.. py:method:: send_video(path, [duration=None, caption=None, extra=None])
624+
625+
Reply with the video found in the *path* to the chat. You may optionally
626+
specify the *duration* and the *caption* of the video. *extra* is an
627+
optional object which specifies additional reply interface options on the
628+
recipient's end, and can be one of the following types:
629+
630+
* :py:class:`botogram.ReplyKeyboardMarkup`
631+
* :py:class:`botogram.ReplyKeyboardHide`
632+
* :py:class:`botogram.ForceReply`
633+
634+
:param str path: The path to the video
635+
:param int duration: The video duration, in seconds
636+
:param str caption: The caption of the video
637+
:param object extra: An extra reply interface object to attach
638+
585639
.. py:method:: reply_with_file(path, [extra=None])
586640
587641
Reply with the generic file found in the *path* to the chat. If the file

0 commit comments

Comments
 (0)