Botframework-sdk: Issue with using multiple LUIS models

Created on 18 Jul 2016  路  13Comments  路  Source: microsoft/botframework-sdk

I have 2 luis dialogs and am trying to call one from another using context.Forward. However, I am getting the exception Microsoft.Bot.Builder.Internals.Fibers.InvalidTypeException at this line:

await context.Forward(new NextDialog(), ResumeAfter, result, CancellationToken.None);

Any suggestions on what the problem is?

Most helpful comment

All 13 comments

Just a guess: NextDialog implements a IDialog and your calling dialog (with the context.Forward call) implements IDialog - I believe it's required that T be assignable to S. I can look some more into it.

NextDialog and my calling dialog both implement a LuisDialog

Is result an IAwaitable < IMessageActivity > ? You would need to await it first before passing it to Forward.

No, result is a LuisResult. That line is inside of an intent handler, like this:

[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.Forward(new NextDialog(), ResumeAfter, result, CancellationToken.None);
}

You are forwarding LuisResult to a LuisDialog that is waiting for IAwaitable<IMessageActivity> in its OnMessageReceived(...) (This is the default implementation of LuisDialog). Either, you should forward an instance of IMessageActivity to the other LuisDialog or have your own implementation of IDialog that is waiting for IAwaitable<LuisResult> after start, if you want to forward the LuisResult.

Ok. What I am trying to do is go into NextDialog and into the correct intent handler based on what the user said. To do this, what would be the correct thing to forward to NextDialog? Since from where I am calling context.Forward I only have context and result passed in, I just assumed that I should be forwarding the LuisResult result.
Do you have a suggestion on what would be a suitable instance of IMessageActivity to forward that would work?

you can keep the original message's text and create a new activity to be forwarded it to NextDialog like below:

private string userToBotText; 
protected async override Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
{
    userToBotText = (await item).Text; 
    await base.MessageReceived(context, item);
}

[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
    await context.Forward(new NextDialog(), ResumeAfter, new Activity { Text = userToBotText }, CancellationToken.None);
}

Also you can use result.Query to create the activity. Query is the original message's text, if you are using the base MessageReceived implementation.

That fixed it, thank you so much!

@msft-shahins, I know that this particular issue has been closed but my issue is quite similar to that so I hope you'd be able to answer it.

I have a PromptDialog.Choice and I want to do send the chosen option from the PromptDialog.Choice, how can I do that? In resumeAfter, it is of type string and what you have explained above is IMessageActivity.

Okay I could make it as IMessageActivity but MessageReceived wants IMessageActivity as IAwaitable there I have got stuck!

Thanks a lot. I did it using Awaitable.FromItem()

How can we use a yes/no question in Luis intent? if user inputs yes, the intent should resume . if user inputs no, the process has to stop

Was this page helpful?
0 / 5 - 0 ratings