This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skills] update to ActivityHandler (#2667)
- Loading branch information
Showing
23 changed files
with
254 additions
and
201 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
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
55 changes: 55 additions & 0 deletions
55
skills/csharp/experimental/automotiveskill/Bots/DefaultActivityHandler.cs
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,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
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 AutomotiveSkill.Bots | ||
{ | ||
public class DefaultActivityHandler<T> : ActivityHandler | ||
where T : Dialog | ||
{ | ||
private readonly Dialog _dialog; | ||
private readonly BotState _conversationState; | ||
private readonly BotState _userState; | ||
private IStatePropertyAccessor<DialogState> _dialogStateAccessor; | ||
|
||
public DefaultActivityHandler(IServiceProvider serviceProvider, T dialog) | ||
{ | ||
_dialog = dialog; | ||
_conversationState = serviceProvider.GetService<ConversationState>(); | ||
_userState = serviceProvider.GetService<UserState>(); | ||
_dialogStateAccessor = _conversationState.CreateProperty<DialogState>(nameof(DialogState)); | ||
} | ||
|
||
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default) | ||
{ | ||
await base.OnTurnAsync(turnContext, cancellationToken); | ||
|
||
// Save any state changes that might have occured during the turn. | ||
await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken); | ||
await _userState.SaveChangesAsync(turnContext, false, cancellationToken); | ||
} | ||
|
||
protected override Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
|
||
protected override Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
|
||
protected override Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
skills/csharp/experimental/automotiveskill/Bots/DialogBot.cs
This file was deleted.
Oops, something went wrong.
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
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
55 changes: 55 additions & 0 deletions
55
skills/csharp/experimental/bingsearchskill/Bots/DefaultActivityHandler.cs
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,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
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 BingSearchSkill.Bots | ||
{ | ||
public class DefaultActivityHandler<T> : ActivityHandler | ||
where T : Dialog | ||
{ | ||
private readonly Dialog _dialog; | ||
private readonly BotState _conversationState; | ||
private readonly BotState _userState; | ||
private IStatePropertyAccessor<DialogState> _dialogStateAccessor; | ||
|
||
public DefaultActivityHandler(IServiceProvider serviceProvider, T dialog) | ||
{ | ||
_dialog = dialog; | ||
_conversationState = serviceProvider.GetService<ConversationState>(); | ||
_userState = serviceProvider.GetService<UserState>(); | ||
_dialogStateAccessor = _conversationState.CreateProperty<DialogState>(nameof(DialogState)); | ||
} | ||
|
||
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default) | ||
{ | ||
await base.OnTurnAsync(turnContext, cancellationToken); | ||
|
||
// Save any state changes that might have occured during the turn. | ||
await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken); | ||
await _userState.SaveChangesAsync(turnContext, false, cancellationToken); | ||
} | ||
|
||
protected override Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
|
||
protected override Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
|
||
protected override Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); | ||
} | ||
} | ||
} |
Oops, something went wrong.