Guest User

Untitled

a guest
Dec 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. services.AddSingleton<ImageProcessingBotAccessors>(sp =>
  2. {
  3. var options = sp.GetRequiredService<IOptions<BotFrameworkOptions>>().Value;
  4. if (options == null)
  5. {
  6. throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the state accessors");
  7. }
  8.  
  9. var conversationState = options.State.OfType<ConversationState>().FirstOrDefault();
  10. if (conversationState == null)
  11. {
  12. throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors.");
  13. }
  14.  
  15. var userState = options.State.OfType<UserState>().FirstOrDefault();
  16.  
  17. if (userState == null)
  18. {
  19. throw new InvalidOperationException("User State mjust be defined and added befor the conversation scoping");
  20. }
  21.  
  22. // Create the custom state accessor.
  23. // State accessors enable other components to read and write individual properties of state.
  24. var accessors = new ImageProcessingBotAccessors(conversationState, userState)
  25. {
  26. ConversationDialogState = userState.CreateProperty<DialogState>(ImageProcessingBotAccessors.DialogStateName),
  27. CommandState = userState.CreateProperty<string>(ImageProcessingBotAccessors.CommandStateName)
  28.  
  29.  
  30. };
  31.  
  32. return accessors;
  33. });
Add Comment
Please, Sign In to add comment