1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add some comment

This commit is contained in:
eternnoir 2015-06-27 02:14:45 +08:00
parent 70b63fddc1
commit a62139fafc
2 changed files with 50 additions and 8 deletions

View File

@ -121,16 +121,58 @@ class TeleBot:
return apihelper.forward_message(self.token, chat_id, from_chat_id, message_id) return apihelper.forward_message(self.token, chat_id, from_chat_id, message_id)
def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None): def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send photos.
:param chat_id:
:param photo:
:param caption:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
return apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup) return apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup)
def send_audio(self, chat_id, data, reply_to_message_id=None, reply_markup=None): def send_audio(self, chat_id, data, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send audio files, if you want Telegram clients to display the file as a playable
voice message. For this to work, your audio must be in an .ogg file encoded with OPUS
:param chat_id:
:param data:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
return apihelper.send_data(self.token, chat_id, data, 'audio', reply_to_message_id, reply_markup) return apihelper.send_data(self.token, chat_id, data, 'audio', reply_to_message_id, reply_markup)
def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None): def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send general files.
:param chat_id:
:param data:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
return apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup) return apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup)
def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None): def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send .webp stickers.
:param chat_id:
:param data:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
return apihelper.send_data(self.token, chat_id, data, 'sticker', reply_to_message_id, reply_markup) return apihelper.send_data(self.token, chat_id, data, 'sticker', reply_to_message_id, reply_markup)
def send_video(self, chat_id, data, reply_to_message_id=None, reply_markup=None): def send_video(self, chat_id, data, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send video files, Telegram clients support mp4 videos.
:param chat_id:
:param data:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
return apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup) return apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup)

View File

@ -69,12 +69,12 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re
req = requests.post(request_url, params=payload, files=files) req = requests.post(request_url, params=payload, files=files)
return req.json() return req.json()
def send_data(token, chat_id, data, type, reply_to_message_id=None, reply_markup=None): def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None):
api_url = telebot.API_URL api_url = telebot.API_URL
method_url = get_method_by_type(type) method_url = get_method_by_type(data_type)
request_url = api_url + 'bot' + token + '/' + method_url request_url = api_url + 'bot' + token + '/' + method_url
payload = {'chat_id': chat_id} payload = {'chat_id': chat_id}
files = {type: data} files = {data_type: data}
if reply_to_message_id: if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id payload['reply_to_message_id'] = reply_to_message_id
if reply_markup: if reply_markup:
@ -82,12 +82,12 @@ def send_data(token, chat_id, data, type, reply_to_message_id=None, reply_markup
req = requests.post(request_url, params=payload, files=files) req = requests.post(request_url, params=payload, files=files)
return req.json() return req.json()
def get_method_by_type(type): def get_method_by_type(data_type):
if type == 'audio': if data_type == 'audio':
return 'sendAudio' return 'sendAudio'
if type == 'document': if data_type == 'document':
return 'sendDocument' return 'sendDocument'
if type == 'sticker': if data_type == 'sticker':
return 'sendSticker' return 'sendSticker'
if type == 'video': if data_type == 'video':
return 'sendVideo' return 'sendVideo'