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

[#6596] TeamsChannelData need OnBehalfOf #6609

Merged
merged 5 commits into from
Apr 20, 2023
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
@@ -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;

Expand Down Expand Up @@ -88,5 +89,16 @@ public static void TeamsNotifyUser(this IActivity activity)
{
activity.TeamsNotifyUser(false);
}

/// <summary>
/// Gets the Teams OnBehalfOf list from the current activity.
/// </summary>
/// <param name="activity">The current activity.</param>
/// <returns>The current activity's OnBehalfOf list, or null.</returns>
public static IList<OnBehalfOf> TeamsGetTeamOnBehalfOf(this IActivity activity)
{
var channelData = activity.GetChannelData<TeamsChannelData>();
return channelData?.OnBehalfOf;
}
}
}
23 changes: 23 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/TeamsChannelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@ public TeamsChannelData()
/// <param name="tenant">Information about the tenant in which the
/// message was sent.</param>
public TeamsChannelData(ChannelInfo channel = default, string eventType = default, TeamInfo team = default, NotificationInfo notification = default, TenantInfo tenant = default)
: this(channel, eventType, team, notification, tenant, null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="TeamsChannelData"/> class.
/// </summary>
/// <param name="channel">Information about the channel in which the message was sent.</param>
/// <param name="eventType">Type of event.</param>
/// <param name="team">Information about the team in which the message was sent.</param>
/// <param name="notification">Notification settings for the message.</param>
/// <param name="tenant">Information about the tenant in which the
/// message was sent.</param>
/// <param name="onBehalfOf">The OnBehalfOf information of the message.</param>
public TeamsChannelData(ChannelInfo channel = default, string eventType = default, TeamInfo team = default, NotificationInfo notification = default, TenantInfo tenant = default, IList<OnBehalfOf> onBehalfOf = default)
{
Channel = channel;
EventType = eventType;
Team = team;
Notification = notification;
Tenant = tenant;
OnBehalfOf = onBehalfOf ?? new List<OnBehalfOf>();
CustomInit();
}

Expand Down Expand Up @@ -91,6 +107,13 @@ public TeamsChannelData(ChannelInfo channel = default, string eventType = defaul
[JsonProperty(PropertyName = "settings")]
public TeamsChannelDataSettings Settings { get; set; }

/// <summary>
/// Gets the OnBehalfOf list for user attribution.
/// </summary>
/// <value>The Teams activity OnBehalfOf list.</value>
[JsonProperty(PropertyName = "onBehalfOf")]
public IList<OnBehalfOf> OnBehalfOf { get; private 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
@@ -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;
Expand All @@ -21,7 +23,7 @@ public void TeamsGetSelectedChannelId()
// Assert
Assert.Equal("channel123", channelId);
}

[Fact]
public void TeamsGetSelectedChannelIdNullSettings()
{
Expand Down Expand Up @@ -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> { onBehalfOf }) };

// Act
var onBehalfOfList = activity.TeamsGetTeamOnBehalfOf();

// Assert
Assert.Equal(1, onBehalfOfList.Count);
Assert.Equal("TestOnBehalfOf", onBehalfOfList[0].DisplayName);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<OnBehalfOf>()
{
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
Expand All @@ -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]
Expand Down