Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
João Quitério
committed
Jul 13, 2020
1 parent
3785fca
commit c3ef8f4
Showing
15 changed files
with
633 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Azure.Services.AppAuthentication; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Actions; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class CallAzureFunction : HttpRequest | ||
{ | ||
new public const string Kind = "CallAzureFunction"; | ||
|
||
[JsonConstructor] | ||
public CallAzureFunction([CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0) : base(callerPath, callerLine) | ||
{ | ||
} | ||
|
||
public CallAzureFunction(HttpMethod method, string url, Dictionary<string, StringExpression> headers = null, object body = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0) : base(method, url, headers, body, callerPath, callerLine) | ||
{ | ||
} | ||
|
||
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) | ||
{ | ||
if (Headers == null) | ||
{ | ||
Headers = new Dictionary<string, StringExpression>(); | ||
} | ||
if (!Headers.ContainsKey("Authorization")) | ||
{ | ||
Headers.Add("Authorization", new StringExpression($"Bearer {await GetAzureTokenAsync(new Uri(this.Url.GetValue(dc)))}")); | ||
} | ||
|
||
return await base.BeginDialogAsync(dc, options, cancellationToken); | ||
} | ||
|
||
private async Task<string> GetAzureTokenAsync(Uri uri) | ||
{ | ||
AzureServiceTokenProvider azureTokenProvider = new AzureServiceTokenProvider(); | ||
string tokenPayload = await azureTokenProvider.GetAccessTokenAsync($"{uri.Scheme}://{uri.Host}"); | ||
return tokenPayload; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class ConnectToChitChatKB : QnAMakerDialog | ||
{ | ||
new public const string Kind = "ConnectToChitChatKB"; | ||
|
||
[JsonConstructor] | ||
public ConnectToChitChatKB([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) : base(sourceFilePath, sourceLineNumber) | ||
{ | ||
} | ||
|
||
public ConnectToChitChatKB(string knowledgeBaseId, string endpointKey, string hostName, Activity noAnswer = null, float threshold = 0.3F, string activeLearningCardTitle = "Did you mean:", string cardNoMatchText = "None of the above.", int top = 3, Activity cardNoMatchResponse = null, Metadata[] strictFilters = null, HttpClient httpClient = null, [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) : base(knowledgeBaseId, endpointKey, hostName, noAnswer, threshold, activeLearningCardTitle, cardNoMatchText, top, cardNoMatchResponse, strictFilters, httpClient, sourceFilePath, sourceLineNumber) | ||
{ | ||
} | ||
|
||
protected override async Task<IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc) | ||
{ | ||
var qnaClient = dc.Context.TurnState.Get<IQnAMakerClient>(); | ||
if (qnaClient != null) | ||
{ | ||
// return mock client | ||
return qnaClient; | ||
} | ||
|
||
var configuration = dc.Context.TurnState.Get<IConfiguration>(); | ||
var endpoint = new QnAMakerEndpoint | ||
{ | ||
EndpointKey = configuration.GetValue<string>("qna:endpointkey"), | ||
Host = configuration.GetValue<string>("qna:hostname"), | ||
KnowledgeBaseId = configuration.GetValue<string>("qna:chitchat:kbId") | ||
}; | ||
var options = await GetQnAMakerOptionsAsync(dc).ConfigureAwait(false); | ||
return new QnAMaker(endpoint, options, HttpClient, this.TelemetryClient, this.LogPersonalInformation.GetValue(dc.State)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class EndCall : Dialog | ||
{ | ||
new public const string Kind = "EndCall"; | ||
|
||
[JsonConstructor] | ||
public EndCall([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) | ||
{ | ||
} | ||
|
||
[JsonProperty("reason")] | ||
public StringExpression Reason { get; set; } | ||
|
||
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) | ||
{ | ||
await dc.Context.SendActivityAsync($"[TODO] - In the future I will end the current call with reason: {Reason.GetValue(dc.State)}"); | ||
|
||
return await dc.EndDialogAsync(result: true, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class SetSpeechEndpoint : Dialog | ||
{ | ||
new public const string Kind = "SetSpeechEndpoint"; | ||
|
||
[JsonConstructor] | ||
public SetSpeechEndpoint([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) | ||
{ | ||
} | ||
|
||
[JsonProperty("endpoint")] | ||
public StringExpression Endpoint { get; set; } | ||
|
||
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) | ||
{ | ||
await dc.Context.SendActivityAsync($"[TODO] - In the future I set the speech endpoint to: {Endpoint.GetValue(dc.State)}. I'm setting converstation.speechEndpoint variable"); | ||
|
||
dc.State.SetValue("conversation.speechEndpoint", Endpoint.GetValue(dc.State)); | ||
|
||
return await dc.EndDialogAsync(result: true, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class SetTTSCaching : Dialog | ||
{ | ||
new public const string Kind = "SetTTSCaching"; | ||
|
||
[JsonConstructor] | ||
public SetTTSCaching([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) | ||
{ | ||
} | ||
|
||
[JsonProperty("enableCache")] | ||
public bool IsEnabled { get; set; } | ||
|
||
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) | ||
{ | ||
await dc.Context.SendActivityAsync($"[TODO] - In the future I'm goint to toggle the TTS cache. The cache should be set to: {IsEnabled}. I'm setting converstation.ttsCache variable"); | ||
|
||
dc.State.SetValue("conversation.ttsCache", IsEnabled); | ||
|
||
return await dc.EndDialogAsync(result: true, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdaptiveExpressions.Properties; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.AI.QnA.Dialogs; | ||
using Microsoft.Bot.Builder.AI.QnA.Utils; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.BotFramework.Composer.CustomAction | ||
{ | ||
/// <summary> | ||
/// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result. | ||
/// </summary> | ||
public class TransferCall : Dialog | ||
{ | ||
new public const string Kind = "TransferCall"; | ||
|
||
[JsonConstructor] | ||
public TransferCall([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) | ||
{ | ||
} | ||
|
||
[JsonProperty("reason")] | ||
public StringExpression Reason { get; set; } | ||
|
||
[JsonProperty("phoneNumber")] | ||
public StringExpression PhoneNumber { get; set; } | ||
|
||
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) | ||
{ | ||
await dc.Context.SendActivityAsync($"[TODO] - In the future I will transfer the call to {PhoneNumber.GetValue(dc.State)} with the handover reason: {Reason.GetValue(dc.State)}"); | ||
|
||
return await dc.EndDialogAsync(result: true, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.