mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Adding sendChatAction, its tests and minor fixes
This commit is contained in:
parent
86c1f68419
commit
c20d6465fc
6 changed files with 49 additions and 3 deletions
|
@ -18,6 +18,7 @@ from sticker import Sticker
|
|||
from video import Video
|
||||
# from contact import Contact
|
||||
from location import Location
|
||||
from chataction import ChatAction
|
||||
# from inputfile import InputFile
|
||||
# from userprofilephotos import UserProfilePhotos
|
||||
# from replykeyboardmarkup import ReplyKeyboardMarkup
|
||||
|
|
|
@ -354,9 +354,37 @@ class Bot(object):
|
|||
|
||||
return Message.newFromJsonDict(data)
|
||||
|
||||
def sendChatAction(self):
|
||||
def sendChatAction(self,
|
||||
chat_id,
|
||||
action):
|
||||
"""Use this method when you need to tell the user that something is
|
||||
happening on the bot's side. The status is set for 5 seconds or less
|
||||
(when a message arrives from your bot, Telegram clients clear its
|
||||
typing status).
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the message recipient — User or GroupChat id.
|
||||
action:
|
||||
Type of action to broadcast. Choose one, depending on what the user
|
||||
is about to receive:
|
||||
- ChatAction.TYPING for text messages,
|
||||
- ChatAction.UPLOAD_PHOTO for photos,
|
||||
- ChatAction.UPLOAD_VIDEO or upload_video for videos,
|
||||
- ChatAction.UPLOAD_AUDIO or upload_audio for audio files,
|
||||
- ChatAction.UPLOAD_DOCUMENT for general files,
|
||||
- ChatAction.FIND_LOCATION for location data.
|
||||
Returns:
|
||||
?
|
||||
"""
|
||||
|
||||
url = '%s/sendChatAction' % (self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'action': action}
|
||||
|
||||
self._requestUrl(url, 'POST', data=data)
|
||||
|
||||
def getUserProfilePhotos(self):
|
||||
url = '%s/getUserProfilePhotos' % (self.base_url)
|
||||
|
||||
|
|
10
telegram/chataction.py
Normal file
10
telegram/chataction.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
class ChatAction(object):
|
||||
TYPING = 'typing'
|
||||
UPLOAD_PHOTO = 'upload_photo'
|
||||
RECORD_VIDEO = 'upload_video'
|
||||
RECORD_AUDIO = 'upload_audio'
|
||||
UPLOAD_DOCUMENT = 'upload_document'
|
||||
FIND_LOCATION = 'find_location'
|
|
@ -14,4 +14,4 @@ class Location(object):
|
|||
@staticmethod
|
||||
def newFromJsonDict(data):
|
||||
return Location(longitude=data.get('longitude', None),
|
||||
latitude=data.get('latitude', None))
|
||||
latitude=data.get('latitude', None))
|
||||
|
|
|
@ -29,7 +29,7 @@ class Message(object):
|
|||
|
||||
for (param, default) in param_defaults.iteritems():
|
||||
setattr(self, param, kwargs.get(param, default))
|
||||
|
||||
|
||||
@property
|
||||
def chat_id(self):
|
||||
return self.chat.id
|
||||
|
|
|
@ -108,3 +108,10 @@ class BotTest(unittest.TestCase):
|
|||
chat_id=12173560)
|
||||
self.assertEqual(-23.558873, message.location.latitude)
|
||||
self.assertEqual(-46.659732, message.location.longitude)
|
||||
|
||||
def testSendChatAction(self):
|
||||
'''Test the telegram.Bot sendChatAction method'''
|
||||
print 'Testing sendChatAction - ChatAction.TYPING'
|
||||
message = self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
|
||||
chat_id=12173560)
|
||||
# TODO: return json
|
||||
|
|
Loading…
Reference in a new issue