Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings.selectedChannel to TeamsChannelData and Type to ChannelInfo and TeamDetails #6360

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ namespace Microsoft.Bot.Builder.Teams
/// </summary>
public static class TeamsActivityExtensions
{
/// <summary>
/// Gets the Team's selected channel id from the current activity.
/// </summary>
/// <param name="activity"> The current activity. </param>
/// <returns>The current activity's team's selected channel, or empty string.</returns>
public static string TeamsGetSelectedChannelId(this IActivity activity)
{
var channelData = activity.GetChannelData<TeamsChannelData>();
return channelData?.Settings?.SelectedChannel?.Id;
}

/// <summary>
/// Gets the TeamsMeetingInfo object from the current activity.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/ChannelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public ChannelInfo(string id = default, string name = default)
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

/// <summary>
/// Gets or sets type of the channel. Valid values are standard, shared and private.
/// </summary>
/// <value>The channel type.</value>
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

/// <summary>
/// An initialization method that performs custom operations like setting defaults.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/TeamDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public TeamDetails(string id = default, string name = default, string aadGroupId
[JsonProperty(PropertyName = "memberCount")]
public int MemberCount { get; set; }

/// <summary>
/// Gets or sets type of the team. Valid values are standard, sharedChannel and privateChannel.
/// </summary>
/// <value>The team type.</value>
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

/// <summary>
/// An initialization method that performs custom operations like setting defaults.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public TeamsChannelData(ChannelInfo channel = default, string eventType = defaul
[JsonProperty(PropertyName = "meeting")]
public TeamsMeetingInfo Meeting { get; set; }

/// <summary>
/// Gets or sets information about the settings sent with this <see cref="TeamsChannelData"/>.
/// </summary>
/// <value>The <see cref="TeamsChannelDataSettings"/> for this <see cref="TeamsChannelData"/>.</value>
[JsonProperty(PropertyName = "settings")]
public TeamsChannelDataSettings Settings { get; set; }

/// <summary>
/// Gets or sets properties that are not otherwise defined by the <see cref="TeamsChannelData"/> type but that
/// might appear in the REST JSON object.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Settings within teams channel data specific to messages received in Microsoft Teams.
/// </summary>
public partial class TeamsChannelDataSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="TeamsChannelDataSettings"/> class.
/// </summary>
public TeamsChannelDataSettings()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the <see cref="TeamsChannelDataSettings"/> class.
/// </summary>
/// <param name="channel">Information about the channel in which the message was sent.</param>
public TeamsChannelDataSettings(ChannelInfo channel = default)
{
SelectedChannel = channel;
CustomInit();
}

/// <summary>
/// Gets or sets information about the selected Teams channel.
/// </summary>
/// <value>The selected Teams channel.</value>
[JsonProperty(PropertyName = "selectedChannel")]
public ChannelInfo SelectedChannel { get; set; }

/// <summary>
/// Gets or sets properties that are not otherwise defined by the <see cref="TeamsChannelDataSettings"/> type but that
/// might appear in the REST JSON object.
/// </summary>
/// <value>The extended properties for the object.</value>
/// <remarks>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.</remarks>
[JsonExtensionData(ReadData = true, WriteData = true)]
#pragma warning disable CA2227 // Collection properties should be read only
public IDictionary<string, object> AdditionalProperties { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// An initialization method that performs custom operations like setting defaults.
/// </summary>
partial void CustomInit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions tests/Microsoft.Bot.Schema.Tests/Teams/ChannelInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(channelInfo);
Assert.Equal(id, channelInfo.Id);
Assert.Equal(name, channelInfo.Name);
Assert.Equal(type, channelInfo.Type);
}

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions tests/Microsoft.Bot.Schema.Tests/Teams/TeamDetailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
{
Expand Down