From c298f57411316e0533b2e5295c296c80b814fc09 Mon Sep 17 00:00:00 2001 From: Eric Dahlvang Date: Tue, 14 Jun 2022 12:58:34 -0500 Subject: [PATCH 1/2] Add settings.selectedChannel to TeamsChannelData --- .../Teams/TeamsActivityExtensions.cs | 11 ++++ .../Teams/TeamsChannelData.cs | 7 +++ .../Teams/TeamsChannelDataSettings.cs | 57 +++++++++++++++++++ .../Teams/TeamsActivityExtensionsTests.cs | 26 +++++++++ .../Teams/TeamsChannelDataTests.cs | 10 ++-- 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 libraries/Microsoft.Bot.Schema/Teams/TeamsChannelDataSettings.cs diff --git a/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs b/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs index d68eb5d2bd..52113392a6 100644 --- a/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs +++ b/libraries/Microsoft.Bot.Builder/Teams/TeamsActivityExtensions.cs @@ -12,6 +12,17 @@ namespace Microsoft.Bot.Builder.Teams /// public static class TeamsActivityExtensions { + /// + /// Gets the Team's selected channel id from the current activity. + /// + /// The current activity. + /// The current activity's team's selected channel, or empty string. + public static string TeamsGetSelectedChannelId(this IActivity activity) + { + var channelData = activity.GetChannelData(); + return channelData?.Settings?.SelectedChannel?.Id; + } + /// /// Gets the TeamsMeetingInfo object from the current activity. /// diff --git a/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs index 53d46d0ef1..f9aa648e6f 100644 --- a/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs +++ b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs @@ -84,6 +84,13 @@ public TeamsChannelData(ChannelInfo channel = default, string eventType = defaul [JsonProperty(PropertyName = "meeting")] public TeamsMeetingInfo Meeting { get; set; } + /// + /// Gets or sets information about the settings sent with this . + /// + /// The for this . + [JsonProperty(PropertyName = "settings")] + public TeamsChannelDataSettings Settings { get; 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/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelDataSettings.cs b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelDataSettings.cs new file mode 100644 index 0000000000..5f5dfa4c4c --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/Teams/TeamsChannelDataSettings.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Bot.Schema.Teams +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + /// + /// Settings within teams channel data specific to messages received in Microsoft Teams. + /// + public partial class TeamsChannelDataSettings + { + /// + /// Initializes a new instance of the class. + /// + public TeamsChannelDataSettings() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the class. + /// + /// Information about the channel in which the message was sent. + public TeamsChannelDataSettings(ChannelInfo channel = default) + { + SelectedChannel = channel; + CustomInit(); + } + + /// + /// Gets or sets information about the selected Teams channel. + /// + /// The selected Teams channel. + [JsonProperty(PropertyName = "selectedChannel")] + public ChannelInfo SelectedChannel { get; set; } + + /// + /// Gets or sets properties that are not otherwise defined by the type but that + /// might appear in the REST JSON object. + /// + /// The extended properties for the object. + /// With this, properties not represented in the defined type are not dropped when + /// the JSON object is deserialized, but are instead stored in this property. Such properties + /// will be written to a JSON object when the instance is serialized. + [JsonExtensionData(ReadData = true, WriteData = true)] +#pragma warning disable CA2227 // Collection properties should be read only + public IDictionary AdditionalProperties { get; set; } +#pragma warning restore CA2227 // Collection properties should be read only + + /// + /// An initialization method that performs custom operations like setting defaults. + /// + partial void CustomInit(); + } +} diff --git a/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs b/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs index 63c89695f4..37f44e6f80 100644 --- a/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs +++ b/tests/Microsoft.Bot.Builder.Tests/Teams/TeamsActivityExtensionsTests.cs @@ -9,6 +9,32 @@ namespace Microsoft.Bot.Builder.Teams.Tests { public class TeamsActivityExtensionsTests { + [Fact] + public void TeamsGetSelectedChannelId() + { + // Arrange + var activity = new Activity { ChannelData = new TeamsChannelData { Settings = new TeamsChannelDataSettings { SelectedChannel = new ChannelInfo("channel123") } } }; + + // Act + var channelId = activity.TeamsGetSelectedChannelId(); + + // Assert + Assert.Equal("channel123", channelId); + } + + [Fact] + public void TeamsGetSelectedChannelIdNullSettings() + { + // Arrange + var activity = new Activity { ChannelData = new TeamsChannelData { Settings = null } }; + + // Act + var channelId = activity.TeamsGetSelectedChannelId(); + + // Assert + Assert.Null(channelId); + } + [Fact] public void TeamsGetMeetingInfo() { diff --git a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs index 087e1c96cb..719f301a20 100644 --- a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs +++ b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamsChannelDataTests.cs @@ -18,10 +18,11 @@ public void TeamsChannelDataInits() var notification = new NotificationInfo(true); 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) { - Meeting = meeting + Meeting = meeting, + Settings = settings }; Assert.NotNull(channelData); @@ -31,9 +32,10 @@ public void TeamsChannelDataInits() Assert.Equal(team, channelData.Team); Assert.Equal(notification, channelData.Notification); Assert.Equal(tenant, channelData.Tenant); - Assert.Equal(meeting, channelData.Meeting); + Assert.Equal(settings, channelData.Settings); + Assert.Equal(channel, channelData.Settings.SelectedChannel); } - + [Fact] public void TeamsChannelDataInitsWithNoArgs() { From e74f3e4f9a0aacbfc82f67591be031d0c71e11a8 Mon Sep 17 00:00:00 2001 From: Eric Dahlvang Date: Wed, 6 Jul 2022 17:14:08 -0500 Subject: [PATCH 2/2] Add Type field to ChannelInfo and TeamDetails --- libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs | 7 +++++++ libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs | 7 +++++++ tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs | 4 ++++ tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs | 3 +++ 4 files changed, 21 insertions(+) diff --git a/libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs b/libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs index 32f73b7d21..d913201503 100644 --- a/libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs +++ b/libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs @@ -45,6 +45,13 @@ public ChannelInfo(string id = default, string name = default) [JsonProperty(PropertyName = "name")] public string Name { get; set; } + /// + /// Gets or sets type of the channel. Valid values are standard, shared and private. + /// + /// The channel type. + [JsonProperty(PropertyName = "type")] + public string Type { get; set; } + /// /// An initialization method that performs custom operations like setting defaults. /// diff --git a/libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs b/libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs index 5405ecf659..b620a7e1d8 100644 --- a/libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs +++ b/libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs @@ -79,6 +79,13 @@ public TeamDetails(string id = default, string name = default, string aadGroupId [JsonProperty(PropertyName = "memberCount")] public int MemberCount { get; set; } + /// + /// Gets or sets type of the team. Valid values are standard, sharedChannel and privateChannel. + /// + /// The team type. + [JsonProperty(PropertyName = "type")] + public string Type { get; set; } + /// /// An initialization method that performs custom operations like setting defaults. /// diff --git a/tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs b/tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs index b5abe85d90..e3f93311d9 100644 --- a/tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs +++ b/tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs @@ -13,12 +13,16 @@ public void ChannelInfoInits() { var id = "channelId"; var name = "watercooler"; + var type = "standard"; + var channelInfo = new ChannelInfo(id, name); + channelInfo.Type = type; Assert.NotNull(channelInfo); Assert.IsType(channelInfo); Assert.Equal(id, channelInfo.Id); Assert.Equal(name, channelInfo.Name); + Assert.Equal(type, channelInfo.Type); } [Fact] diff --git a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs index 03e63a1ac4..11fc28ed10 100644 --- a/tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs +++ b/tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs @@ -16,11 +16,13 @@ public void TeamDetailsInits() var aadGroupId = "0000-0000-0000-0000-0000-0000"; var channelCount = 1; var memberCount = 2; + var type = "standard"; var teamDetails = new TeamDetails(id, name, aadGroupId) { ChannelCount = channelCount, MemberCount = memberCount, + Type = type }; Assert.NotNull(teamDetails); @@ -30,6 +32,7 @@ public void TeamDetailsInits() Assert.Equal(aadGroupId, teamDetails.AadGroupId); Assert.Equal(channelCount, teamDetails.ChannelCount); Assert.Equal(memberCount, teamDetails.MemberCount); + Assert.Equal(type, teamDetails.Type); } [Fact]