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

Commit

Permalink
Add files for Hospitality Sample VA (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
litofish authored and darrenj committed Aug 5, 2019
1 parent 846b822 commit 6c4bb37
Show file tree
Hide file tree
Showing 95 changed files with 19,300 additions and 0 deletions.
15 changes: 15 additions & 0 deletions solutions/HospitalitySample/.filenesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"dependentFileProviders": {
"add": {
"pathSegment": {
"add": {
".*": [
".json",
".resx"
]
}
}
}
}
}
40 changes: 40 additions & 0 deletions solutions/HospitalitySample/Adapters/DefaultAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using HospitalitySample.Responses.Main;
using HospitalitySample.Services;

namespace HospitalitySample.Adapters
{
public class DefaultAdapter : BotFrameworkHttpAdapter
{
public DefaultAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
IBotTelemetryClient telemetryClient)
: base(credentialProvider)
{
OnTurnError = async (turnContext, exception) =>
{
await turnContext.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"{exception.Message}"));
await turnContext.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"{exception.StackTrace}"));
await turnContext.SendActivityAsync(MainStrings.ERROR);
telemetryClient.TrackException(exception);
};

// Uncomment the following line for local development without Azure Storage
// Use(new TranscriptLoggerMiddleware(new MemoryTranscriptStore()));
Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
}
}
}
41 changes: 41 additions & 0 deletions solutions/HospitalitySample/Adapters/DefaultWebSocketAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.StreamingExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using HospitalitySample.Responses.Main;
using HospitalitySample.Services;

namespace HospitalitySample.Adapters
{
public class DefaultWebSocketAdapter : WebSocketEnabledHttpAdapter
{
public DefaultWebSocketAdapter(
IConfiguration config,
BotSettings settings,
ICredentialProvider credentialProvider,
IBotTelemetryClient telemetryClient)
: base(config, credentialProvider)
{
OnTurnError = async (turnContext, exception) =>
{
await turnContext.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"{exception.Message}"));
await turnContext.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"{exception.StackTrace}"));
await turnContext.SendActivityAsync(MainStrings.ERROR);
telemetryClient.TrackException(exception);
};

// Uncomment the following line for local development without Azure Storage
// Use(new TranscriptLoggerMiddleware(new MemoryTranscriptStore())); Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new SetSpeakMiddleware(settings.DefaultLocale ?? "en-us"));
}
}
}
46 changes: 46 additions & 0 deletions solutions/HospitalitySample/Bots/DialogBot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.DependencyInjection;

namespace HospitalitySample.Bots
{
public class DialogBot<T> : IBot
where T : Dialog
{
private readonly Dialog _dialog;
private readonly BotState _conversationState;
private readonly BotState _userState;
private readonly IBotTelemetryClient _telemetryClient;

public DialogBot(IServiceProvider serviceProvider, T dialog)
{
_dialog = dialog;
_conversationState = serviceProvider.GetService<ConversationState>();
_userState = serviceProvider.GetService<UserState>();
_telemetryClient = serviceProvider.GetService<IBotTelemetryClient>();
}

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
// Client notifying this bot took to long to respond (timed out)
if (turnContext.Activity.Code == EndOfConversationCodes.BotTimedOut)
{
_telemetryClient.TrackTrace($"Timeout in {turnContext.Activity.ChannelId} channel: Bot took too long to respond.", Severity.Information, null);
return;
}

await _dialog.RunAsync(turnContext, _conversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);

// Save any state changes that might have occured during the turn.
await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await _userState.SaveChangesAsync(turnContext, false, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
"Version": "8.13.10627.1",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?LinkID=798432"
}
}
Loading

0 comments on commit 6c4bb37

Please sign in to comment.