Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

port: GetMeetingInfo, meeting start/end events [.NET] #1178

Merged
merged 1 commit into from
Jul 9, 2021
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
104 changes: 104 additions & 0 deletions packages/Teams/dotnet/Actions/GetMeetingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Teams.Actions
{
/// <summary>
/// Calls TeamsInfo.GetMeetingInfoAsync and sets the result to a memory property.
/// </summary>
public class GetMeetingInfo : Dialog
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Teams.GetMeetingInfo";

/// <summary>
/// Initializes a new instance of the <see cref="GetMeetingInfo"/> class.
/// </summary>
/// <param name="callerPath">Optional, source file full path.</param>
/// <param name="callerLine">Optional, line number in source file.</param>
[JsonConstructor]
public GetMeetingInfo([CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base()
{
RegisterSourceLocation(callerPath, callerLine);
}

/// <summary>
/// Gets or sets an optional expression which if is true will disable this action.
/// </summary>
/// <example>
/// "user.age > 18".
/// </example>
/// <value>
/// A boolean expression.
/// </value>
[JsonProperty("disabled")]
public BoolExpression Disabled { get; set; }

/// <summary>
/// Gets or sets property path to put the value in.
/// </summary>
/// <value>
/// Property path to put the value in.
/// </value>
[JsonProperty("property")]
public StringExpression Property { get; set; }

/// <summary>
/// Gets or sets the expression to get the value to use for meeting id.
/// </summary>
/// <value>
/// The expression to get the value to use for meeting id. Default value is turn.activity.channelData.meeting.id.
/// </value>
[JsonProperty("meetingId")]
public StringExpression MeetingId { get; set; } = "=turn.activity.channelData.meeting.id";

/// <inheritdoc/>
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (options is CancellationToken)
{
throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
}

if (Disabled != null && Disabled.GetValue(dc.State))
{
return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}

if (dc.Context.Activity.ChannelId != Channels.Msteams)
{
throw new InvalidOperationException($"{Kind} works only on the Teams channel.");
}

string meetingId = MeetingId.GetValueOrNull(dc.State);
var result = await TeamsInfo.GetMeetingInfoAsync(dc.Context, meetingId, cancellationToken: cancellationToken).ConfigureAwait(false);

if (Property != null)
{
dc.State.SetValue(Property.GetValue(dc.State), result);
}

return await dc.EndDialogAsync(result, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc/>
protected override string OnComputeId()
{
return $"{GetType().Name}[{MeetingId?.ToString() ?? string.Empty},{Property?.ToString() ?? string.Empty}]";
}
}
}
38 changes: 38 additions & 0 deletions packages/Teams/dotnet/Schemas/Actions/Teams.GetMeetingInfo.schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": "implements(Microsoft.IDialog)",
"title": "Get meeting information",
"description": "Get teams meeting information.",
"type": "object",
"properties": {
"id": {
"type": "string",
"title": "Id",
"description": "Optional id for the dialog"
},
"property": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Property",
"description": "Property (named location to store information).",
"examples": [
"dialog.meetingInfo"
]
},
"meetingId": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Meeting id",
"description": "Meeting Id or expression to a meetingId to use to get the meeting information. Default value is the current turn.activity.channelData.meeting.id.",
"examples": [
"=turn.activity.channelData.meeting.id"
]
},
"disabled": {
"$ref": "schema:#/definitions/booleanExpression",
"title": "Disabled",
"description": "Optional condition which if true will disable this action.",
"examples": [
"=user.age > 3"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema",
"menu": {
"submenu": ["Microsoft Teams", "Get Teams Info"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": [ "implements(Microsoft.ITrigger)", "extends(Microsoft.OnCondition)" ],
"title": "On meeting end",
"description": "Actions triggered when a Teams Meeting is ended",
"type": "object",
"required": [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema",
"trigger": {
"submenu": "Microsoft Teams",
"label": "On meeting end"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": [ "implements(Microsoft.ITrigger)", "extends(Microsoft.OnCondition)" ],
"title": "On meeting start",
"description": "Actions triggered when a Teams Meeting is started",
"type": "object",
"required": [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema",
"trigger": {
"submenu": "Microsoft Teams",
"label": "On meeting start"
}
}
3 changes: 3 additions & 0 deletions packages/Teams/dotnet/TeamsBotComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsChannelRenamed>(OnTeamsChannelRenamed.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsChannelRestored>(OnTeamsChannelRestored.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsFileConsent>(OnTeamsFileConsent.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsMeetingStart>(OnTeamsMeetingStart.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsMeetingEnd>(OnTeamsMeetingEnd.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsMECardButtonClicked>(OnTeamsMECardButtonClicked.Kind));

services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<OnTeamsMEConfigQuerySettingUrl>(OnTeamsMEConfigQuerySettingUrl.Kind));
Expand All @@ -68,6 +70,7 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati

// Actions

services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<GetMeetingInfo>(GetMeetingInfo.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<GetMeetingParticipant>(GetMeetingParticipant.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<GetMember>(GetMember.Kind));
services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<GetPagedMembers>(GetPagedMembers.Kind));
Expand Down
37 changes: 37 additions & 0 deletions packages/Teams/dotnet/TriggerConditions/OnTeamsMeetingEnd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using AdaptiveExpressions;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Conditions;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Teams.Conditions
{
/// <summary>
/// Actions triggered when a Teams Meeting End event is received.
/// </summary>
/// <remarks>
/// turn.activity.value has meeting data.
/// </remarks>
public class OnTeamsMeetingEnd : OnEventActivity
{
[JsonProperty("$kind")]
public new const string Kind = "Teams.OnMeetingEnd";

[JsonConstructor]
public OnTeamsMeetingEnd(List<Dialog> actions = null, string condition = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(actions: actions, condition: condition, callerPath: callerPath, callerLine: callerLine)
{
}

/// <inheritdoc/>
protected override Expression CreateExpression()
{
return Expression.AndExpression(Expression.Parse($"{TurnPath.Activity}.channelId == '{Channels.Msteams}' && {TurnPath.Activity}.name == 'application/vnd.microsoft.meetingEnd'"), base.CreateExpression());
}
}
}
37 changes: 37 additions & 0 deletions packages/Teams/dotnet/TriggerConditions/OnTeamsMeetingStart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using AdaptiveExpressions;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Conditions;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Teams.Conditions
{
/// <summary>
/// Actions triggered when a Teams Meeting Start event is received.
/// </summary>
/// <remarks>
/// turn.activity.value has meeting data.
/// </remarks>
public class OnTeamsMeetingStart : OnEventActivity
{
[JsonProperty("$kind")]
public new const string Kind = "Teams.OnMeetingStart";

[JsonConstructor]
public OnTeamsMeetingStart(List<Dialog> actions = null, string condition = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(actions: actions, condition: condition, callerPath: callerPath, callerLine: callerLine)
{
}

/// <inheritdoc/>
protected override Expression CreateExpression()
{
return Expression.AndExpression(Expression.Parse($"{TurnPath.Activity}.channelId == '{Channels.Msteams}' && {TurnPath.Activity}.name == 'application/vnd.microsoft.meetingStart'"), base.CreateExpression());
}
}
}