Closed MingxuanGame closed 1 year ago
此 PR 引入了后端(Backend)代替了 WebHook 服务器的概念。后端是对 WebHook 服务器的抽象包装。
目前 Herta SDK 内置了 AIOHTTP 和 FastAPI 后端,默认使用 AIOHTTP 后端.
FastAPI 后端需要安装扩展 fastapi
fastapi
pip install herta-villa-sdk[fastapi]
run 函数提供了一个参数 backend_class,用来传入后端类
run
backend_class
例如: 替换后端为 FastAPI
from __future__ import annotations from hertavilla import VillaBot, run from hertavilla.server.fastapi import FastAPIBackend bot = VillaBot( "bot_id", "bot_secret", "/", ) -run(bot) +run(bot, backend_class=FastAPIBackend)
运行时可以通过 get_backend() 获取后端,运行前(run 之前)通过 init_backend 设置后端
get_backend()
init_backend
Warning 使用 init_backend 设置后端后,run 的参数 backend_class 就会失效
Warning
使用 init_backend 设置后端后,run 的参数 backend_class 就会失效
详见 hertavilla.server
hertavilla.server
简介
此 PR 引入了后端(Backend)代替了 WebHook 服务器的概念。后端是对 WebHook 服务器的抽象包装。
目前 Herta SDK 内置了 AIOHTTP 和 FastAPI 后端,默认使用 AIOHTTP 后端.
FastAPI 后端需要安装扩展
fastapi
设置后端
run
函数提供了一个参数backend_class
,用来传入后端类例如: 替换后端为 FastAPI
运行时获取后端和运行前修改后端
运行时可以通过
get_backend()
获取后端,运行前(run
之前)通过init_backend
设置后端其他
详见
hertavilla.server