From 67aaed4f2058c3e67b5232e611f80427e53b8256 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Fri, 26 Jun 2015 22:35:52 +0800 Subject: [PATCH] Forward message method done. --- README.md | 2 +- telebot/__init__.py | 7 +++++++ telebot/apihelper.py | 18 +++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5a24107..8c972c7 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ while True: - [x] getMe - [x] sendMessage -- [ ] forwardMessage +- [x] forwardMessage - [ ] sendPhoto - [ ] sendAudio - [ ] sendDocument diff --git a/telebot/__init__.py b/telebot/__init__.py index dde1b9f..cb2c141 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -111,4 +111,11 @@ class TeleBot: reply_markup) def forward_message(self, chat_id, from_chat_id, message_id): + """ + + :param chat_id: which chat to forward + :param from_chat_id: which chat message from + :param message_id: message id + :return: + """ return apihelper.forward_message(self.token, chat_id, from_chat_id, message_id) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index effdfc4..93720f9 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -3,13 +3,15 @@ import telebot import requests + def get_me(token): - api_url=telebot.API_URL + api_url = telebot.API_URL method_url = r'getMe' - request_url = api_url+'bot'+token+'/'+method_url + request_url = api_url + 'bot' + token + '/' + method_url req = requests.get(request_url) return req.json() + def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None): """ Use this method to send text messages. On success, the sent Message is returned. @@ -34,17 +36,19 @@ def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_m req = requests.get(request_url, params=payload) return req.json() + def get_updates(token): api_url = telebot.API_URL method_url = r'getUpdates' - request_url = api_url+'bot'+token+'/'+method_url + request_url = api_url + 'bot' + token + '/' + method_url req = requests.get(request_url) return req.json() -def forward_message(token,chat_id,from_chat_id,message_id): + +def forward_message(token, chat_id, from_chat_id, message_id): api_url = telebot.API_URL method_url = r'forwardMessage' - request_url = api_url+'bot'+token+'/'+method_url - payload = {'chat_id':chat_id,'from_chat_id':from_chat_id,'message_id':message_id} - req = requests.get(request_url,params=payload) + request_url = api_url + 'bot' + token + '/' + method_url + payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id} + req = requests.get(request_url, params=payload) return req.json()