mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 14:35:00 +01:00
Adding Sticker and its tests
This commit is contained in:
parent
a33abadcb8
commit
635fae04e6
6 changed files with 64 additions and 3 deletions
|
@ -14,7 +14,7 @@ from groupchat import GroupChat
|
|||
from photosize import PhotoSize
|
||||
from audio import Audio
|
||||
from document import Document
|
||||
# from sticket import Sticker
|
||||
from sticker import Sticker
|
||||
# from video import Video
|
||||
# from contact import Contact
|
||||
# from location import Location
|
||||
|
|
|
@ -234,9 +234,27 @@ class Bot(object):
|
|||
|
||||
return Message.newFromJsonDict(data)
|
||||
|
||||
def sendSticker(self):
|
||||
def sendSticker(self,
|
||||
chat_id,
|
||||
sticker,
|
||||
reply_to_message_id=None,
|
||||
reply_markup=None):
|
||||
|
||||
url = '%s/sendSticker' % (self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'sticker': sticker}
|
||||
|
||||
if reply_to_message_id:
|
||||
data['reply_to_message_id'] = reply_to_message_id
|
||||
if reply_markup:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
json_data = self._requestUrl(url, 'POST', data=data)
|
||||
data = self._parseAndCheckTelegram(json_data.content)
|
||||
|
||||
return Message.newFromJsonDict(data)
|
||||
|
||||
def sendVideo(self):
|
||||
url = '%s/sendVideo' % (self.base_url)
|
||||
|
||||
|
|
|
@ -79,6 +79,12 @@ class Message(object):
|
|||
else:
|
||||
photo = None
|
||||
|
||||
if 'sticker' in data:
|
||||
from telegram import Sticker
|
||||
sticker = Sticker.newFromJsonDict(data['sticker'])
|
||||
else:
|
||||
sticker = None
|
||||
|
||||
if 'new_chat_participant' in data:
|
||||
from telegram import User
|
||||
new_chat_participant = User.newFromJsonDict(
|
||||
|
@ -106,7 +112,7 @@ class Message(object):
|
|||
audio=audio,
|
||||
document=document,
|
||||
photo=photo,
|
||||
sticker=data.get('sticker', None),
|
||||
sticker=sticker,
|
||||
video=data.get('video', None),
|
||||
contact=data.get('contact', None),
|
||||
location=data.get('location', None),
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
class Sticker(object):
|
||||
def __init__(self, **kwargs):
|
||||
param_defaults = {
|
||||
'file_id': None,
|
||||
'width': None,
|
||||
'height': None,
|
||||
'thumb': None,
|
||||
'file_size': None
|
||||
}
|
||||
|
||||
for (param, default) in param_defaults.iteritems():
|
||||
setattr(self, param, kwargs.get(param, default))
|
||||
|
||||
@staticmethod
|
||||
def newFromJsonDict(data):
|
||||
if 'thumb' in data:
|
||||
from telegram import PhotoSize
|
||||
thumb = PhotoSize.newFromJsonDict(data['thumb'])
|
||||
else:
|
||||
thumb = None
|
||||
|
||||
return Sticker(file_id=data.get('file_id', None),
|
||||
width=data.get('width', None),
|
||||
height=data.get('height', None),
|
||||
thumb=thumb,
|
||||
file_size=data.get('file_size', None))
|
|
@ -5,6 +5,7 @@ class User(object):
|
|||
def __init__(self, **kwargs):
|
||||
param_defaults = {
|
||||
'id': None,
|
||||
# 'chat_id' TODO
|
||||
'first_name': None,
|
||||
'last_name': None,
|
||||
'username': None
|
||||
|
|
|
@ -85,3 +85,10 @@ class BotTest(unittest.TestCase):
|
|||
message = self._bot.sendDocument(document=str('BQADAQADHAADNTwtBxZxUGKyxYbYAg'),
|
||||
chat_id=12173560)
|
||||
self.assertEqual(u'BQADAQADHAADNTwtBxZxUGKyxYbYAg', message.document.file_id)
|
||||
|
||||
def testSendSticker(self):
|
||||
'''Test the telegram.Bot sendSticker method'''
|
||||
print 'Testing sendSticket'
|
||||
message = self._bot.sendSticker(sticker=str('BQADAQADHAADyIsGAAFZfq1bphjqlgI'),
|
||||
chat_id=12173560)
|
||||
self.assertEqual(39518, message.sticker.file_size)
|
||||
|
|
Loading…
Reference in a new issue