如何让插件控制协议适配器的 webhook 返回值 #556
Answered
by
yanyongyu
YangRucheng
asked this question in
问答
-
以下面代码为例(去掉了部分代码),我希望能让插件控制返回值,而不只是固定的 这是因为 微信公众号 支持被动回复消息,需要直接回复 webhook,并且要在5秒内回复。(需要实现超时回复默认的 success)官方文档 我看了 QQ适配器 和 OneBot适配器 都没有这种奇怪的需求。 class Adapter(BaseAdapter):
def setup(self) -> None:
for bot_info in self.wxmp_config.wxmp_bots:
self.setup_http_server(
HTTPServerSetup(
path=URL(f"/wxmp/revice/{bot_info.appid}"),
method="POST",
name=f"WebHook",
handle_func=self._handle_event,
)
)
async def _handle_event(self, request: Request) -> Response:
""" 处理事件推送 """
bot: Bot = self.bots.get(self._get_appid(url.path), None)
if request.content:
payload: dict = self.parse_body(request.content)
self.dispatch_event(bot, payload)
return Response(200, content="success")
else:
return Response(400, content="Invalid request body") |
Beta Was this translation helpful? Give feedback.
Answered by
yanyongyu
Jan 13, 2025
Replies: 1 comment
-
你可以用 ob 的 future store 形式实现回调,超时可以用 asyncio.wait_for 。 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YangRucheng
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你可以用 ob 的 future store 形式实现回调,超时可以用 asyncio.wait_for 。