Pages Menu
TwitterRssFacebook

Posted by on Feb 17, 2020 in Development, Microsoft Teams | 0 comments

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.

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.

This site uses cookies to help make this website better. By continuing to use this site we’ll assume you’re OK with that (implied consent).