Sjakiem
Sjakiem

Reputation: 21

Is it possible to scope a Teams Messaging Extension?

I developed a messaging extension for Teams. I want it to only be available for the teams i specifically install the app to. Is that possible and how? I can't find any info on this, but my use-case does not seem to be far-fetched, so i would expect it to be possible.

use-case: Members of a team use an external system to register cases. I want them to be able to search and reference cases within the teams corresponding project site in the external system. I add a tab to the general channel that refers to the project site, and the messaging extension uses the contentUrl of that tab to query the right case list. I don't want the extension to be available outside the teams channels. By default it seems that the extension is available in every chat input option.

Upvotes: 1

Views: 406

Answers (2)

Sjakiem
Sjakiem

Reputation: 21

I ended up responding with a card that handles the error:

private MessagingExtensionResponse errorResponse(string title, string errorText)
{
    MessagingExtensionResult composeExtensionResult = new MessagingExtensionResult
    {
        Type = "result",
        AttachmentLayout = "list",
        Attachments = new List<MessagingExtensionAttachment>(),
    };

    ThumbnailCard h = new ThumbnailCard()
    {
        Title = title,
        Text = errorText,
    };
    composeExtensionResult.Attachments.Add(h.ToAttachment().ToMessagingExtensionAttachment());
    var messagingExtensionResponse = new MessagingExtensionResponse();
    messagingExtensionResponse.ComposeExtension = composeExtensionResult;
    return messagingExtensionResponse;
}

Although it would be nice to be able to scope the extension, this way i can catch some more invalid usage. For example:

var currentTeam = new TeamDetails();
IList<ChannelInfo> currentTeamChannels = new List<ChannelInfo>();
try
{
    currentTeam = await TeamsInfo.GetTeamDetailsAsync(turnContext, turnContext.Activity.TeamsGetTeamInfo().Id, cancellationToken);
    currentTeamChannels = await TeamsInfo.GetTeamChannelsAsync(turnContext, turnContext.Activity.TeamsGetTeamInfo().Id, cancellationToken);
}
catch
{
    return errorResponse("Permission error", "This app has no permissions to this team / channel. Please add the app to this team / channel.");
}

Got the suggestion from this question: Is it possible for a teams messaging extension to return a plaintext response instead of a card?

Upvotes: 0

Nikitha-MSFT
Nikitha-MSFT

Reputation: 595

Message extensions do no have a scope defined and they are available once you install it in teams. Currently, it is no possible to restrict to show the message extension in one team

Upvotes: 1

Related Questions