Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ experimental/generator-dotnet-yeoman/node_modules

# Allow the root-level /packages/ directory or it gets confused with NuGet directories
!/[Pp]ackages/*
!/tests/[Pp]ackages/*

# Ignore correct yarn files (no zero install support)
.yarn/*
Expand Down
16 changes: 8 additions & 8 deletions packages/Telephony/Actions/CallTransfer.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

namespace Microsoft.Bot.Components.Telephony.Actions
{
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Newtonsoft.Json;

/// <summary>
/// Transfers call to given phone number.
/// </summary>
Expand Down
23 changes: 9 additions & 14 deletions packages/Telephony/Actions/PauseRecording.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Telephony.Actions
{
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Telephony;
using Newtonsoft.Json;

/// <summary>
/// Pauses recording the current conversation.
/// </summary>
Expand All @@ -41,7 +36,7 @@ public PauseRecording([CallerFilePath] string sourceFilePath = "", [CallerLineNu
// enable instances of this command as debug break point
this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);

this.Name = RecordingPause;
this.CommandName = RecordingPause;
}

public async override Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
Expand Down
23 changes: 9 additions & 14 deletions packages/Telephony/Actions/ResumeRecording.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Telephony.Actions
{
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Telephony;
using Newtonsoft.Json;

/// <summary>
/// Resume recording the current conversation.
/// </summary>
Expand All @@ -41,7 +36,7 @@ public ResumeRecording([CallerFilePath] string sourceFilePath = "", [CallerLineN
// enable instances of this command as debug break point
this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);

this.Name = RecordingResume;
this.CommandName = RecordingResume;
}

public async override Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
Expand Down
24 changes: 10 additions & 14 deletions packages/Telephony/Actions/StartRecording.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema.Telephony;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Telephony.Actions
{
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Components.Telephony.Common;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Telephony;
using Newtonsoft.Json;

/// <summary>
/// Starts recording the current conversation.
/// </summary>
Expand All @@ -41,7 +37,7 @@ public StartRecording([CallerFilePath] string sourceFilePath = "", [CallerLineNu
// enable instances of this command as debug break point
this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);

this.Name = RecordingStart;
this.CommandName = RecordingStart;

this.Data = new RecordingStartSettings()
{
Expand Down
51 changes: 40 additions & 11 deletions packages/Telephony/Common/CommandDialog{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Adaptive;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Telephony.Common
{
Expand All @@ -23,13 +23,22 @@ namespace Microsoft.Bot.Components.Telephony.Common
/// <typeparam name="T">Type of data stored in the <see <see cref="CommandValue{T}"/>.</typeparam>
public class CommandDialog<T> : Dialog
{
/// <summary>
/// Gets or sets intteruption policy.
/// </summary>
/// <value>
/// Bool or expression which evalutes to bool.
/// </value>
[JsonProperty("allowInterruptions")]
public BoolExpression AllowInterruptions { get; set; } = true;

/// <summary>
/// Gets or sets the name of the command.
/// </summary>
/// <value>
/// <see cref="StringExpression"/>.
/// </value>
protected StringExpression Name { get; set; }
protected StringExpression CommandName { get; set; }

/// <summary>
/// Gets or sets the data payload of the command.
Expand All @@ -42,8 +51,7 @@ public class CommandDialog<T> : Dialog
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
{
// TODO: check name not null / expression has value

var startRecordingActivity = CreateCommandActivity<T>(dc.Context, this.Data, this.Name.GetValue(dc.State));
var startRecordingActivity = CreateCommandActivity<T>(dc.Context, this.Data, this.CommandName.GetValue(dc.State));

var response = await dc.Context.SendActivityAsync(startRecordingActivity, cancellationToken).ConfigureAwait(false);

Expand All @@ -54,30 +62,51 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,

public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default)
{
// check activity
var activity = dc.Context.Activity;

// If command result, handle it
// We are expecting a command result with the same name as our current CommandName.
if (activity.Type == ActivityTypes.CommandResult
&& activity.Name == this.Name.GetValue(dc.State))
&& activity.Name == this.CommandName.GetValue(dc.State))
{
// TODO: correlate command id before handling it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this TODO. Each command will decide if it needs correlation or is fire-and-forget.


var commandResult = TelephonyExtensions.GetCommandResultValue(activity);

if (commandResult.Error != null)
if (commandResult?.Error != null)
{
throw new ErrorResponseException($"{commandResult.Error.Code}: {commandResult.Error.Message}");
}

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

// for now, end turn and keep waiting
// TODO: Carlos add interruption model
// This activity was not the command result we were expecting. Mark as waiting and end the turn.
return new DialogTurnResult(DialogTurnStatus.Waiting);
}

/// <inheritdoc/>
protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, DialogEvent e, CancellationToken cancellationToken)
{
if (e.Name == DialogEvents.ActivityReceived && dc.Context.Activity.Type == ActivityTypes.Message)
{
// Ask parent to perform recognition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the recognition block is before the interruption check. Will recognize utterance lead to activities being processed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just emitting the event but if we return false in this method, then interruptions will not block this flow no matter the recognition.

await dc.Parent.EmitEventAsync(AdaptiveEvents.RecognizeUtterance, value: dc.Context.Activity, bubble: false, cancellationToken: cancellationToken).ConfigureAwait(false);

// Should we allow interruptions
var canInterrupt = true;
if (this.AllowInterruptions != null)
{
var (allowInterruptions, error) = this.AllowInterruptions.TryGetValue(dc.State);
canInterrupt = error == null && allowInterruptions;
}

// Stop bubbling if interruptions ar NOT allowed
return !canInterrupt;
}

return false;
}

private static Activity CreateCommandActivity<TValue>(ITurnContext turnContext, T data, string name)
{
if (turnContext == null)
Expand Down
4 changes: 0 additions & 4 deletions packages/Telephony/Common/RecordingStartSettings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Bot.Schema.Telephony
{
public enum RecordingContentType
Expand Down
4 changes: 0 additions & 4 deletions packages/Telephony/Common/TelephonyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Newtonsoft.Json.Linq;

Expand Down
23 changes: 17 additions & 6 deletions tests/Microsoft.Bot.Components.Tests.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Teams", "..\packages\Teams\Microsoft.Bot.Components.Teams.csproj", "{1C09226C-3DE0-48BF-BEB7-68F0691908EA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "skills", "skills", "{31CBAEDA-E319-49AE-A662-AA0739205C82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Dialogs.Tests.Common", "skills\common\Microsoft.Bot.Dialogs.Tests.Common.csproj", "{94784B33-91CD-4EFE-A1DF-D0FD670A0058}"
Expand All @@ -21,16 +19,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Graph", "..\packages\Graph\Microsoft.Bot.Components.Graph.csproj", "{9561BF32-D0EE-464F-981B-7E4298ACDDFB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "telephony", "telephony", "{47F3E043-D5E7-42E3-8B18-DF64A9F2FC1C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Telephony.Tests", "packages\Microsoft.Bot.Components.Telephony.Tests\Microsoft.Bot.Components.Telephony.Tests.csproj", "{485E9D0F-6534-475D-8400-31BFF633EDE0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Telephony", "..\packages\Telephony\Microsoft.Bot.Components.Telephony.csproj", "{BDA3A62A-8762-44EA-A417-5DC01D26AAF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1C09226C-3DE0-48BF-BEB7-68F0691908EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C09226C-3DE0-48BF-BEB7-68F0691908EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C09226C-3DE0-48BF-BEB7-68F0691908EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C09226C-3DE0-48BF-BEB7-68F0691908EA}.Release|Any CPU.Build.0 = Release|Any CPU
{94784B33-91CD-4EFE-A1DF-D0FD670A0058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94784B33-91CD-4EFE-A1DF-D0FD670A0058}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94784B33-91CD-4EFE-A1DF-D0FD670A0058}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -51,6 +51,14 @@ Global
{9561BF32-D0EE-464F-981B-7E4298ACDDFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9561BF32-D0EE-464F-981B-7E4298ACDDFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9561BF32-D0EE-464F-981B-7E4298ACDDFB}.Release|Any CPU.Build.0 = Release|Any CPU
{485E9D0F-6534-475D-8400-31BFF633EDE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{485E9D0F-6534-475D-8400-31BFF633EDE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{485E9D0F-6534-475D-8400-31BFF633EDE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{485E9D0F-6534-475D-8400-31BFF633EDE0}.Release|Any CPU.Build.0 = Release|Any CPU
{BDA3A62A-8762-44EA-A417-5DC01D26AAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDA3A62A-8762-44EA-A417-5DC01D26AAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDA3A62A-8762-44EA-A417-5DC01D26AAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDA3A62A-8762-44EA-A417-5DC01D26AAF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -61,6 +69,9 @@ Global
{F0E73465-DB1D-4F8A-B527-88F1E2515A5C} = {31CBAEDA-E319-49AE-A662-AA0739205C82}
{61708441-52A4-48F6-819A-B8D4C279C4C8} = {73825711-6685-48E2-BFA2-3FCDECE1A0FD}
{F6E872DE-52B7-4372-B546-B18B5A495C73} = {61708441-52A4-48F6-819A-B8D4C279C4C8}
{47F3E043-D5E7-42E3-8B18-DF64A9F2FC1C} = {73825711-6685-48E2-BFA2-3FCDECE1A0FD}
{485E9D0F-6534-475D-8400-31BFF633EDE0} = {47F3E043-D5E7-42E3-8B18-DF64A9F2FC1C}
{BDA3A62A-8762-44EA-A417-5DC01D26AAF9} = {47F3E043-D5E7-42E3-8B18-DF64A9F2FC1C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2D0FB02B-704A-44E0-AECA-A4FDF6F805C5}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.AdaptiveDialog",
"id": "Recording_BaseScenario.test",
"triggers": [
{
"$kind": "Microsoft.OnBeginDialog",
"actions": [
{
"$kind": "Microsoft.Telephony.StartRecording",
"allowInterruptions": "=coalesce(settings.allowInterruptions, true)"
},
{
"$kind": "Microsoft.SendActivity",
"activity": "Started recording!"
}
]
},
{
"$kind": "Microsoft.OnIntent",
"intent": "HelpIntent",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "On help intent handler"
}
]
}
],
"recognizer": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "HelpIntent",
"pattern": "help"
}
]
}
}
Loading