Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Fix build bug from VA & replace asset images #1035

Merged
merged 3 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,15 @@ public class MainDialog : RouterDialog
private ProactiveState _proactiveState;
private EndpointService _endpointService;
private IBackgroundTaskQueue _backgroundTaskQueue;
private IHttpContextAccessor _httpContext;
private IStatePropertyAccessor<OnboardingState> _onboardingState;
private IStatePropertyAccessor<Dictionary<string, object>> _parametersAccessor;
private IStatePropertyAccessor<VirtualAssistantState> _virtualAssistantState;
private ResponseManager _responseManager;
private string _imageAssetLocation;
private MainResponses _responder = new MainResponses();
private SkillRouter _skillRouter;

private string headerImagePath = "header_greeting.png";
private string backgroundImagePath = "background_light.png";
private string columnBackgroundImagePath = "background_dark.png";
private bool _conversationStarted = false;

public MainDialog(BotServices services, ConversationState conversationState, UserState userState, ProactiveState proactiveState, EndpointService endpointService, IBotTelemetryClient telemetryClient, IBackgroundTaskQueue backgroundTaskQueue, ResponseManager responseManager, string imageAssetLocation, IHttpContextAccessor httpContext = null)
public MainDialog(BotServices services, ConversationState conversationState, UserState userState, ProactiveState proactiveState, EndpointService endpointService, IBotTelemetryClient telemetryClient, IBackgroundTaskQueue backgroundTaskQueue, ResponseManager responseManager)
: base(nameof(MainDialog), telemetryClient)
{
_services = services ?? throw new ArgumentNullException(nameof(services));
Expand All @@ -61,8 +55,6 @@ public MainDialog(BotServices services, ConversationState conversationState, Use
_endpointService = endpointService;
TelemetryClient = telemetryClient;
_backgroundTaskQueue = backgroundTaskQueue;
_httpContext = httpContext;
_imageAssetLocation = imageAssetLocation;
_responseManager = responseManager;
_onboardingState = _userState.CreateProperty<OnboardingState>(nameof(OnboardingState));
_parametersAccessor = _userState.CreateProperty<Dictionary<string, object>>("userInfo");
Expand Down Expand Up @@ -451,9 +443,6 @@ protected override async Task<InterruptionAction> OnInterruptDialogAsync(DialogC

var greetingCardData = new GreetingCardModel()
{
HeaderImageUrl = GetCardImageUri(headerImagePath),
BackgroundImageUrl = GetCardImageUri(backgroundImagePath),
ColumnBackgroundImageUrl = GetCardImageUri(columnBackgroundImagePath),
Title = titleResponse.Text,
Body = bodyResponse.Text,
Speak = string.Format("{0} {1}", titleResponse.Speak, bodyResponse.Speak)
Expand All @@ -474,9 +463,6 @@ protected override async Task<InterruptionAction> OnInterruptDialogAsync(DialogC

var greetingCardData = new GreetingCardModel()
{
HeaderImageUrl = GetCardImageUri(headerImagePath),
BackgroundImageUrl = GetCardImageUri(backgroundImagePath),
ColumnBackgroundImageUrl = GetCardImageUri(columnBackgroundImagePath),
Title = titleResponse.Text,
Body = bodyResponse.Text,
Speak = string.Format("{0} {1}", titleResponse.Speak, bodyResponse.Speak)
Expand Down Expand Up @@ -551,28 +537,6 @@ private void RegisterSkills(List<SkillDefinition> skillDefinitions)
_skillRouter = new SkillRouter(_services.SkillDefinitions);
}

private string GetCardImageUri(string imagePath)
{
// If we are in local mode we leverage the HttpContext to get the current path to the image assets
if (_httpContext != null)
{
string serverUrl = _httpContext.HttpContext.Request.Scheme + "://" + _httpContext.HttpContext.Request.Host.Value;
return $"{serverUrl}/images/{imagePath}";
}
else
{
// Otherwise use a configured image asset location
if (string.IsNullOrWhiteSpace(_imageAssetLocation))
{
throw new Exception("imageAssetLocation not configured on the skill.");
}
else
{
return $"{_imageAssetLocation}/{imagePath}";
}
}
}

private class Events
{
public const string TokenResponseEvent = "tokens/response";
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
"ReturningUserGreetingTitle": {
"replies": [
{
"text": "Welcome back {Name}",
"text": "Welcome back {Name}!",
"speak": "Welcome back {Name}!"
},
{
"text": "Hi there {Name}",
"text": "Hi there {Name}!",
"speak": "Hi there {Name}!"
},
{
"text": "Hi {Name}",
"text": "Hi {Name}!",
"speak": "Hi {Name}!"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ include file="..\..\..\..\..\..\..\..\lib\microsoft.bot.builder.solutions\Responses\ResponseIdCollection.t4"#>
<#@ include file="..\..\..\..\..\..\..\..\lib\csharp\microsoft.bot.builder.solutions\microsoft.bot.builder.solutions\Responses\ResponseIdCollection.t4"#>
ryanisgrig marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ namespace VirtualAssistant.Models
{
public class GreetingCardModel : ICardData
{
public string HeaderImageUrl { get; set; }

public string BackgroundImageUrl { get; set; }

public string ColumnBackgroundImageUrl { get; set; }

public string Speak { get; set; }

public string Title { get; set; }
Expand Down
6 changes: 0 additions & 6 deletions solutions/Virtual-Assistant/src/csharp/assistant/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ public void ConfigureServices(IServiceCollection services)
var connectedServices = new BotServices(botConfig, languageModels, skills, skillEvents);
services.AddSingleton(sp => connectedServices);

var imageAssetLocation = Configuration.GetSection("imageAssetLocation").Get<string>();
services.AddSingleton(sp => imageAssetLocation);

var defaultLocale = Configuration.GetSection("configuration").Get<string>();
var supportedLanguages = languageModels.Select(l => l.Key).ToArray();
var responseManager = new ResponseManager(
Expand Down Expand Up @@ -131,9 +128,6 @@ public void ConfigureServices(IServiceCollection services)

services.AddSingleton<IBot, VirtualAssistant>();

// HttpContext required for path resolution
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

// Add the http adapter to enable MVC style bot API
services.AddSingleton<IBotFrameworkHttpAdapter>((sp) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class VirtualAssistant : IBot
private readonly IBotTelemetryClient _telemetryClient;
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
private readonly ResponseManager _responseManager;
private readonly string _imageAssetLocation;
private IHttpContextAccessor _httpContext;
private DialogSet _dialogs;

/// <summary>
Expand All @@ -46,7 +44,7 @@ public class VirtualAssistant : IBot
/// <param name="responseManager">Response manager.</param>
/// <param name="imageAssetLocation">Image asset location.</param>
/// <param name="httpContext">Http context.</param>
public VirtualAssistant(BotServices botServices, ConversationState conversationState, UserState userState, ProactiveState proactiveState, EndpointService endpointService, IBotTelemetryClient telemetryClient, IBackgroundTaskQueue backgroundTaskQueue, ResponseManager responseManager, string imageAssetLocation, IHttpContextAccessor httpContext = null)
public VirtualAssistant(BotServices botServices, ConversationState conversationState, UserState userState, ProactiveState proactiveState, EndpointService endpointService, IBotTelemetryClient telemetryClient, IBackgroundTaskQueue backgroundTaskQueue, ResponseManager responseManager)
{
_conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
_userState = userState ?? throw new ArgumentNullException(nameof(userState));
Expand All @@ -56,11 +54,9 @@ public VirtualAssistant(BotServices botServices, ConversationState conversationS
_telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
_backgroundTaskQueue = backgroundTaskQueue;
_responseManager = responseManager;
_imageAssetLocation = imageAssetLocation;
_httpContext = httpContext ?? throw new ArgumentNullException(nameof(httpContext));

_dialogs = new DialogSet(_conversationState.CreateProperty<DialogState>(nameof(VirtualAssistant)));
_dialogs.Add(new MainDialog(_services, _conversationState, _userState, _proactiveState, _endpointService, _telemetryClient, _backgroundTaskQueue, _responseManager, _imageAssetLocation, _httpContext));
_dialogs.Add(new MainDialog(_services, _conversationState, _userState, _proactiveState, _endpointService, _telemetryClient, _backgroundTaskQueue, _responseManager));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"botFileSecret": ""
}
},
"imageAssetLocation": "http://localhost:3979/images",
"skills": [
{
"type": "skill",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public class AssistantTestBase : BotTestBase

public IBotTelemetryClient TelemetryClient { get; set; }

public string ImageAssetLocation { get; set; }

public HttpContext MockHttpContext { get; set; }

public HttpContextAccessor MockHttpContextAcessor { get; set; }

public EndpointService EndPointService { get; set; }

public BotServices BotServices { get; set; }
Expand All @@ -60,18 +54,6 @@ public class AssistantTestBase : BotTestBase
this.ProactiveState = new ProactiveState(new MemoryStorage());
this.TelemetryClient = new NullBotTelemetryClient();
this.BackgroundTaskQueue = new BackgroundTaskQueue();
this.ImageAssetLocation = "https://localhost";

// Mock HttpContext for image path resolution
MockHttpContext = new DefaultHttpContext();
MockHttpContext.Request.Scheme = "http";
MockHttpContext.Request.Host = new HostString("localhost", 3980);

MockHttpContextAcessor = new HttpContextAccessor
{
HttpContext = MockHttpContext
};

this.EndPointService = new EndpointService();

builder.RegisterInstance(new BotStateSet(this.UserState, this.ConversationState));
Expand Down Expand Up @@ -166,7 +148,7 @@ public TestFlow GetTestFlow(string locale = null)

public override IBot BuildBot()
{
return new VirtualAssistant(this.BotServices, this.ConversationState, this.UserState, this.ProactiveState, this.EndPointService, this.TelemetryClient, this.BackgroundTaskQueue, this.ResponseManager, this.ImageAssetLocation, this.MockHttpContextAcessor);
return new VirtualAssistant(this.BotServices, this.ConversationState, this.UserState, this.ProactiveState, this.EndPointService, this.TelemetryClient, this.BackgroundTaskQueue, this.ResponseManager);
}

/// <summary>
Expand Down