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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ docs/_build/

# PyBuilder
target/
.idea/
.gitignore
23 changes: 19 additions & 4 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,24 @@ def setWebhook(self, webhook_url=""):

return True

def _isFileRequest(self,
data=None):
"""Check if the request is a file request
Args:
data:
A dict od (str, unicode) key/value pairs

Returns:
bool
"""
if data:
file_types = ['audio', 'document', 'photo', 'video']
file_type = [i for i in data.keys() if i in file_types]
if file_type:
file_content = data[file_type[0]]
return isinstance(file_content, file) or str(file_content).startswith('http')
return False

def _requestUrl(self,
url,
method,
Expand All @@ -602,10 +620,7 @@ def _requestUrl(self,
"""

if method == 'POST':
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']):
if self._isFileRequest(data):
try:
data = InputFile(data)
request = urllib2.Request(
Expand Down