From 0959af1a3a9c8dd546a42aff31d133048e7ca254 Mon Sep 17 00:00:00 2001 From: Vanshika Sinha Date: Wed, 14 Jul 2021 16:16:45 -0700 Subject: [PATCH 1/4] chore: Updating tests and adding documentation for error handling in Call Transfer. --- packages/Telephony/Actions/CallTransfer.cs | 17 +++++++---- packages/Telephony/Readme.md | 9 +++--- .../CallTransferTests.cs | 6 ++++ .../CallTransfer_BaseScenario.test.dialog | 16 ++++++---- .../CallTransfer_HappyPath.test.dialog | 30 +++++++++++-------- ...r_IgnoredInNonTelephonyChannel.test.dialog | 15 ++++++++++ 6 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_IgnoredInNonTelephonyChannel.test.dialog diff --git a/packages/Telephony/Actions/CallTransfer.cs b/packages/Telephony/Actions/CallTransfer.cs index bca5c0661c..d89250c1f5 100644 --- a/packages/Telephony/Actions/CallTransfer.cs +++ b/packages/Telephony/Actions/CallTransfer.cs @@ -5,9 +5,9 @@ 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.Actions; +using Microsoft.Bot.Connector; using Newtonsoft.Json; namespace Microsoft.Bot.Components.Telephony.Actions @@ -55,12 +55,17 @@ public CallTransfer([CallerFilePath] string sourceFilePath = "", [CallerLineNumb /// A representing the asynchronous operation. public async override Task BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) { - var phoneNumber = this.PhoneNumber?.GetValue(dc.State); + if (dc.Context.Activity.ChannelId == Channels.Telephony) + { + var phoneNumber = this.PhoneNumber?.GetValue(dc.State); - // Create handoff event, passing the phone number to transfer to as context. - HandoffContext = new { TargetPhoneNumber = phoneNumber }; - - return await base.BeginDialogAsync(dc, options, cancellationToken).ConfigureAwait(false); + // Create handoff event, passing the phone number to transfer to as context. + HandoffContext = new { TargetPhoneNumber = phoneNumber }; + + return await base.BeginDialogAsync(dc, options, cancellationToken).ConfigureAwait(false); + } + + return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/packages/Telephony/Readme.md b/packages/Telephony/Readme.md index 89d67ad6fe..a3b287dbbe 100644 --- a/packages/Telephony/Readme.md +++ b/packages/Telephony/Readme.md @@ -13,18 +13,17 @@ Like any other channel, Telephony channel allows you to transfer call to an agen * PhoneNumber #### Usage -* Phone Number is not empty and in the E.164 format. +* Phone Number should not empty and in the E.164 format. * The call transfer action is only valid when called in a conversation on the Telephony channel. The action can be considered a No-op for all other channels. #### Dialog Flow * Once the call transfer is completed, the bot is removed from the current conversation and control is transferred to the extenal phone nunber. -* [Open] Do we get back a handoff status on success? Should we wait for the status in our package? +* We don't get any handoff status on success. * Any actions specified after call transfer will not be executed. Treat it like a call end. #### Failures -* [Open] How should the package fail when Phone Number is Empty - should we throw an exception? How can we make sure that the exception message is localize properly? -* [Open] When the phone number is not in a valid E.164 format, how does the call transfer fail? -* [Open] Do we get back a handoff status on failure? +* For all failure cases where the connection is not established, either due to Phone Number being empty, invalid, bogus or just connection failure, an asynchronous "handoff.status" event is sent with value "failed". More details [here](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-design-pattern-handoff-human?view=azure-bot-service-4.0). +* This can be handled either in code as per [this](https://github.com/microsoft/botframework-telephony/blob/main/TransferCallOut.md) or in Composer by adding a trigger -> Activities -> Event Received (Event Activity), you can add this condition, turn.activity.name == "handoff.status", following which you can use @turn.activity.value for handling the failure. ## **Call Recording** diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs index 4dd5a18c4e..18a03acb1d 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs @@ -20,6 +20,12 @@ public CallTransferTests(ResourceExplorerFixture resourceExplorerFixture) : base public async Task CallTransfer_HappyPath() { await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer, adapterChannel: Channels.Telephony); + } + + [Fact] + public async Task CallTransfer_IgnoredInNonTelephonyChannel() + { + await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer, adapterChannel: Channels.Msteams); } } } diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog index 1472a80cca..cc435f88ca 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog @@ -5,12 +5,16 @@ "triggers": [ { "$kind": "Microsoft.OnBeginDialog", - "actions": [ - { - "$kind": "Microsoft.Telephony.CallTransfer", - "phoneNumber": "+1555443443" - } - ] + "actions": [ + { + "$kind": "Microsoft.Telephony.CallTransfer", + "phoneNumber": "+15554434432" + }, + { + "$kind": "Microsoft.SendActivity", + "activity": "Transfer Initiated!" + } + ] } ] } \ No newline at end of file diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog index f97dc05f83..d5abbcaff4 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog @@ -2,17 +2,21 @@ "$schema": "../../../tests.schema", "$kind": "Microsoft.Test.Script", "dialog": "CallTransfer_BaseScenario.test", - "script": [ - { - "$kind": "Microsoft.Test.UserSays", - "text": "Hello I'm Calculon" - }, - { - "$kind": "Microsoft.Test.AssertReplyActivity", - "assertions": [ - "type == 'event'", - "value.TargetPhoneNumber == '+1555443443'" - ] - } - ] + "script": [ + { + "$kind": "Microsoft.Test.UserSays", + "text": "Hello I'm Calculon" + }, + { + "$kind": "Microsoft.Test.AssertReplyActivity", + "assertions": [ + "type == 'event'", + "value.TargetPhoneNumber == '+15554434432'" + ] + }, + { + "$kind": "Microsoft.Test.AssertReply", + "text": "Transfer Initiated!" + } + ] } \ No newline at end of file diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_IgnoredInNonTelephonyChannel.test.dialog b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_IgnoredInNonTelephonyChannel.test.dialog new file mode 100644 index 0000000000..49e8b15658 --- /dev/null +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_IgnoredInNonTelephonyChannel.test.dialog @@ -0,0 +1,15 @@ +{ + "$schema": "../../../tests.schema", + "$kind": "Microsoft.Test.Script", + "dialog": "CallTransfer_BaseScenario.test", + "script": [ + { + "$kind": "Microsoft.Test.UserSays", + "text": "Hello I'm Calculon" + }, + { + "$kind": "Microsoft.Test.AssertReply", + "text": "Transfer Initiated!" + } + ] +} \ No newline at end of file From d2830b132e182572688812fec3bef70c9361d5ac Mon Sep 17 00:00:00 2001 From: Vanshika Sinha Date: Wed, 14 Jul 2021 16:34:50 -0700 Subject: [PATCH 2/4] updating uischema --- .../Schemas/Microsoft.Telephony.CallTransfer.uischema | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema index a510ec23fa..232a76d112 100644 --- a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema +++ b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema @@ -1,8 +1,8 @@ { "$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema", "form": { - "label": "Transfer a call", - "subtitle": "Call Transfer", + "label": "Call Transfer", + "subtitle": "Transfers call to phone number specified (in E.164 format such as +1425123456)", "order": [ "phoneNumber", "*" @@ -16,7 +16,7 @@ } }, "menu": { - "label": "Transfer a call", + "label": "Call Transfer", "submenu": [ "Telephony" ] }, "flow": { From a7b700f099736f58670d4b84effe7c9d3aa9fadb Mon Sep 17 00:00:00 2001 From: Vanshika Sinha Date: Thu, 15 Jul 2021 10:21:45 -0700 Subject: [PATCH 3/4] addressing comment --- packages/Telephony/Readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/Telephony/Readme.md b/packages/Telephony/Readme.md index a3b287dbbe..25609649bd 100644 --- a/packages/Telephony/Readme.md +++ b/packages/Telephony/Readme.md @@ -13,17 +13,17 @@ Like any other channel, Telephony channel allows you to transfer call to an agen * PhoneNumber #### Usage -* Phone Number should not empty and in the E.164 format. +* Phone Number should not be empty and should be in the E.164 format. * The call transfer action is only valid when called in a conversation on the Telephony channel. The action can be considered a No-op for all other channels. #### Dialog Flow * Once the call transfer is completed, the bot is removed from the current conversation and control is transferred to the extenal phone nunber. -* We don't get any handoff status on success. +* The bot will not get any handoff status on success. * Any actions specified after call transfer will not be executed. Treat it like a call end. #### Failures * For all failure cases where the connection is not established, either due to Phone Number being empty, invalid, bogus or just connection failure, an asynchronous "handoff.status" event is sent with value "failed". More details [here](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-design-pattern-handoff-human?view=azure-bot-service-4.0). -* This can be handled either in code as per [this](https://github.com/microsoft/botframework-telephony/blob/main/TransferCallOut.md) or in Composer by adding a trigger -> Activities -> Event Received (Event Activity), you can add this condition, turn.activity.name == "handoff.status", following which you can use @turn.activity.value for handling the failure. +* This can be handled either in code as per [this](https://github.com/microsoft/botframework-telephony/blob/main/TransferCallOut.md) or in Composer by adding a trigger -> Activities -> Event Received (Event Activity), with this condition, turn.activity.name == "handoff.status", following which @turn.activity.value can be used for handling the failure case. ## **Call Recording** From 3cdf6524e5f335bd60b0646388e90b303d80fb5c Mon Sep 17 00:00:00 2001 From: Vanshika Sinha Date: Fri, 16 Jul 2021 12:03:58 -0700 Subject: [PATCH 4/4] addressing Poojas comments --- packages/Telephony/Readme.md | 4 ++-- .../Schemas/Microsoft.Telephony.CallTransfer.uischema | 2 +- .../CallTransferTests.cs | 4 ++-- .../CallTransferTests/CallTransfer_BaseScenario.test.dialog | 2 +- .../CallTransferTests/CallTransfer_HappyPath.test.dialog | 1 + 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/Telephony/Readme.md b/packages/Telephony/Readme.md index 25609649bd..2f193a46a5 100644 --- a/packages/Telephony/Readme.md +++ b/packages/Telephony/Readme.md @@ -17,14 +17,14 @@ Like any other channel, Telephony channel allows you to transfer call to an agen * The call transfer action is only valid when called in a conversation on the Telephony channel. The action can be considered a No-op for all other channels. #### Dialog Flow -* Once the call transfer is completed, the bot is removed from the current conversation and control is transferred to the extenal phone nunber. +* Once the call transfer is completed, the bot is removed from the current conversation and control is transferred to the external phone number. * The bot will not get any handoff status on success. * Any actions specified after call transfer will not be executed. Treat it like a call end. #### Failures * For all failure cases where the connection is not established, either due to Phone Number being empty, invalid, bogus or just connection failure, an asynchronous "handoff.status" event is sent with value "failed". More details [here](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-design-pattern-handoff-human?view=azure-bot-service-4.0). * This can be handled either in code as per [this](https://github.com/microsoft/botframework-telephony/blob/main/TransferCallOut.md) or in Composer by adding a trigger -> Activities -> Event Received (Event Activity), with this condition, turn.activity.name == "handoff.status", following which @turn.activity.value can be used for handling the failure case. - +* In the failure case, subsequent actions will be executed. ## **Call Recording** The call recording commands enable bots to request that calls are recorded by the phone provider. The bot can control when to start, stop, pause and resume the recording with these commands. For more information about the call recording capabilities, see [Telephony Advanced Features - Call Recording](https://github.com/microsoft/botframework-telephony/blob/main/CallRecording.md). diff --git a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema index 232a76d112..2cc45aa58b 100644 --- a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema +++ b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema @@ -2,7 +2,7 @@ "$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema", "form": { "label": "Call Transfer", - "subtitle": "Transfers call to phone number specified (in E.164 format such as +1425123456)", + "subtitle": "Transfers call to the phone number specified (in E.164 format such as +1425123456)", "order": [ "phoneNumber", "*" diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs index 18a03acb1d..5893cadc09 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/CallTransferTests.cs @@ -21,8 +21,8 @@ public async Task CallTransfer_HappyPath() { await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer, adapterChannel: Channels.Telephony); } - - [Fact] + + [Fact] public async Task CallTransfer_IgnoredInNonTelephonyChannel() { await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer, adapterChannel: Channels.Msteams); diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog index cc435f88ca..3ff4ede604 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_BaseScenario.test.dialog @@ -5,7 +5,7 @@ "triggers": [ { "$kind": "Microsoft.OnBeginDialog", - "actions": [ + "actions": [ { "$kind": "Microsoft.Telephony.CallTransfer", "phoneNumber": "+15554434432" diff --git a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog index d5abbcaff4..f052fd85f0 100644 --- a/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog +++ b/tests/packages/Microsoft.Bot.Components.Telephony.Tests/Integration/CallTransferTests/CallTransfer_HappyPath.test.dialog @@ -14,6 +14,7 @@ "value.TargetPhoneNumber == '+15554434432'" ] }, + // Due to this being a mock, after actual call transfer this will not execute { "$kind": "Microsoft.Test.AssertReply", "text": "Transfer Initiated!"