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

[4.4] Calendar skill folder restructure + config #1063

Merged
merged 1 commit into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,41 @@
using System.Globalization;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace CalendarSkill.Adapters
{
public class CalendarSkillAdapter : SkillAdapter
{
public CalendarSkillAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient)
: base(credentialProvider)
{
OnTurnError = async (context, exception) =>
{
CultureInfo.CurrentUICulture = new CultureInfo(context.Activity.Locale);
await context.SendActivityAsync(responseManager.GetResponse(CalendarSharedResponses.CalendarErrorMessage));
await context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Calendar Skill Error: {exception.Message} | {exception.StackTrace}"));
telemetryClient.TrackExceptionEx(exception, context.Activity);
};

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 AutoSaveStateMiddleware(botStateSet));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Globalization;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Services;
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.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace CalendarSkill.Adapters
{
public class DefaultAdapter : BotFrameworkHttpAdapter
{
public DefaultAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
BotStateSet botStateSet,
IBotTelemetryClient telemetryClient,
ResponseManager responseManager)
: base(credentialProvider)
{
OnTurnError = async (context, exception) =>
{
CultureInfo.CurrentUICulture = new CultureInfo(context.Activity.Locale);
await context.SendActivityAsync(responseManager.GetResponse(CalendarSharedResponses.CalendarErrorMessage));
await context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Calendar Skill Error: {exception.Message} | {exception.StackTrace}"));
telemetryClient.TrackExceptionEx(exception, context.Activity);
};

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 AutoSaveStateMiddleware(botStateSet));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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 CalendarSkill.Bots
{
public class DialogBot<T> : ActivityHandler
where T : Dialog
{
private readonly IBotTelemetryClient _telemetryClient;
private DialogSet _dialogs;

public DialogBot(IServiceProvider serviceProvider, T dialog)
{
var conversationState = serviceProvider.GetService<ConversationState>() ?? throw new ArgumentNullException(nameof(ConversationState));
_telemetryClient = serviceProvider.GetService<IBotTelemetryClient>() ?? throw new ArgumentNullException(nameof(IBotTelemetryClient));

var dialogState = conversationState.CreateProperty<DialogState>(nameof(CalendarSkill));
_dialogs = new DialogSet(dialogState);
_dialogs.Add(dialog);
}

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken 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;
}

var dc = await _dialogs.CreateContextAsync(turnContext);

if (dc.ActiveDialog != null)
{
var result = await dc.ContinueDialogAsync();
}
else
{
await dc.BeginDialogAsync(typeof(T).Name);
}
}
}
}

This file was deleted.

Loading