diff --git a/telebot/__init__.py b/telebot/__init__.py index db6bcf5..e66a6f1 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import apihelper +import json +import types """ Module : telebot @@ -31,8 +33,11 @@ class TeleBot: self.token = token def get_me(self): - # TODO - return None + result = apihelper.get_me(self.token) + if result['ok'] is not True: + raise Exception('getMe Error.'+json.dumps(result)) + u = types.User.de_json(json.dumps(result['result'])) + return u def send_message(self, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None): return apihelper.send_message(self.token, chat_id, text, disable_web_page_preview, reply_to_message_id, diff --git a/telebot/apihelper.py b/telebot/apihelper.py index ee442d9..25b67b4 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -3,8 +3,24 @@ import telebot import requests +def get_me(token): + apiurl=telebot.API_URL + method_url = r'getMe' + request_url = apiurl+'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. + :param token: + :param chat_id: + :param text: + :param disable_web_page_preview: + :param reply_to_message_id: + :param reply_markup: + :return: + """ api_url = telebot.API_URL method_url = r'sendMessage' request_url = api_url + 'bot' + token + '/' + method_url diff --git a/tests/test_types.py b/tests/test_types.py new file mode 100644 index 0000000..dff4007 --- /dev/null +++ b/tests/test_types.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +import sys +sys.path.append('../') +from telebot import types + +def test_json_user(): + jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","username":"rdss_bot"}' + u = types.User.de_json(jsonstring) + assert u.id is not 101176298 \ No newline at end of file