How to defer a response in the Microsoft Bot Framework

I am using Microsoft Bot Framework FormFlow so that the user can fill out the form. Having completed this, the Dialog ends, and the method specified for the ResumeWith parameter (in this case quoteComplete ) is executed:

 var quoteForm = new FormDialog<Quote>(new Quote(), quoteFormBuilder.BuildForm, FormOptions.PromptInStart); context.Call<Quote>(quoteForm, quoteComplete); 

In quoteComplete I want the bot to tell the user that he is receiving a quote and that it may take a few seconds. Then an asynchronous call is made to execute the quote, and after that I want the bot to show another message with the quote value:

 await context.PostAsync("I will now calculate your quote. I won't be long..."); context.Wait(MessageReceived); //Simulate getting the quote Task.Delay(5000).ContinueWith(t => { context.PostAsync("Your quote is ÂŖ133.54"); }); 

I also tried the following advice in the documentation for posting multiple answers, putting this in Delay().ContinueWith :

 var message = context.MakeMessage(); message.Text = "Your quote is for ÂŖ133.54"; var connector = new ConnectorClient(); connector.Messages.SendMessage(message); 

However, I get an Access Denied error for this.

+5
source share
2 answers

Try creating the client instance as follows.

 using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message)) { var client = scope.Resolve<IConnectorClient>(); client.Messages.SendMessage(message); } 
+2
source

You should be able to use ConnectorClient to send a response to an incoming message as soon as your async task gets the result

Below is a link to the documentation

0
source

All Articles