Home > Mobile >  How to pass additional information to OnTeamsMessagingExtensionFetchTaskAsync and OnTeamsMessagingEx
How to pass additional information to OnTeamsMessagingExtensionFetchTaskAsync and OnTeamsMessagingEx

Time:11-19

I have a Messaging Extension for Teams running locally, depending upon the location from where I am invoking it (example - composebox or message) I will get the "ITurnContext turnContext" and "MessagingExtensionAction action" objects to the bot handlers. I am looking for a way to pass some additional parameters along with these objects I mentioned earlier. Is it possible?

CodePudding user response:

If you check this two official documents from Microsoft on OnTeamsMessagingExtensionFetchTaskAsync and OnTeamsMessagingExtensionSubmitActionAsync methods then, you will find that these two methods only take three parameters which are :

  1. turnContext - A strongly-typed context object for this turn.
  2. action - The messaging extension action.
  3. cancellationToken - A cancellation token that can be used by other objects or threads to receive notice of cancellation.

So currently, you can't pass additional parameters other then the ones mentioned above. Following code snippet shows the basic syntax of these methods.

protected override async Task<MessagingExtensionActionResponse> 
OnTeamsMessagingExtensionFetchTaskAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
{
    ...
}
protected override async Task<MessagingExtensionActionResponse> 
OnTeamsMessagingExtensionSubmitActionAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
{
    ...
}

I would suggest you to read this Bot Framework Teams Messaging Extensions Walkthrough and Respond to the task module submit action documents for more information.

CodePudding user response:

You cannot change or add the parameters of the methods that you are overriding. But while submitting the messaging extension you can get it in action parameter of OnTeamsMessagingExtensionSubmitActionAsync

When using the Adaptive Card you can send it as data in Adaptive Card's submit button.

{
    "type": "Action.Submit",
    "title": "OK",
    "data": {
        "AdditionalData": "TestData"
    }
}

Or you can pass data using SDK as well - microsoftTeams.tasks.submitTask({ additionalData: "someData" });.

  • Related