Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3.  
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Reflection;
  7. using System.Resources;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using Microsoft.Bot.Builder;
  11. using Microsoft.Bot.Schema;
  12. using Microsoft.Bot.Builder.Dialogs;
  13. using Microsoft.Extensions.Logging;
  14.  
  15. namespace myNamedBot
  16. {
  17.     public class EmptyBot<T> : ActivityHandler
  18.                 where T : Dialog
  19.  
  20.     {
  21.         protected readonly Dialog Dialog;
  22.         protected readonly ILogger Logger;
  23.         protected readonly BotState ConversationState;
  24.         protected readonly BotState UserState;
  25.  
  26.         public EmptyBot(ConversationState conversationState, UserState userState, T dialog, ILogger<EmptyBot<T>> logger)
  27.         {
  28.             Dialog = dialog;
  29.             Logger = logger;
  30.             ConversationState = conversationState;
  31.             UserState = userState;
  32.  
  33.         }
  34.  
  35.         protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
  36.         {
  37.  
  38.             ResourceManager rm = new ResourceManager("myNamedBot.messages", Assembly.GetExecutingAssembly());
  39.  
  40.             foreach (var member in membersAdded)
  41.             {
  42.                 if (member.Id != turnContext.Activity.Recipient.Id)
  43.                 {
  44.                     await turnContext.SendActivityAsync(MessageFactory.Text(rm.GetString("myFirstIntent")), cancellationToken);
  45.                 }
  46.             }
  47.         }
  48.  
  49.         public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
  50.         {
  51.             await base.OnTurnAsync(turnContext, cancellationToken);
  52.  
  53.             // Save any state changes that might have occured during the turn.
  54.             await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
  55.             await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
  56.  
  57.         }
  58.  
  59.         protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
  60.         {
  61.  
  62.             // Run the Dialog with the new message Activity.
  63.             await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement