[Question] Is there a way to pass the original message through the Chain?
I'm implementing a Chain with 3 levels of dialogs. Think about Dialog 1 and Dialog 2 in the chain as pre-requisites for executing the logic of Dialog 3. The logic to be executed in Dialog 3 will depend on the original message. So the original message, needs to go through Dialog 1, 2 and get to Dialog 3.
Currently, I'm implementing this by having a class that holds the original message and that it's the input/output of the dialogs that I'm using.
return Chain.PostToChain()
.ContinueWith<Message, MyObject>(CallbackWithDialog1)
.ContinueWith<MyObject, MyObject>(CallbackWithDialog2)
.ContinueWith<MyObject, MyObject>(CallbackWithDialog3);
Is there any other way (already implemented in the framework) to pass the original message through the chain without having to manually do it? Also, does it change anything if the Dialog 3 is a LUIS Dialog?
Thanks, Ez.
If you're willing to use the reflection serialization surrogate, you can also reference the message in the shared lexical environment that contains your "return" statement. However, we generally dis-recommend using the reflection surrogate because of the risk of capturing "too much" and serializing it.
If you use linq query syntax, then successive "from" clauses will automatically be rewritten by the compiler to pass your message and other data along (rather than your manually written MyObject) - something like this from the examples:
var query = from x in new PromptDialog.PromptString("p1", "p1", 1)
from y in new PromptDialog.PromptString("p2", "p2", 1)
select string.Join(" ", x, y);
By the time the select executes, the type includes the result x and y packaged together by the compiler. Maybe that would help - tell us if there's some modifications we can apply to make that easier for you.
Thanks for your response @willportnoy. I'm not sure if I'm following you. Doesn't that depends on the output of the dialog?
I may haven't been clear with my question. Here is a more concrete example.
Let's say that I'm starting the conversation in this way:
return await Conversation.SendAsync(message, MakeRoot);
Where MakeRoot is
`private static IDialog
return Chain.PostToChain()
.ContinueWith<Message, string>(async (ctx, arg) =>
{
Message msg = await arg;
return Chain.ContinueWith<string, string>(new MyDialog1(msg), Callback1);
})
.ContinueWith<string, string>(async (ctx, res) =>
{
string resultFromFirstDialog = await res;
return Chain.ContinueWith<string, string>(new MyDialog2(resultFromFirstDialog), Callback2);
})
.ContinueWith<string, string>(async (ctx, res) =>
{
string resultFromSecondDialog = await res;
return Chain.ContinueWith<string, string>(new MyLuisDialog(resultFromSecondDialog), Callback3);
});
}`
Now, I send the message "List employees". And I need to get the "List employees" message (just the text in my case) in the third dialog (MyLuisDialog). What I'm trying to avoid is to have to return the original message or an object containing the dialog result & and the original message in the context.Done of each of the dialogs. I know that if I do that, I will get the original message because the output of the fist dialog will be that object that will end up being the input of the second dialog and so on.
Ideally each of the dialogs can return their results but also the dialogs can access to some kind of "context" that has the original message ("List employees" in this case) that initiated the conversation. Maybe the recommended approach here is just to store the original message in the PerUserPerConversation data bag in the first dialog so the other dialogs can access to it?
The Chain is great and I understand that the goal is to pass the output of the antecedent dialog to the next dialog in the chain; though it will be nice if every member of the chain can access to the original message/the input of the first dialog.
If you use linq query syntax, it can help with threading additional data through the chained IDialogs. But using the bot data bags is another reasonable method. Part of the reason we don't expose the Message on the IDialogContext is that we wanted to support proactive bots that send messages to the user without any incoming message to get them started.
I'm going to close this issue for now, but feel free to re-open to discuss more.