telegram的bot api和mtproto聊天potocols上的抽象层
twx的Python项目详细描述
contributions: | Please join https://github.com/datamachine/twx |
---|---|
issues: | Please use https://github.com/datamachine/twx/issues |
Python version supported: | |
3.4 |
TWX是用于Telegram bot API的python接口它支持 进行同步和异步调用并转换响应 变成一个可用的本地python对象
对mtproto api的支持正在进行中,但现在被认为是pre-alpha。
安装
对于稳定:
pip install twx
对于dev:
pip install -ihttps://testpypi.python.org/pypi twx
快速启动
from twx.botapi import TelegramBot, ReplyKeyboardMarkup """ Setup the bot """ bot = TelegramBot('<API TOKEN>') bot.update_bot_info().wait() print(bot.username) """ Send a message to a user """ user_id = int(<someuserid>) result = bot.send_message(user_id, 'test message body').wait() print(result) """ Get updates sent to the bot """ updates = bot.get_updates().wait() for update in updates: print(update) """ Use a custom keyboard """ keyboard = [ ['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0'] ] reply_markup = ReplyKeyboardMarkup.create(keyboard) bot.send_message(user_id, 'please enter a number', reply_markup=reply_markup).wait()