recieving item in child Dialog from context.Forward(T item)
var dialog = new EchoDialog();
await context.Forward(dialog, DialogDone, item, CancellationToken.None);
the forward method uses the IPostToBot.PostAsync(T item) method to post an item to the child dialog. But i'm not able to find the item in my new dialog:
async Task IDialog<object>.StartAsync(IDialogContext context)
{
context.Wait(next);
}
You can Wait() to get the message. Forward() puts the message on the BotContext and eventually calls StartAsync on the dialog you passed, so technically you could read the message directly off of the IDialogContext, but I recommend doing context.Wait() and then reading the message from the method you pass into the Wait().
public async Task StartAsync(IDialogContext context)
{
//Since a message is passed along when using IDialogContext.Forward(), read it first
context.Wait(MessageReceivedAsync);
}
async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> message)
{
var msg = await message;
//Do stuff with msg here
}
that sounds logic, and i also get into MessageReceivedAsync. But when I try to await the message, i get a Exception: Stack is empty [File of type 'text/plain']
I tried to access my Dialog with different types of Dialogs and i also changed the generic Type of IAwaitable, but it is always the same, i cannot acces the message.
The primary purpose of Forward is to reuse a child dialog that is "reactive", where the child dialog (in StartAsync) waits for a T with some ResumeAfter
So it's much more common that T is an IMessageActivity, because almost nobody writes dialogs that wait for other types.
So @fingejo you would "find the item" in the first ResumeAfter
(most people just use Call directly)
@willportnoy thankyou for your detailed explanation. I was able to figure out my problem with your explanation That is my solution now:
public async Task Bildersuche(IDialogContext context, IAwaitable<IMessageActivity> argument, LuisResult result)
{
//BilderDialog.lresult = result;
var a = await argument;
a.Text = result.Entities[0].Entity;
var dialog = new BilderDialog();
await context.Forward(dialog, DialogDone, a, CancellationToken.None);
}
public async Task bilder(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
string b = "";
var c = await argument;
I am now able to recieve my item. It had to be an IMessageActivity. So i just cloned the information from LuisDialog i needed into it.