diff --git a/telegram/bot.py b/telegram/bot.py index 97f83c6a4..12e333c79 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -602,10 +602,10 @@ class Bot(object): """ if method == 'POST': - if 'audio' in data and isinstance(data['audio'], file) or \ - 'document' in data and isinstance(data['document'], file) or \ - 'photo' in data and isinstance(data['photo'], file) or \ - 'video' in data and isinstance(data['video'], file): + if 'audio' in data and (isinstance(data['audio'], file) or 'http' in data['audio']) or \ + 'document' in data and (isinstance(data['document'], file) or 'http' in data['document']) or \ + 'photo' in data and (isinstance(data['photo'], file) or 'http' in data['photo']) or \ + 'video' in data and (isinstance(data['video'], file) or 'http' in data['video']): try: data = InputFile(data) request = urllib2.Request( diff --git a/telegram/inputfile.py b/telegram/inputfile.py index 2ada2f41a..f33045dd8 100644 --- a/telegram/inputfile.py +++ b/telegram/inputfile.py @@ -4,6 +4,7 @@ import mimetools import mimetypes import os +import urllib2 class InputFile(object): @@ -12,21 +13,26 @@ class InputFile(object): self.data = data self.boundary = mimetools.choose_boundary() - if 'audio' in data and isinstance(data['audio'], file): + if 'audio' in data: self.input_name = 'audio' self.input_file = data.pop('audio') - if 'document' in data and isinstance(data['document'], file): + if 'document' in data: self.input_name = 'document' self.input_file = data.pop('document') - if 'photo' in data and isinstance(data['photo'], file): + if 'photo' in data: self.input_name = 'photo' self.input_file = data.pop('photo') - if 'video' in data and isinstance(data['video'], file): + if 'video' in data: self.input_name = 'video' self.input_file = data.pop('video') - self.input_file_content = self.input_file.read() - self.filename = os.path.basename(self.input_file.name) + if isinstance(self.input_file, file): + self.filename = os.path.basename(self.input_file.name) + self.input_file_content = self.input_file.read() + if 'http' in self.input_file: + self.filename = os.path.basename(self.input_file) + self.input_file_content = urllib2.urlopen(self.input_file).read() + self.mimetype = mimetypes.guess_type(self.filename)[0] or \ 'application/octet-stream' diff --git a/tests/test_bot.py b/tests/test_bot.py index afb279f35..794e98ac4 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -33,7 +33,7 @@ class BotTest(unittest.TestCase): '''Test the telegram.Bot getUpdates method''' print 'Testing getUpdates' updates = self._bot.getUpdates() - self.assertEqual(129566577, updates[0].update_id) + self.assertEqual(129566590, updates[0].update_id) def testForwardMessage(self): '''Test the telegram.Bot forwardMessage method'''