Files
snowy-yang 0515c6e4c0 refactor!: Bot 门面接管启动,移除 main/run_loop 与控制台脚本入口
bot.run() 同步启动、bot.start() 嵌入外部 asyncio 应用;
bot.call_api 通用 REST、bot.api 类型化 API 面、bot.services 自定义组件注入;
services 登记扩到 8 项(含 Bot 自身,可标注注入)。
2026-10-03 19:12:06 +08:00

34 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Webhook 接入最小示例:HTTP 回调收群 @消息并回复。
运行前提:
1. 项目根目录 .env 配好 APPID/APPSECRET,并设 CONNECTER=webhook;
2. intents.toml 订阅 GROUP_AND_C2C_EVENT 分组(仓库默认已开启);
3. 部署在公网 HTTPS 环境(平台仅支持 80/443/8080/8443 端口,
本地调试可内网穿透),回调地址填
https://<你的域名>:<端口><WEBHOOK_PATH>;
4. 开放平台保存回调配置时会先发 op=13 验证请求,SDK 自动完成签名应答。
运行:uv run python examples/webhook_bot/main.py
"""
from qqbotsdk import Bot
from qqbotsdk.api import BotApi
from qqbotsdk.payloads import GroupAtMessage
bot = Bot()
@bot.on("GROUP_AT_MESSAGE_CREATE")
async def on_group_message(msg: GroupAtMessage, api: BotApi) -> None:
if not (msg.group_openid and msg.id):
return
await api.post_group_message(
msg.group_openid,
content=f"收到:{msg.content}",
msg_id=msg.id,
)
if __name__ == "__main__":
bot.run()