diff --git a/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs b/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs index 52113392a6..3d1452f6f0 100644 --- a/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs +++ b/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Collections.Generic; using Microsoft.Bot.Schema; using Microsoft.Bot.Schema.Teams; @@ -88,5 +89,16 @@ public static void TeamsNotifyUser(this IActivity activity) { activity.TeamsNotifyUser(false); } + + /// + /// Gets the Teams OnBehalfOf list from the current activity. + /// + /// The current activity. + /// The current activity's OnBehalfOf list, or null. + public static IList TeamsGetTeamOnBehalfOf(this IActivity activity) + { + var channelData = activity.GetChannelData(); + return channelData?.OnBehalfOf; + } } } diff --git a/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs index f9aa648e6f..f8aef4a470 100644 --- a/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs +++ b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs @@ -29,12 +29,28 @@ public TeamsChannelData() /// Information about the tenant in which the /// message was sent. public TeamsChannelData(ChannelInfo channel = default, string eventType = default, TeamInfo team = default, NotificationInfo notification = default, TenantInfo tenant = default) + : this(channel, eventType, team, notification, tenant, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Information about the channel in which the message was sent. + /// Type of event. + /// Information about the team in which the message was sent. + /// Notification settings for the message. + /// Information about the tenant in which the + /// message was sent. + /// The OnBehalfOf information of the message. + public TeamsChannelData(ChannelInfo channel = default, string eventType = default, TeamInfo team = default, NotificationInfo notification = default, TenantInfo tenant = default, IList onBehalfOf = default) { Channel = channel; EventType = eventType; Team = team; Notification = notification; Tenant = tenant; + OnBehalfOf = onBehalfOf ?? new List(); CustomInit(); } @@ -91,6 +107,13 @@ public TeamsChannelData(ChannelInfo channel = default, string eventType = defaul [JsonProperty(PropertyName = "settings")] public TeamsChannelDataSettings Settings { get; set; } + /// + /// Gets the OnBehalfOf list for user attribution. + /// + /// The Teams activity OnBehalfOf list. + [JsonProperty(PropertyName = "onBehalfOf")] + public IList OnBehalfOf { get; private set; } + /// /// Gets or sets properties that are not otherwise defined by the type but that /// might appear in the REST JSON object. diff --git a/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs b/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs index 37f44e6f80..03b384b422 100644 --- a/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs +++ b/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using System.Collections.Generic; using Microsoft.Bot.Schema; using Microsoft.Bot.Schema.Teams; using Xunit; @@ -21,7 +23,7 @@ public void TeamsGetSelectedChannelId() // Assert Assert.Equal("channel123", channelId); } - + [Fact] public void TeamsGetSelectedChannelIdNullSettings() { @@ -130,5 +132,27 @@ public void TeamsNotifyUserExistingNotification() Assert.Equal(true, ((TeamsChannelData)activity.ChannelData).Notification.Alert); Assert.Equal("team123", ((TeamsChannelData)activity.ChannelData).Team.Id); } + + [Fact] + public void TeamsChannelDataExistingOnBehalfOf() + { + // Arrange + var onBehalfOf = new OnBehalfOf + { + DisplayName = "TestOnBehalfOf", + ItemId = 0, + MentionType = "person", + Mri = Guid.NewGuid().ToString() + }; + + var activity = new Activity { ChannelData = new TeamsChannelData(onBehalfOf: new List { onBehalfOf }) }; + + // Act + var onBehalfOfList = activity.TeamsGetTeamOnBehalfOf(); + + // Assert + Assert.Equal(1, onBehalfOfList.Count); + Assert.Equal("TestOnBehalfOf", onBehalfOfList[0].DisplayName); + } } } diff --git a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs index 719f301a20..9f49c4a200 100644 --- a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs +++ b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using System.Collections.Generic; using Microsoft.Bot.Schema.Teams; using Newtonsoft.Json.Linq; using Xunit; @@ -19,7 +21,17 @@ public void TeamsChannelDataInits() var tenant = new TenantInfo("uniqueTenantId"); var meeting = new TeamsMeetingInfo("BFSE Stand Up"); var settings = new TeamsChannelDataSettings(channel); - var channelData = new TeamsChannelData(channel, eventType, team, notification, tenant) + var onBehalfOf = new List() + { + new OnBehalfOf() + { + DisplayName = "onBehalfOfTest", + ItemId = 0, + MentionType = "person", + Mri = Guid.NewGuid().ToString() + } + }; + var channelData = new TeamsChannelData(channel, eventType, team, notification, tenant, onBehalfOf) { Meeting = meeting, Settings = settings @@ -34,6 +46,7 @@ public void TeamsChannelDataInits() Assert.Equal(tenant, channelData.Tenant); Assert.Equal(settings, channelData.Settings); Assert.Equal(channel, channelData.Settings.SelectedChannel); + Assert.Equal(onBehalfOf, channelData.OnBehalfOf); } [Fact]