Gagan Ganapathy
Gagan Ganapathy

Reputation: 75

Trying to open task module, but get <BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response

I am building an MS teams bot, and on clicking a submit action on an adaptive card want to open up a modal to submit a form.

Below is a sample adaptive card which has the type = "task/fetch" on the action, which on click should open the task modal.

{
        "$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"
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }

Below is how I'm handling the responses from my teams bot using a flask server:

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

The error I keep getting on clicking the adaptive card action button in the network tab for the invoke call:

{
    "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"
    }
}

Error shown on the modal opened:

Error shown on the modal opened

I don't have a manifest.json in my local app code, I have everything setup on the MSFT dev platform.

Upvotes: 0

Views: 36

Answers (1)

Gagan Ganapathy
Gagan Ganapathy

Reputation: 75

Didn't get a workaround for this issue, but was able to modify my code to use the example app provided in the offical docs here, which worked for me.

Docs: https://github.com/microsoft/BotBuilder-Samples/blob/632217bae6846aa99c3d553e29f8f061dce1754b/archive/samples/python/54.teams-task-module/bots/teams_task_module_bot.py.

Hope this helps :)

Upvotes: 0

Related Questions