mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Adding sendPhoto method
This commit is contained in:
parent
8fb2bf58fc
commit
f7a15306a8
5 changed files with 32 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -22,6 +22,7 @@ var/
|
|||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
.env
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
|
|
|
@ -81,6 +81,7 @@ class Bot(object):
|
|||
|
||||
data = {'chat_id': chat_id,
|
||||
'photo': photo}
|
||||
|
||||
if caption:
|
||||
data['caption'] = caption
|
||||
if reply_to_message_id:
|
||||
|
@ -143,13 +144,25 @@ class Bot(object):
|
|||
data=None):
|
||||
|
||||
if method == 'POST':
|
||||
try:
|
||||
return requests.post(
|
||||
url,
|
||||
data=data
|
||||
)
|
||||
except requests.RequestException as e:
|
||||
pass
|
||||
if data.has_key('photo'):
|
||||
try:
|
||||
photo = data.pop('photo')
|
||||
|
||||
return requests.post(
|
||||
url,
|
||||
data=data,
|
||||
files={'photo': photo}
|
||||
)
|
||||
except requests.RequestException as e:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
return requests.post(
|
||||
url,
|
||||
data=data
|
||||
)
|
||||
except requests.RequestException as e:
|
||||
pass
|
||||
if method == 'GET':
|
||||
try:
|
||||
return requests.get(url)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
class InputFile(object):
|
||||
pass
|
BIN
tests/telegram.png
Normal file
BIN
tests/telegram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -44,7 +44,9 @@ class BotTest(unittest.TestCase):
|
|||
self.assertEqual(u'Oi', message.text)
|
||||
self.assertEqual(u'leandrotoledo', message.forward_from.username)
|
||||
|
||||
# def testSendPhoto(self):
|
||||
# '''Test the telegram.Bot sendPhoto method'''
|
||||
# print 'Testing sendPhoto'
|
||||
# message = self._bot.sendPhoto()
|
||||
def testSendPhoto(self):
|
||||
'''Test the telegram.Bot sendPhoto method'''
|
||||
print 'Testing sendPhoto'
|
||||
message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'),
|
||||
chat_id=12173560)
|
||||
#self.assertEqual(u'')
|
||||
|
|
Loading…
Reference in a new issue