Msteams-docs: Closing task module from Bot (back-end)

Created on 25 Jul 2019  Â·  11Comments  Â·  Source: MicrosoftDocs/msteams-docs

I have a flow that submits task with result to back-end, where Bot (this is important, I don't have HttpRequest/Response there) handles the result (task/submit operation), and sends InvokeResponse back.
When I do that, Teams throws [Bot invoke failed]: <BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response and task module stays open with Unable to reach app. Please try again message. It appears I need to return task object, but it's not clear how to issue close task module command in it.
I can send task with type=message, but I don't need displaying any messages plus task module remains open; type=continue implies opening another task module (TaskInfo with Card/urls - not my case as well).
p.s. When I send task type=continue with default TaskInfo, teams throws <BotError>Bot returned unsuccessful status code NotImplemented


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

teams-developer-support

Most helpful comment

Hi @Trinetra-MSFT,
I also see this issue. I tried your piece of code mentioned above and still got _Error when processing invoke response: Task or Task Type is missing in Task Module response_ with status code 502.
At the same time the task module is still opened with error message "Unable to reach app. Please try again."

All 11 comments

To sum everything up, the only way I currently see to close the task module is to do microsoftTeams.tasks.submitTask() on front-end.

Could you please share the code snippet of how you are handling _task/submit_ action? Here are samples for Task Module for reference.

@wajeed-msft I can’t right now, but off-the-cuff it is based on your samples. The only difference is handling is inside ‘IBot.OnTurnAsync’ method, not Controller Post. Thus I can’t directly return success HttpResponse. I’m looking for InvokeResponse that would close the task module.

Hello ,
I am running with issue we are using task module with deep link for upload link in adaptive card .once click that link it will open upload popup in teams bot but it is not opening in web browser teams and desktop teams app.
the below URL used to redirecting on upload link click.
https://teams.microsoft.com/l/task/6132add7-9049-472d-a329-de6290441c00?url=https%3A%2F%2Ficebreaker-y5l22i4ytireq.azurewebsites.net%2FUpload%2FUpload&height=450&width=510&title=Upload&completionBotId=6132add7-9049-472d-a329-de6290441c00
Note : it is working for some of the users but not for all.

can you please help me to get the resolution .Is it issue with users or teams app access related permissions. if you need more details please let me know
Thanks
Raveendra

@crow-ua Could you please try to pass invoke response inside task/submit for closing the task module pop up?

````
InvokeResponse ir = new InvokeResponse
{
Status = 200,
};
var activity = new Activity
{
Value = ir,
Type = ActivityTypesEx.InvokeResponse
};

            try
            {
                await stepContext.Context.SendActivityAsync(activity);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex);
            }`

@Trinetra-MSFT That's exactly what I was doing and getting <BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response.

Please try this piece of code and let us know if you are still facing issue with closing task module pop-up.

` case "task/submit":
                    // Close task module by sending reponse as Accepted.
                    await SendResponse(turnContext);
                    break;`

` private static async Task SendResponse(ITurnContext<IInvokeActivity> turnContext, object body = null)
        {
            await turnContext.SendActivityAsync(new Activity
            {
                Value = new InvokeResponse { Status = 200, Body = body },
                Type = ActivityTypesEx.InvokeResponse,
            });
        }`

Hi @Trinetra-MSFT,
I also see this issue. I tried your piece of code mentioned above and still got _Error when processing invoke response: Task or Task Type is missing in Task Module response_ with status code 502.
At the same time the task module is still opened with error message "Unable to reach app. Please try again."

@Leks12lk , @crow-ua - Could you please try this inside your ActivityHandler?

        public override Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            switch (turnContext.Activity.Type)
            {
                // handle invokes
                case ActivityTypes.Invoke:
                    return OnInvokeActivityAsync(new DelegatingTurnContext<IInvokeActivity>(turnContext), cancellationToken);
                default:
                    return base.OnTurnAsync(turnContext, cancellationToken);
            }
        }

        protected virtual async Task OnInvokeActivityAsync(ITurnContext<IInvokeActivity> turnContext, CancellationToken cancellationToken)
        {
            switch (turnContext.Activity.Name)
            {
                case "task/fetch":
                   // Show task module
                    break;
                case "task/submit":
                    // Handle task module submit
                    await SendResponse(turnContext);
                    break;
            }
        }

        private static async Task SendResponse(ITurnContext<IInvokeActivity> turnContext, object body = null)
        {
            await turnContext.SendActivityAsync(new Activity
            {
                Value = new InvokeResponse { Status = 200, Body = body },
                Type = ActivityTypesEx.InvokeResponse,
            });
        }

Hi @Wajeed-msft,
It does not work for me with mentioned above SendResponse method implementation, but it works with the next implementation of that method
private static async Task SendResponse(ITurnContext<IInvokeActivity> turnContext, object body = null) { await turnContext.SendActivityAsync(new Activity { Value = null, Type = ActivityTypesEx.InvokeResponse }); }

Thanks

turnContext.SendActivityAsync(new Activity { Value = null, Type = ActivityTypesEx.InvokeResponse }); worked for me as well.

The documentation probably needs to be updated for Bot Framework v4.

Was this page helpful?
0 / 5 - 0 ratings