Teams Bot点击自适应卡片按钮打开任务模块时出现「Task or Task Type is missing」错误的排查求助
Teams Bot点击自适应卡片按钮打开任务模块时出现「Task or Task Type is missing」错误的排查求助
各位好,我现在在开发一个Microsoft Teams机器人,遇到了个棘手的问题:当点击自适应卡片上的提交按钮,想要触发打开任务模块模态框来提交表单时,一直报错。
我用的是task/fetch类型的动作来触发模态框,下面是我使用的自适应卡片示例代码:
{ "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.4", "body": [ { "type": "TextBlock", "text": "Available Options", "weight": "Bolder", "size": "Large" }, { "type": "Container", "items": [ { "type": "ColumnSet", "columns": [ { "type": "Column", "width": "stretch", "items": [ { "type": "Image", "url": "https://picsum.photos/200", "size": "Small" }, { "type": "TextBlock", "text": "Create Option", "weight": "Bolder" }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Create new", "data": { "msteams": { "type": "task/fetch" }, "action": "createOption" } } ] } ] } ] } ] } ] }
后端我用Flask服务器来处理Teams机器人的响应,处理task/fetch类型invoke请求的代码如下:
settings = BotFrameworkAdapterSettings(bot_id, bot_password) adapter = BotFrameworkAdapter(settings) async def turn_logic(turn_context: TurnContext): typing_activity = Activity(type=ActivityTypes.typing) await turn_context.send_activity(typing_activity) if turn_context.activity.type == "invoke" and turn_context.activity.name == "task/fetch": task_response = Activity( type=ActivityTypes.invoke_response, value=InvokeResponse( status=200, body={ "task": { "type": "continue", "value": { "title": "Create Form", "height": "large", "width": "large", "card": { "contentType": "application/vnd.microsoft.card.adaptive", "content": get_form_adaptive_card() } } } } ) ) await turn_context.send_activity(task_response) def initiate_task_loop(request, callback): body = request.json activity = Activity().deserialize(body) auth_header = request.headers["Authorization"] loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) try: task = adapter.process_activity(activity, auth_header, callback) loop.run_until_complete(task) finally: loop.close() @app.route("/<endpoint>", methods=["POST"]) def messages(): try: initiate_task_loop(request, turn_logic) return jsonify({"status": "ok"}), 200 except Exception as e: import traceback print(str(e)) print("".join(traceback.format_tb(e.__traceback__))) return jsonify({"error": str(e)}), 500
点击按钮后,网络请求返回的错误信息如下:
{ "errorCode": 1008, "message": "<BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response", "standardizedError": { "errorCode": 1008, "errorSubCode": 1, "errorDescription": "<BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response" } }
同时,打开的模态框里显示「Something went wrong. Please try again later.」的提示。
另外需要说明的是,我的本地代码里没有manifest.json文件,所有应用配置都是在微软开发者平台上完成的。
现在不知道哪里出了问题,有没有大佬能帮忙排查下这个错误的原因呀?
备注:内容来源于stack exchange,提问作者Gagan Ganapathy
相关产品推荐
相关产品推荐

