question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inject DialogContext to BoolExpression

See original GitHub issue

Is your feature request related to a problem? Please describe. On adaptive dialogs, I am trying to implement custom validation (eg. Calling external API with user input as parameter), custom retry message based on the response of API and store validation result on conversation state.

Describe the solution you’d like I would like BoolExpression to have a method that accepts Func<object, DialogContext, object>, an addition of DialogContext to existing method here

This way, I would be able to access ConversationState via dc.Context.TurnState.Get<ConversationState>() (not injecting ConversationState to dialog) and save validation result on ConversationState by creating property state accessors and calling SetAsync method

Describe alternatives you’ve considered

  • Storing ConversationState to dialog class: Still does not have access to DialogContext and TurnContext.

Haven’t tested storing DialogContext, as I thought changes on DialogContext between it is stored and custom validation not reflected on DialogContext.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tomlmcommented, Oct 23, 2020

You can’t do this declaratively with our current classes, but you can do this easily with custom classes.

For example, if you create a new class which derives from NumberInput and overrides OnRecognizeInputAsync() then you have access exactly to what you need to do your validatation, the dc and async<task>.

        /// <summary>
        /// Called when input has been received, override this method to customize recognition of the input.
        /// </summary>
        /// <param name="dc">dialogContext.</param>
        /// <param name="cancellationToken">the <see cref="CancellationToken"/> for the task.</param>
        /// <returns>InputState which reflects whether input was recognized as valid or not.</returns>
        protected abstract Task<InputState> OnRecognizeInputAsync(DialogContext dc, CancellationToken cancellationToken);

Something like this:

public class PartNumberInput : NumberInput
{
   // part number database connectionstring
   public StringExpression ConnectionString { get;set;} 
   
   protected override Task<InputState> OnRecognizeInputAsync(DialogContext dc, CancellationToken)
   {
       // call number database to validate
       return InputState;
   }
}

Register it as a custom component and now you have rich partnumber input with async validation.

0reactions
chrimc62commented, Oct 21, 2020

@tomlm Could you comment on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SetProperties class
Called when an event has been raised, using DialogContext.emitEvent() , by either the current dialog or a dialog that the current dialog started....
Read more >
Bot Framework: Pass DialogContext to ...
When constructing a DialogContext as coded below in the BotCallbackHandler method, I can use it to start a new Dialog using BeginDialogAsync ....
Read more >
How to use continueDialog function in DialogContext
The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system. * If no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found