Skip to main content

Python asyncio 之上的一个简单的电报机器人框架

项目描述

Baymax,一个基于 Python asyncio 的简单电报机器人框架

工作正在进行中

要求

  • Python 3.7 或更高版本

安装

pip install baymax

基本使用示例

from baymax.bot import Bot

bot = Bot('token')

@bot.on('/start')
async def start_handler(message):
    await bot.reply(message, 'Welcome!')

bot.run()

中间件示例

@bot.middleware
async def message_logging_middleware(raw_update):
    bot.logger.info('New update received: %s', raw_update['update_id'])

注意:所有中间件函数现在都应该是协程,即使它们没有异步操作。

回复键盘标记示例

from baymax.markups import KeyboardButton, ReplyKeyboardMarkup

@bot.on('/rate')
async def rate_handler(message):
    await bot.reply(message, 'Rate me', reply_markup=ReplyKeyboardMarkup(
        [
            [
                KeyboardButton('⭐️'),
                KeyboardButton('⭐️⭐️'),
                KeyboardButton('⭐️⭐️⭐️')
            ]
        ], resize_keyboard=True, one_time_keyboard=True))

注意:回复标记 API / 对象将发生变化,它们现在远非如此。

运行测试

git clone git@github.com:dmrz/baymax.git
pip install -e .
pip install -r requirements-test.txt
pytest

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置分布

baymax-0.0.5-py3-none-any.whl (9.7 kB 查看哈希

已上传 py3