diff --git a/packages/Microsoft.Bot.Components.sln b/packages/Microsoft.Bot.Components.sln index a1352f774d..25c2572803 100644 --- a/packages/Microsoft.Bot.Components.sln +++ b/packages/Microsoft.Bot.Components.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Ad EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Components.Teams", "Teams\Microsoft.Bot.Components.Teams.csproj", "{FD29CBA6-C18F-498B-9F00-A3C34C1BEC5F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Components.Telephony", "Telephony\Microsoft.Bot.Components.Telephony.csproj", "{A854B5EC-3A34-4D1F-8080-F0846DEDF63F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {FD29CBA6-C18F-498B-9F00-A3C34C1BEC5F}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD29CBA6-C18F-498B-9F00-A3C34C1BEC5F}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD29CBA6-C18F-498B-9F00-A3C34C1BEC5F}.Release|Any CPU.Build.0 = Release|Any CPU + {A854B5EC-3A34-4D1F-8080-F0846DEDF63F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A854B5EC-3A34-4D1F-8080-F0846DEDF63F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A854B5EC-3A34-4D1F-8080-F0846DEDF63F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A854B5EC-3A34-4D1F-8080-F0846DEDF63F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/packages/Telephony/Actions/CallTransfer.cs b/packages/Telephony/Actions/CallTransfer.cs new file mode 100644 index 0000000000..2551644ea9 --- /dev/null +++ b/packages/Telephony/Actions/CallTransfer.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +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; + + /// + /// Transfers call to given phone number. + /// + public class CallTransfer : Dialog + { + /// + /// Class identifier. + /// + [JsonProperty("$kind")] + public const string Kind = "Microsoft.Telephony.CallTransfer"; + + /// + /// Initializes a new instance of the class. + /// + /// Optional, source file full path. + /// Optional, line number in source file. + [JsonConstructor] + public CallTransfer([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) + : base() + { + // enable instances of this command as debug break point + this.RegisterSourceLocation(sourceFilePath, sourceLineNumber); + } + + /// + /// Gets or sets the phone number to be included when sending the handoff activity. + /// + /// + /// . + /// + [JsonProperty("phoneNumber")] + public StringExpression PhoneNumber { get; set; } + + /// + /// Called when the dialog is started and pushed onto the dialog stack. + /// + /// The for the current turn of conversation. + /// Optional, initial information to pass to the dialog. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// 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); + + // Create handoff event, passing the phone number to transfer to as context. + var context = new { TargetPhoneNumber = phoneNumber }; + var handoffEvent = EventFactory.CreateHandoffInitiation(dc.Context, context); + await dc.Context.SendActivityAsync(handoffEvent, cancellationToken).ConfigureAwait(false); + return await dc.EndDialogAsync(result: null, cancellationToken: cancellationToken).ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/packages/Telephony/Microsoft.Bot.Components.Telephony.csproj b/packages/Telephony/Microsoft.Bot.Components.Telephony.csproj new file mode 100644 index 0000000000..6e5f572aaa --- /dev/null +++ b/packages/Telephony/Microsoft.Bot.Components.Telephony.csproj @@ -0,0 +1,44 @@ + + + + Library + netstandard2.0 + + + + Microsoft.Bot.Components.Telephony + 1.0.0-preview + This library implements .NET support for adaptive dialogs with Telephony. + This library implements .NET support for adaptive dialogs with Telephony. + true + ..\..\build\35MSSharedLib1024.snk + true + content + msbot-component;msbot-action + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + + + + + $(NoWarn),SA0001,SA1649 + + + \ No newline at end of file diff --git a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.schema b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.schema new file mode 100644 index 0000000000..4666c744e9 --- /dev/null +++ b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.schema @@ -0,0 +1,21 @@ +{ + "$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema", + "$role": "implements(Microsoft.IDialog)", + "title": "Call Transfer", + "description": "Phone number to transfer the call to (in E.164 format such as +1425123456)", + "type": "object", + "required": [ + "phoneNumber" + ], + "additionalProperties": false, + "properties": { + "phoneNumber": { + "$ref": "schema:#/definitions/stringExpression", + "title": "Phone Number", + "description": "Phone number to transfer the call to.", + "examples": [ + "in E.164 format such as +1425123456" + ] + } + } +} diff --git a/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema new file mode 100644 index 0000000000..ba73979ccc --- /dev/null +++ b/packages/Telephony/Schemas/Microsoft.Telephony.CallTransfer.uischema @@ -0,0 +1,26 @@ +{ + "$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema", + "form": { + "label": "Transfer a call", + "subtitle": "Call Transfer", + "order": [ + "phoneNumber", + "*" + ], + "properties": { + "phoneNumber": { + "intellisenseScopes": [ + "variable-scopes" + ] + } + } + }, + "menu": { + "label": "Transfer a call", + "submenu": [ "Channels", "Telephony" ] + }, + "flow": { + "widget": "ActionCard", + "body": "=action.phoneNumber" + } +} \ No newline at end of file diff --git a/packages/Telephony/TelephonyBotComponent.cs b/packages/Telephony/TelephonyBotComponent.cs new file mode 100644 index 0000000000..969ec1be33 --- /dev/null +++ b/packages/Telephony/TelephonyBotComponent.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Bot.Components.Telephony +{ + using Microsoft.Bot.Builder; + using Microsoft.Bot.Builder.Dialogs.Declarative; + using Microsoft.Bot.Components.Telephony.Actions; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; + + /// + /// Telephony actions registration. + /// + public class TelephonyBotComponent : BotComponent + { + /// + public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + // Conditionals + services.AddSingleton(sp => new DeclarativeType(CallTransfer.Kind)); + } + } +} \ No newline at end of file