@@ -142,28 +142,38 @@ def decorator(self, *args, **kwargs):
142142 decorator
143143 """
144144 url , data = func (self , * args , ** kwargs )
145+ return Bot ._post_message (url , data , kwargs )
146+ return decorator
145147
146- if not data .get ('chat_id' ):
147- raise TelegramError ('Invalid chat_id' )
148+ @staticmethod
149+ def _post_message (url , data , kwargs , timeout = None , network_delay = 2. ):
150+ """Posts a message to the telegram servers.
148151
149- if kwargs .get ('reply_to_message_id' ):
150- reply_to_message_id = kwargs .get ('reply_to_message_id' )
151- data ['reply_to_message_id' ] = reply_to_message_id
152+ Returns:
153+ telegram.Message
152154
153- if kwargs .get ('reply_markup' ):
154- reply_markup = kwargs .get ('reply_markup' )
155- if isinstance (reply_markup , ReplyMarkup ):
156- data ['reply_markup' ] = reply_markup .to_json ()
157- else :
158- data ['reply_markup' ] = reply_markup
155+ """
156+ if not data .get ('chat_id' ):
157+ raise TelegramError ('Invalid chat_id' )
159158
160- result = request .post (url , data )
159+ if kwargs .get ('reply_to_message_id' ):
160+ reply_to_message_id = kwargs .get ('reply_to_message_id' )
161+ data ['reply_to_message_id' ] = reply_to_message_id
161162
162- if result is True :
163- return result
163+ if kwargs .get ('reply_markup' ):
164+ reply_markup = kwargs .get ('reply_markup' )
165+ if isinstance (reply_markup , ReplyMarkup ):
166+ data ['reply_markup' ] = reply_markup .to_json ()
167+ else :
168+ data ['reply_markup' ] = reply_markup
164169
165- return Message .de_json (result )
166- return decorator
170+ result = request .post (url , data , timeout = timeout ,
171+ network_delay = network_delay )
172+
173+ if result is True :
174+ return result
175+
176+ return Message .de_json (result )
167177
168178 @log
169179 def getMe (self ):
@@ -430,12 +440,12 @@ def sendSticker(self,
430440 return url , data
431441
432442 @log
433- @message
434443 def sendVideo (self ,
435444 chat_id ,
436445 video ,
437446 duration = None ,
438447 caption = None ,
448+ timeout = None ,
439449 ** kwargs ):
440450 """Use this method to send video files, Telegram clients support mp4
441451 videos (other formats may be sent as telegram.Document).
@@ -452,6 +462,9 @@ def sendVideo(self,
452462 caption:
453463 Video caption (may also be used when resending videos by file_id).
454464 [Optional]
465+ timeout:
466+ float. If this value is specified, use it as the definitive timeout
467+ (in seconds) for urlopen() operations. [Optional]
455468 reply_to_message_id:
456469 If the message is a reply, ID of the original message. [Optional]
457470 reply_markup:
@@ -473,7 +486,7 @@ def sendVideo(self,
473486 if caption :
474487 data ['caption' ] = caption
475488
476- return url , data
489+ return self . _post_message ( url , data , kwargs , timeout = timeout )
477490
478491 @log
479492 @message
0 commit comments