Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // Licensed under the MIT License.
- using System.Collections.Generic;
- using System.Globalization;
- using System.Reflection;
- using System.Resources;
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.Bot.Builder;
- using Microsoft.Bot.Schema;
- using Microsoft.Bot.Builder.Dialogs;
- using Microsoft.Extensions.Logging;
- namespace myNamedBot
- {
- public class EmptyBot<T> : ActivityHandler
- where T : Dialog
- {
- protected readonly Dialog Dialog;
- protected readonly ILogger Logger;
- protected readonly BotState ConversationState;
- protected readonly BotState UserState;
- public EmptyBot(ConversationState conversationState, UserState userState, T dialog, ILogger<EmptyBot<T>> logger)
- {
- Dialog = dialog;
- Logger = logger;
- ConversationState = conversationState;
- UserState = userState;
- }
- protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
- {
- ResourceManager rm = new ResourceManager("myNamedBot.messages", Assembly.GetExecutingAssembly());
- foreach (var member in membersAdded)
- {
- if (member.Id != turnContext.Activity.Recipient.Id)
- {
- await turnContext.SendActivityAsync(MessageFactory.Text(rm.GetString("myFirstIntent")), cancellationToken);
- }
- }
- }
- public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
- {
- 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 async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
- {
- // Run the Dialog with the new message Activity.
- await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement