Skip to content

Commit f5976fc

Browse files
committed
Adding documentation
1 parent ddfb22c commit f5976fc

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

telegram/bot.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# encoding: utf-8
23

34
"""A library that provides a Python interface to the Telegram Bots API"""
45

@@ -19,7 +20,12 @@ def __init__(self,
1920
self.base_url = base_url + token
2021

2122
def getMe(self):
23+
"""A simple method for testing your bot's auth token.
2224
25+
Returns:
26+
A telegram.User instance representing that bot if the
27+
credentials are valid, None otherwise.
28+
"""
2329
url = '%s/getMe' % (self.base_url)
2430

2531
json_data = self._requestUrl(url, 'GET')
@@ -33,6 +39,25 @@ def sendMessage(self,
3339
disable_web_page_preview=None,
3440
reply_to_message_id=None,
3541
reply_markup=None):
42+
"""Use this method to send text messages.
43+
44+
Args:
45+
chat_id:
46+
Unique identifier for the message recipient — telegram.User or
47+
telegram.GroupChat id.
48+
text:
49+
Text of the message to be sent.
50+
disable_web_page_preview:
51+
Disables link previews for links in this message. [Optional]
52+
reply_to_message_id:
53+
If the message is a reply, ID of the original message. [Optional]
54+
reply_markup:
55+
Additional interface options. A JSON-serialized object for a custom
56+
reply keyboard, instructions to hide keyboard or to force a reply
57+
from the user. [Optional]
58+
Returns:
59+
A telegram.Message instance representing the message posted.
60+
"""
3661

3762
url = '%s/sendMessage' % (self.base_url)
3863

@@ -54,6 +79,19 @@ def forwardMessage(self,
5479
chat_id,
5580
from_chat_id,
5681
message_id):
82+
"""Use this method to forward messages of any kind.
83+
84+
Args:
85+
chat_id:
86+
Unique identifier for the message recipient — User or GroupChat id.
87+
from_chat_id:
88+
Unique identifier for the chat where the original message was sent
89+
— User or GroupChat id.
90+
message_id:
91+
Unique message identifier.
92+
Returns:
93+
A telegram.Message instance representing the message forwarded.
94+
"""
5795

5896
url = '%s/forwardMessage' % (self.base_url)
5997

@@ -76,6 +114,27 @@ def sendPhoto(self,
76114
caption=None,
77115
reply_to_message_id=None,
78116
reply_markup=None):
117+
"""Use this method to send photos.
118+
119+
Args:
120+
chat_id:
121+
Unique identifier for the message recipient — User or GroupChat id.
122+
photo:
123+
Photo to send. You can either pass a file_id as String to resend a
124+
photo that is already on the Telegram servers, or upload a new
125+
photo using multipart/form-data.
126+
caption:
127+
Photo caption (may also be used when resending photos by file_id).
128+
[Optional]
129+
reply_to_message_id:
130+
If the message is a reply, ID of the original message. [Optional]
131+
reply_markup:
132+
Additional interface options. A JSON-serialized object for a custom
133+
reply keyboard, instructions to hide keyboard or to force a reply
134+
from the user. [Optional]
135+
Returns:
136+
A telegram.Message instance representing the message posted.
137+
"""
79138

80139
url = '%s/sendPhoto' % (self.base_url)
81140

@@ -142,9 +201,21 @@ def _requestUrl(self,
142201
url,
143202
method,
144203
data=None):
204+
"""Request an URL.
205+
206+
Args:
207+
url:
208+
The web location we want to retrieve.
209+
method:
210+
Either POST or GET.
211+
data:
212+
A dict of (str, unicode) key/value pairs.
213+
Returns:
214+
A JSON object.
215+
"""
145216

146217
if method == 'POST':
147-
if data.has_key('photo') and isinstance(data['photo'], file):
218+
if 'photo' in data and isinstance(data['photo'], file):
148219
try:
149220
photo = data.pop('photo')
150221

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