How to pass additional information to OnTeamsMessagingExtensionFetchTaskAsync and OnTeamsMessagingExtensionSubmitActionAsync handlers from Teams

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?

Answer

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.