MicrosoftDocs / msteams-docs

Source for the Microsoft Teams developer platform documentation.
https://aka.ms/teamsdev
Creative Commons Attribution 4.0 International
285 stars 508 forks source link

Closing task module from Bot (back-end) in nodeJS #10242

Open atymic opened 9 months ago

atymic commented 9 months ago

See the issue https://github.com/MicrosoftDocs/msteams-docs/issues/832 It provides the way to do it for c# (turnContext.SendActivityAsync(new Activity { Value = null, Type = ActivityTypesEx.InvokeResponse });) How can we do this in node?

microsoft-github-policy-service[bot] commented 9 months ago

Hi atymic! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

Vikram-MSFT commented 9 months ago

Hii @atymic we are investigating the issue and get back to you soon.

Vikram-MSFT commented 9 months ago

Hello @atymic Could you please refer this sample - https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/c173c0e7a316df7425db1d795713e46c00594632/samples/bot-sharepoint-file-viewer/nodejs/bots/dialogBot.js#L64

atymic commented 9 months ago

Hi @Vikram-MSFT Returning null also gives an error on teams, saying the response is invalid

ChetanSharma-msft commented 9 months ago

Hello @atymic - Could you please share the complete code snippets that you are trying from your end?

atymic commented 9 months ago

Works:

return {
      statusCode: 200,
      task: {
        type: 'message',
        value: 'SMS Sent successfully! You can close this dialog'
      }
    }

Does not work

return {
      statusCode: 200,
    }
return null
return {
 statusCode: 200,
      task: null
    }
return {
      statusCode: 200,
      task: {
        type: 'message',
        value: null
      }
    }
return {
      statusCode: 200,
      task: {
        type: 'InvokeResponse',
        value: null
      }
    }
Vikram-MSFT commented 8 months ago

Hello @atymic To close a task module from a bot in Node.js, you can use the following code snippet: const response = { task: { type: 'message', value: 'Task module dismissed' } }; await turnContext.sendActivity({ value: response, type: 'invokeResponse' }); This will send an invokeResponse activity to the client, which will close the task module and display the message "Task module dismissed".

Nivedipa-MSFT commented 1 month ago

@atymic - You can call submitTask() without any parameters if you want Teams to close the dialog. Ref Doc: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/task-modules/task-modules-bots?tabs=nodejs#submit-the-result-of-a-dialog