Skip to content

Commit

Permalink
Merge branch 'master' into hond/error-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Danieladu committed Feb 9, 2020
2 parents 1207de2 + 3348bc1 commit 93ffdaa
Show file tree
Hide file tree
Showing 273 changed files with 5,229 additions and 2,398 deletions.
3 changes: 3 additions & 0 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@
<Source>.*\\FacebookThreadControl.cs</Source>
<Source>.*\\HandoverConstants.cs</Source>
<Source>.*\\AttachmentPayload.cs</Source>
<Source>.*\\CommonRegexLexer.cs</Source>
<Source>.*\\CommonRegexParser.cs</Source>
<Source>.*\\ExpressionLexer.cs</Source>
<Source>.*\\ExpressionParser.cs</Source>
<Source>.*\\LGFileLexer.cs</Source>
<Source>.*\\LGFileParser.cs</Source>
</Exclude>
</Sources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ private void GetEnvironmentVars()
speechBotSecret = Environment.GetEnvironmentVariable("SPEECHBOTSECRET");
if (string.IsNullOrWhiteSpace(speechBotSecret))
{
throw new Exception("Environment variable 'SPEECHBOTSECRET' not found.");
Assert.Inconclusive("Environment variable 'SPEECHBOTSECRET' not found.");
}

// The cog services key for use with DLS.
speechSubscription = Environment.GetEnvironmentVariable("SPEECHSUBSCRIPTION");
if (string.IsNullOrWhiteSpace(speechSubscription))
{
throw new Exception("Environment variable 'SPEECHSUBSCRIPTION' not found.");
Assert.Inconclusive("Environment variable 'SPEECHSUBSCRIPTION' not found.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ private async Task<string> ReceiveMessageAsync()
{
var httpResponse = await client.GetAsync(retrieveMessagesUri);
var response = httpResponse.Content.ReadAsStringAsync().Result;
var messages = JObject.Parse(response);

result = messages.SelectToken("data[0].messages.data[0].message").ToString();
try
{
var messages = JObject.Parse(response);
result = messages.SelectToken("data[0].messages.data[0].message").ToString();
}
catch
{
result = response;
}
}

return result;
Expand Down Expand Up @@ -125,25 +132,25 @@ private void GetEnvironmentVars()
_appSecret = Environment.GetEnvironmentVariable("FACEBOOK_APP_SECRET");
if (string.IsNullOrWhiteSpace(_appSecret))
{
throw new Exception("Environment variable 'FACEBOOK_APP_SECRET' not found.");
Assert.Inconclusive("Environment variable 'FACEBOOK_APP_SECRET' not found.");
}

_accessToken = Environment.GetEnvironmentVariable("FACEBOOK_ACCESS_TOKEN");
if (string.IsNullOrWhiteSpace(_accessToken))
{
throw new Exception("Environment variable 'FACEBOOK_ACCESS_TOKEN' not found.");
Assert.Inconclusive("Environment variable 'FACEBOOK_ACCESS_TOKEN' not found.");
}

_botEndpoint = Environment.GetEnvironmentVariable("BOT_ENDPOINT");
if (string.IsNullOrWhiteSpace(_botEndpoint))
{
throw new Exception("Environment variable 'BOT_ENDPOINT' not found.");
Assert.Inconclusive("Environment variable 'BOT_ENDPOINT' not found.");
}

_senderId = Environment.GetEnvironmentVariable("SENDER_ID");
if (string.IsNullOrWhiteSpace(_senderId))
{
throw new Exception("Environment variable 'SENDER_ID' not found.");
Assert.Inconclusive("Environment variable 'SENDER_ID' not found.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<Configurations>Debug;Release;</Configurations>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,31 @@ private void GetEnvironmentVars()
_twilioNumber = Environment.GetEnvironmentVariable("TWILIO_NUMBER");
if (string.IsNullOrWhiteSpace(_twilioNumber))
{
throw new Exception("Environment variable 'TwilioNumber' not found.");
Assert.Inconclusive("Environment variable 'TwilioNumber' not found.");
}

_twilioAuthToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
if (string.IsNullOrWhiteSpace(_twilioAuthToken))
{
throw new Exception("Environment variable 'TWILIO_AUTH_TOKEN' not found.");
Assert.Inconclusive("Environment variable 'TWILIO_AUTH_TOKEN' not found.");
}

_twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
if (string.IsNullOrWhiteSpace(_twilioAccountSid))
{
throw new Exception("Environment variable 'TWILIO_ACCOUNT_SID' not found.");
Assert.Inconclusive("Environment variable 'TWILIO_ACCOUNT_SID' not found.");
}

_senderNumber = Environment.GetEnvironmentVariable("SENDER_NUMBER");
if (string.IsNullOrWhiteSpace(_senderNumber))
{
throw new Exception("Environment variable 'SENDER_NUMBER' not found.");
Assert.Inconclusive("Environment variable 'SENDER_NUMBER' not found.");
}

_botEndpoint = Environment.GetEnvironmentVariable("TwilioValidationUrl");
if (string.IsNullOrWhiteSpace(_botEndpoint))
{
throw new Exception("Environment variable 'TwilioValidationUrl' not found.");
Assert.Inconclusive("Environment variable 'TwilioValidationUrl' not found.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,31 @@ private void GetEnvironmentVars()
_roomId = Environment.GetEnvironmentVariable("WEBEX_ROOM_ID");
if (string.IsNullOrWhiteSpace(_roomId))
{
throw new Exception("Environment variable 'WEBEX_ROOM_ID' not found.");
Assert.Inconclusive("Environment variable 'WEBEX_ROOM_ID' not found.");
}

_refreshToken = Environment.GetEnvironmentVariable("REFRESH_TOKEN");
if (string.IsNullOrWhiteSpace(_refreshToken))
{
throw new Exception("Environment variable 'REFRESH_TOKEN' not found.");
Assert.Inconclusive("Environment variable 'REFRESH_TOKEN' not found.");
}

_integrationClientId = Environment.GetEnvironmentVariable("WebexIntegrationClientId");
if (string.IsNullOrWhiteSpace(_integrationClientId))
{
throw new Exception("Environment variable 'WebexIntegrationClientId' not found.");
Assert.Inconclusive("Environment variable 'WebexIntegrationClientId' not found.");
}

_integrationClientSecret = Environment.GetEnvironmentVariable("INTEGRATION_CLIENT_SECRET");
if (string.IsNullOrWhiteSpace(_integrationClientSecret))
{
throw new Exception("Environment variable 'INTEGRATION_CLIENT_SECRET' not found.");
Assert.Inconclusive("Environment variable 'INTEGRATION_CLIENT_SECRET' not found.");
}

_targetBotEmail = Environment.GetEnvironmentVariable("WebexBotUserName");
if (string.IsNullOrWhiteSpace(_targetBotEmail))
{
throw new Exception("Environment variable 'WebexBotUserName' not found.");
Assert.Inconclusive("Environment variable 'WebexBotUserName' not found.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Configuration;

namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Authentication
{
/// <summary>
/// Sample claims validator that loads an allowed list from configuration if present
/// and checks that requests are coming from allowed parent bots.
/// </summary>
public class AllowedCallersClaimsValidator : ClaimsValidator
{
private const string ConfigKey = "AllowedCallers";
private readonly List<string> _allowedCallers;

public AllowedCallersClaimsValidator(IConfiguration config)
{
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}

// AllowedCallers is the setting in appsettings.json file
// that consists of the list of parent bot ids that are allowed to access the skill
// to add a new parent bot simply go to the AllowedCallers and add
// the parent bot's microsoft app id to the list
var section = config.GetSection(ConfigKey);
var appsList = section.Get<string[]>();
_allowedCallers = appsList != null ? new List<string>(appsList) : null;
}

public override Task ValidateClaimsAsync(IList<Claim> claims)
{
// if _allowedCallers is null we allow all calls
if (_allowedCallers != null && SkillValidation.IsSkillClaim(claims))
{
// Check that the appId claim in the skill request is in the list of skills configured for this bot.
var appId = JwtTokenValidation.GetAppIdFromClaims(claims);
if (!_allowedCallers.Contains(appId))
{
throw new UnauthorizedAccessException($"Received a request from a bot with an app ID of \"{appId}\". To enable requests from this caller, add the app ID to your configuration file.");
}
}

return Task.CompletedTask;
}
}
}
30 changes: 30 additions & 0 deletions FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Bots/EchoBot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;

namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Bots
{
public class EchoBot : ActivityHandler
{
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
if (turnContext.Activity.Text.Contains("end") || turnContext.Activity.Text.Contains("stop"))
{
// Send End of conversation at the end.
await turnContext.SendActivityAsync(MessageFactory.Text($"ending conversation from the skill..."), cancellationToken);
var endOfConversation = Activity.CreateEndOfConversationActivity();
endOfConversation.Code = EndOfConversationCodes.CompletedSuccessfully;
await turnContext.SendActivityAsync(endOfConversation, cancellationToken);
}
else
{
await turnContext.SendActivityAsync(MessageFactory.Text($"Echo (dotnet core 3.1) : {turnContext.Activity.Text}"), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Text("Say \"end\" or \"stop\" and I'll end the conversation and back to the parent."), cancellationToken);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Controllers
{
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
// achieved by specifying a more specific type for the bot constructor argument.
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter _adapter;
private readonly IBot _bot;

public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
_adapter = adapter;
_bot = bot;
}

[HttpPost]
public async Task PostAsync()
{
await _adapter.ProcessAsync(Request, Response, _bot);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<AssemblyName>Microsoft.BotBuilderSamples.EchoSkillBot31</AssemblyName>
<RootNamespace>Microsoft.BotBuilderSamples.EchoSkillBot31</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\libraries\integration\Microsoft.Bot.Builder.Integration.AspNet.Core\Microsoft.Bot.Builder.Integration.AspNet.Core.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Microsoft.BotBuilderSamples.EchoSkillBot31
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:39783/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"EchoSkillBot31": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

0 comments on commit 93ffdaa

Please sign in to comment.