Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
from .inputcontactmessagecontent import InputContactMessageContent
from .webhookinfo import WebhookInfo
from .gamehighscore import GameHighScore
from .videonote import VideoNote
from .update import Update
from .bot import Bot
from .constants import (MAX_MESSAGE_LENGTH, MAX_CAPTION_LENGTH, SUPPORTED_WEBHOOK_PORTS,
Expand Down Expand Up @@ -115,5 +116,5 @@
'Video', 'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
'Game', 'GameHighScore'
'Game', 'GameHighScore', 'VideoNote'
]
61 changes: 61 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,66 @@ def send_voice(self,
timeout=timeout,
**kwargs)

@log
def send_video_note(self,
chat_id,
video_note,
duration=None,
length=None,
disable_notification=False,
reply_to_message_id=None,
reply_markup=None,
timeout=20.,
**kwargs):
"""As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute
long. Use this method to send video messages

Args:
chat_id (int|str): Unique identifier for the message recipient - Chat id.
video_note (InputFile|str): Video note to send. Pass a file_id as String to send a
video note that exists on the Telegram servers (recommended) or upload a new video.
Sending video notes by a URL is currently unsupported
duration (Optional[int]): Duration of sent audio in seconds.
length (Optional[int]): Video width and height
disable_notification (Optional[bool]): Sends the message silently. iOS users will not
receive a notification, Android users will receive a notification with no sound.
reply_to_message_id (Optional[int]): If the message is a reply, ID of the original
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to remove reply keyboard or to force a reply from the user.
timeout (Optional[int|float]): Send file timeout (default: 20 seconds).
**kwargs (dict): Arbitrary keyword arguments.

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/sendVideoNote'.format(self.base_url)

data = {'chat_id': chat_id, 'video_note': video_note}

if duration is not None:
data['duration'] = duration
if length is not None:
data['length'] = length

return self._message_wrapper(
url,
data,
chat_id=chat_id,
video_note=video_note,
duration=duration,
length=length,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
reply_markup=reply_markup,
timeout=timeout,
**kwargs)

@log
@message
def send_location(self,
Expand Down Expand Up @@ -1787,6 +1847,7 @@ def __reduce__(self):
sendSticker = send_sticker
sendVideo = send_video
sendVoice = send_voice
sendVideoNote = send_video_note
sendLocation = send_location
sendVenue = send_venue
sendContact = send_contact
Expand Down
2 changes: 2 additions & 0 deletions telegram/chataction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ class ChatAction(object):
UPLOAD_AUDIO = 'upload_audio'
UPLOAD_DOCUMENT = 'upload_document'
FIND_LOCATION = 'find_location'
RECORD_VIDEO_NOTE = 'record_video_note'
UPLOAD_VIDEO_NOTE = 'upload_video_note'
29 changes: 7 additions & 22 deletions telegram/inputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

DEFAULT_MIME_TYPE = 'application/octet-stream'
USER_AGENT = 'Python Telegram Bot (https://github.com/python-telegram-bot/python-telegram-bot)'
FILE_TYPES = ('audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certificate')
FILE_TYPES = ('audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certificate',
'video_note')


class InputFile(object):
Expand All @@ -45,27 +46,11 @@ def __init__(self, data):
self.data = data
self.boundary = choose_boundary()

if 'audio' in data:
self.input_name = 'audio'
self.input_file = data.pop('audio')
elif 'document' in data:
self.input_name = 'document'
self.input_file = data.pop('document')
elif 'photo' in data:
self.input_name = 'photo'
self.input_file = data.pop('photo')
elif 'sticker' in data:
self.input_name = 'sticker'
self.input_file = data.pop('sticker')
elif 'video' in data:
self.input_name = 'video'
self.input_file = data.pop('video')
elif 'voice' in data:
self.input_name = 'voice'
self.input_file = data.pop('voice')
elif 'certificate' in data:
self.input_name = 'certificate'
self.input_file = data.pop('certificate')
for t in FILE_TYPES:
if t in data:
self.input_name = t
self.input_file = data.pop(t)
break
else:
raise TelegramError('Unknown inputfile type')

Expand Down
24 changes: 24 additions & 0 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject,
User, Video, Voice, Venue, MessageEntity, Game)
from telegram.utils.helpers import escape_html, escape_markdown
from telegram.videonote import VideoNote


class Message(TelegramObject):
Expand All @@ -51,6 +52,8 @@ class Message(TelegramObject):
sticker (:class:`telegram.Sticker`):
video (:class:`telegram.Video`):
voice (:class:`telegram.Voice`):
video_note (:class:`telegram.VideoNote`): Message is a video note, information about the
video message
caption (str):
contact (:class:`telegram.Contact`):
location (:class:`telegram.Location`):
Expand Down Expand Up @@ -91,6 +94,7 @@ class Message(TelegramObject):
sticker (Optional[:class:`telegram.Sticker`]):
video (Optional[:class:`telegram.Video`]):
voice (Optional[:class:`telegram.Voice`]):
video_note (Optional[:class:`telegram.VideoNote`]):
caption (Optional[str]):
contact (Optional[:class:`telegram.Contact`]):
location (Optional[:class:`telegram.Location`]):
Expand Down Expand Up @@ -142,6 +146,7 @@ def __init__(self,
pinned_message=None,
forward_from_message_id=None,
bot=None,
video_note=None,
**kwargs):
# Required
self.message_id = int(message_id)
Expand All @@ -163,6 +168,7 @@ def __init__(self,
self.sticker = sticker
self.video = video
self.voice = voice
self.video_note = video_note
self.caption = caption
self.contact = contact
self.location = location
Expand Down Expand Up @@ -220,6 +226,7 @@ def de_json(data, bot):
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
data['video'] = Video.de_json(data.get('video'), bot)
data['voice'] = Voice.de_json(data.get('voice'), bot)
data['video_note'] = VideoNote.de_json(data.get('video_note'), bot)
data['contact'] = Contact.de_json(data.get('contact'), bot)
data['location'] = Location.de_json(data.get('location'), bot)
data['venue'] = Venue.de_json(data.get('venue'), bot)
Expand Down Expand Up @@ -408,6 +415,23 @@ def reply_video(self, *args, **kwargs):
self._quote(kwargs)
return self.bot.sendVideo(self.chat_id, *args, **kwargs)

def reply_video_note(self, *args, **kwargs):
"""
Shortcut for ``bot.send_video_note(update.message.chat_id, *args, **kwargs)``

Keyword Args:
quote (Optional[bool]): If set to ``True``, the video is sent as an actual reply to
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

"""

self._quote(kwargs)
return self.bot.send_video_note(self.chat_id, *args, **kwargs)

def reply_voice(self, *args, **kwargs):
"""
Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``
Expand Down
63 changes: 63 additions & 0 deletions telegram/videonote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram VideoNote."""

from telegram import PhotoSize, TelegramObject


class VideoNote(TelegramObject):
"""This object represents a Telegram VideoNote.

Attributes:
file_id (str): Unique identifier for this file
length (int): Video width and height as defined by sender
duration (int): Duration of the video in seconds as defined by sender
thumb (Optional[:class:`telegram.PhotoSize`]): Video thumbnail
file_size (Optional[int]): File size
"""

def __init__(self, file_id, length, duration, thumb=None, file_size=None, **kwargs):
# Required
self.file_id = str(file_id)
self.length = int(length)
self.duration = int(duration)
# Optionals
self.thumb = thumb
self.file_size = file_size

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):

Returns:
telegram.VideoNote:
"""
if not data:
return None

data = super(VideoNote, VideoNote).de_json(data, bot)

data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)

return VideoNote(**data)
Loading