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

send file methods done.

This commit is contained in:
eternnoir 2015-06-27 01:53:07 +08:00
parent 1c4c75ee8f
commit 70b63fddc1
3 changed files with 60 additions and 6 deletions

View File

@ -65,11 +65,11 @@ while True:
- [x] getMe - [x] getMe
- [x] sendMessage - [x] sendMessage
- [x] forwardMessage - [x] forwardMessage
- [ ] sendPhoto - [x] sendPhoto
- [ ] sendAudio - [x] sendAudio
- [ ] sendDocument - [x] sendDocument
- [ ] sendSticker - [x] sendSticker
- [ ] sendVideo - [x] sendVideo
- [ ] sendLocation - [ ] sendLocation
- [ ] sendChatAction - [ ] sendChatAction
- [ ] getUserProfilePhotos - [ ] getUserProfilePhotos

View File

@ -112,10 +112,25 @@ class TeleBot:
def forward_message(self, chat_id, from_chat_id, message_id): def forward_message(self, chat_id, from_chat_id, message_id):
""" """
Use this method to forward messages of any kind.
:param chat_id: which chat to forward :param chat_id: which chat to forward
:param from_chat_id: which chat message from :param from_chat_id: which chat message from
:param message_id: message id :param message_id: message id
:return: :return:
""" """
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):
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):
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):
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):
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):
return apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup)

View File

@ -52,3 +52,42 @@ def forward_message(token, chat_id, from_chat_id, message_id):
payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id} payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id}
req = requests.get(request_url, params=payload) req = requests.get(request_url, params=payload)
return req.json() return req.json()
def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None):
api_url = telebot.API_URL
method_url = r'sendPhoto'
request_url = api_url + 'bot' + token + '/' + method_url
payload = {'chat_id': chat_id}
files = {'photo': photo}
if caption:
payload['caption'] = caption
if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id
if reply_markup:
payload['reply_markup'] = reply_markup
req = requests.post(request_url, params=payload, files=files)
return req.json()
def send_data(token, chat_id, data, type, reply_to_message_id=None, reply_markup=None):
api_url = telebot.API_URL
method_url = get_method_by_type(type)
request_url = api_url + 'bot' + token + '/' + method_url
payload = {'chat_id': chat_id}
files = {type: data}
if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id
if reply_markup:
payload['reply_markup'] = reply_markup
req = requests.post(request_url, params=payload, files=files)
return req.json()
def get_method_by_type(type):
if type == 'audio':
return 'sendAudio'
if type == 'document':
return 'sendDocument'
if type == 'sticker':
return 'sendSticker'
if type == 'video':
return 'sendVideo'