我正在尝试 Bot Framework SDK V4 Python GA。使用 LUIS 检测到意图后,我希望能够处理一些业务逻辑并做出响应。我希望能够在业务逻辑的同时发送消息,因为我想让用户知道逻辑正在处理并且需要他稍等片刻。我知道机器人通常不用于长时间运行的进程,但我有一个需要这样做的用例。我正在尝试将 turncontext 传递给业务逻辑并从那里发送消息,但它会引发以下错误。不能腌制协程对象我是异步编程的新手,不确定这里到底发生了什么。以下是我尝试过的。我尝试通过将业务逻辑完全放在不同的类中来做同样的事情,但遇到了同样的问题。来自 on_message_activity 的初始消息运行良好,但是当尝试从业务发送消息时,它会抛出上述错误。我在这里错过了什么?async def someUseCase(self,turncontext: TurnContext): await turncontext.send_activity(MessageFactory.text("Processing your query. Give me a moment.")) output = someLongRunningBusinessLogic() return MessageFactory.text(output)async def on_message_activity(self, turn_context: TurnContext): luisResult = await self.LuisRecog.recognize(turn_context) print(luisResult.get_top_scoring_intent()) intent = LuisRecognizer.top_intent(luisResult,min_score=0.40) if intent != "None": await turn_context.send_activity("processing your query...") return await turn_context.send_activity(self.someUseCase(turn_context)) else: await turn_context.send_activity(MessageFactory.text("No intent detected."))
1 回答

慕标琳琳
TA贡献1830条经验 获得超9个赞
async def
函数返回应该等待的可等待对象。您遇到的错误很可能是因为您试图将协程传递给期望在此行发生活动的函数:
return await turn_context.send_activity(self.someUseCase(turn_context))
send_activity
期望一个活动但someUseCase
返回一个协程。
您可以在 Python 文档中阅读有关协程的更多信息:https ://docs.python.org/3/library/asyncio-task.html
添加回答
举报
0/150
提交
取消