botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

How to generate new post to Bot from class which extends LuisDialog<object>?

Open virendrak opened this issue 9 years ago • 9 comments

I have created one C# Bot Framework application. I'm displaying list of buttons in HeroCard based on LUIS intent. If user selects one button, that button text would be passed to other method (called DiasplayTraining as shown below) and displays respective information.

image

Please find below buttons which display in the HeroCard.

image

My DisplayTraining async method is as below,

image

If user entered/posted any text instead of selecting any button from above HeroCard, code goes to above highlighted else case, from this else block I should pass the text as new post to the bot. My else block statement await context.PostAsync(title) displays the text to me in the bot but not posting as new post.

Please help me how can I Post user entered text from above else block as new post to the Bot.

Thanks in Advance! V

virendrak avatar Dec 21 '16 12:12 virendrak

Are you asking how to disable threading for the message posted in the else block? You can call MakeMessage to construct an IMessageActivity and clear out the reply ID field before sending the message with PostAsync.

willportnoy avatar Dec 21 '16 17:12 willportnoy

@willportnoy , No, we are not looking to disable posting a message from else block, we are looking to post as new post which should be identified by our LUIDDialog. Currently value inside title is getting displayed but we want this value should be catch by intents in the LUISDialog.

virendrak avatar Dec 22 '16 09:12 virendrak

@virendrak you want to construct a new IMessageActivity (as if it came from the user to the bot) to be re-dispatched using the MessageReceived logic in LuisDialog?

willportnoy avatar Dec 26 '16 22:12 willportnoy

We are constructing IMessageActivity in block (as highlighted in question) as below.

IMessageActivity newPost = context.MakeMessage();
newPost.Text = title;
await context.PostAsync(newPost);
context.Wait(this.MessageReceived); 

But, it's not calling any intent in LUIS dialog. Just simply displaying the text.

virendrak avatar Dec 27 '16 14:12 virendrak

this should let you re-dispatch the activity on the same LuisDialog:

await MessageReceived(context, Awaitable.FromItem(context.Activity.AsMessageActivity()));

msft-shahins avatar Dec 27 '16 18:12 msft-shahins

as we see message definition in above question, context is IDialogContext type parameter, when i'm adding above your line of code it showing me following error, 'IDialogContext' does not contain a definition for 'Activity' and no extension method 'Activity' accepting a first argument of type 'IDialogContext' could be found (are you missing a using directive or an assembly reference? I couldn't find any assembly reference to resolve this.

RasheedSiriyala avatar Dec 28 '16 04:12 RasheedSiriyala

Have you updated to the latest bot builder nuget?

willportnoy avatar Dec 28 '16 05:12 willportnoy

Thank you @willportnoy its working after updating bot builder nuget, Thank you @msft-shahins your line helped us.

RasheedSiriyala avatar Dec 28 '16 05:12 RasheedSiriyala

@willportnoy, @msft-shahins Thank you so much for your help!!!

virendrak avatar Dec 28 '16 08:12 virendrak