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

Method getMe done.

This commit is contained in:
eternnoir 2015-06-26 15:46:02 +08:00
parent b4691a2a3a
commit ba2e1662cd
3 changed files with 32 additions and 2 deletions

View File

@ -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,

View File

@ -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

9
tests/test_types.py Normal file
View File

@ -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