Pages Menu
TwitterRssFacebook

Posted by on Feb 17, 2020 in Development, Microsoft Teams

Microsoft Teams Development: adding things to the … More Actions menu on messages

Microsoft Teams Development: adding things to the … More Actions menu on messages

I get asked about this quite a lot, so I thought a blog post would be a good way of writing up the answer. It’s a common want to be able to trigger actions from specific messages:

As I said in my reply, you can do this today, but you need to write an application to do it, you can’t do it by configuring Teams settings. So, what do you need to do and how does it work?

Messaging Extensions

This specific type of button is a type of Messaging Extensions. These are places where an application can enhance the built-in Teams functionality by registering to appear. Messaging extensions can show up in the Teams Search Bar, the compose tray under a new message, and in the More Actions menu from a specific message:

How do I set them up?

The easiest way to make the changes needed to your manifest.json file is via App Studio. Under Capabilities, choose Messaging extensions, and Add a new Command. You’ll be given two options:

Which one do you want? It all depends on what you’re doing with your command. If you want a button which will go and find some information which you then want to post into the message, it’s the first option. However, if you just want to invoke an external action, it’s the second.

Many of the asks I get are around the second type of action, such as the ability to add the message content to a todo application. In this case, there’s an additional setup choice around parameters. Depending on your use case you might not want or need to ask the user any more parameters – the content of the message might be enough. Or, you might want to ask for some clarifying information etc.

How do I consume the commands in code?

When a user invokes these commands, they get sent to a registered bot registration instance. (you set which one in the manifest set up). This can be the same instance that you have for an existing chat bot, or you could create a completely separate new bot just for commands.

These commands have a different Activity type (type of composeExtension/fetchTask) so you can easily tell them apart from other bot messages. If you need to get the message content then you can do so:

protected override async Task<MessagingExtensionActionResponse> OnTeamsMessagingExtensionFetchTaskAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
{
  var messageText = action.MessagePayload.Body.Content;
  var fromId = action.MessagePayload.From.User.Id;

  //finish handling the fetchTask
}

Other than that though, the More Actions button command behaves like any other Messaging Extension. If you’ve not done this before, see either the Microsoft documentation: Create a messaging extension in Microsoft Teams or see my Teams Dev Project: Expose existing LOB apps in Teams for users to share easily with Compose Extensions post that has code samples to help you get started quickly.

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.