Skip to content

Commit b39b624

Browse files
committed
Updating README and minor fixes
1 parent f79c47b commit b39b624

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

README.rst

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ View the last release API documentation at: https://core.telegram.org/bots/api
5151
API
5252
---
5353

54-
The API is exposed via the ``telegram.Bot`` class::
54+
The API is exposed via the ``telegram.Bot`` class.
55+
56+
To generate an Access Token you have to talk to `BotFather https://telegram.me/botfather`_ and follow a few simple steps (described `here https://core.telegram.org/bots#botfather`_).
57+
58+
For full details see the `Bots: An introduction for developers <https://core.telegram.org/bots>`_.
59+
60+
To create an instance of the ``telegram.Bot``::
5561

5662
>>> import telegram
5763
>>> bot = telegram.Bot(token='token')
@@ -62,3 +68,46 @@ To see if your credentials are successful::
6268
{"first_name": "Toledo's Palace Bot", "username": "ToledosPalaceBot"}
6369

6470
**NOTE**: much more than the small sample given here will print
71+
72+
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use ``telegram.me/<bot_username>`` links or username search to find your bot.
73+
74+
To fetch text messages sent to your Bot::
75+
76+
>>> updates = bot.getUpdates()
77+
>>> print [u.message.text for u in updates]
78+
79+
To fetch images sent to your Bot::
80+
81+
>>> updates = bot.getUpdates()
82+
>>> print [u.message.photo for u in updates if u.message.photo]
83+
84+
To post a text message (you'll always need chat_id to reply users)::
85+
86+
>>> chat_id = bot.getUpdates()[-1].message.chat_id
87+
>>> bot.sendMessage(chat_id=chat_id, text=u"I'm sorry Dave I'm afraid I can't do that.")
88+
89+
To post a audio file (you'll always need chat_id to reply users)::
90+
91+
>>> chat_id = bot.getUpdates()[-1].message.chat_id
92+
>>> bot.sendAudio(chat_id=chat_id, audio=open('tests/telegram.ogg', 'rb'))
93+
94+
To tell the user that something is happening on bot's side::
95+
96+
>>> chat_id = bot.getUpdates()[-1].message.chat_id
97+
>>> bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
98+
99+
There are many more API methods, to read the full API documentation::
100+
101+
$ pydoc telegram.Bot
102+
103+
----
104+
TODO
105+
----
106+
107+
Patches and bug reports are `welcome <https://github.com/leandrotoledo/python-telegram-bot/issues/new>`_, just please keep the style consistent with the original source.
108+
109+
Add more example scripts.
110+
111+
Add `custom keyboards <https://core.telegram.org/bots#keyboards>`_ methods.
112+
113+
Add commands handler.

telegram/bot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def username(self):
5050
return self._username
5151

5252
def clearCredentials(self):
53+
"""Clear any credentials for this instance.
54+
"""
5355
self.__auth = False
5456

5557
def getMe(self):
@@ -439,9 +441,6 @@ def sendChatAction(self,
439441
- ChatAction.UPLOAD_AUDIO or upload_audio for audio files,
440442
- ChatAction.UPLOAD_DOCUMENT for general files,
441443
- ChatAction.FIND_LOCATION for location data.
442-
443-
Returns:
444-
?
445444
"""
446445

447446
url = '%s/sendChatAction' % (self.base_url)
@@ -539,7 +538,6 @@ def setWebhook(self):
539538
if not self.__auth:
540539
raise TelegramError({'message': "API must be authenticated."})
541540

542-
543541
def _requestUrl(self,
544542
url,
545543
method,

tests/test_bot.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ def testSendLocation(self):
112112
def testSendChatAction(self):
113113
'''Test the telegram.Bot sendChatAction method'''
114114
print 'Testing sendChatAction - ChatAction.TYPING'
115-
message = self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
116-
chat_id=12173560)
117-
# TODO: return json
115+
self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
116+
chat_id=12173560)
118117

119118
def testGetUserProfilePhotos(self):
120119
'''Test the telegram.Bot getUserProfilePhotos method'''

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy