1
1
#!/usr/bin/env python
2
+ # encoding: utf-8
2
3
3
4
"""A library that provides a Python interface to the Telegram Bots API"""
4
5
@@ -19,7 +20,12 @@ def __init__(self,
19
20
self .base_url = base_url + token
20
21
21
22
def getMe (self ):
23
+ """A simple method for testing your bot's auth token.
22
24
25
+ Returns:
26
+ A telegram.User instance representing that bot if the
27
+ credentials are valid, None otherwise.
28
+ """
23
29
url = '%s/getMe' % (self .base_url )
24
30
25
31
json_data = self ._requestUrl (url , 'GET' )
@@ -33,6 +39,25 @@ def sendMessage(self,
33
39
disable_web_page_preview = None ,
34
40
reply_to_message_id = None ,
35
41
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
+ """
36
61
37
62
url = '%s/sendMessage' % (self .base_url )
38
63
@@ -54,6 +79,19 @@ def forwardMessage(self,
54
79
chat_id ,
55
80
from_chat_id ,
56
81
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
+ """
57
95
58
96
url = '%s/forwardMessage' % (self .base_url )
59
97
@@ -76,6 +114,27 @@ def sendPhoto(self,
76
114
caption = None ,
77
115
reply_to_message_id = None ,
78
116
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
+ """
79
138
80
139
url = '%s/sendPhoto' % (self .base_url )
81
140
@@ -142,9 +201,21 @@ def _requestUrl(self,
142
201
url ,
143
202
method ,
144
203
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
+ """
145
216
146
217
if method == 'POST' :
147
- if data . has_key ( 'photo' ) and isinstance (data ['photo' ], file ):
218
+ if 'photo' in data and isinstance (data ['photo' ], file ):
148
219
try :
149
220
photo = data .pop ('photo' )
150
221
0 commit comments