Is it possible to return an Activity from a LuisDialog?
I understand that the "original" activity is needed to create a response with attachments from inside a Dialog like this:
public async Task ActivityReceivedAsync(IDialogContext context, IAwaitable
But, when I try to pass the activity as an argument to a LuisDialog to use it for the construction of the reply It always fails because the Activity Class is not marked as Serializable, it seems that in a LuisDialog you can only post text responses, my bot needs to respond with Attachments.
Thank you
You can use context.MakeMessage to get access to an activity for sending attachments.
If you want to pass activity to a child dialog, consider https://github.com/Microsoft/BotBuilder/issues/1082.
Also in the newest release, you can access the original incoming message from the intent handlers:
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/AlarmBot/Dialogs/AlarmLuisDialog.cs#L108
Ok, now I tried with this code:
var msj = context.MakeMessage(); msj.Text = "hello"; msj.Attachments.Add( new Attachment() { ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png", ContentType = "image/png", Name = "Bender_Rodriguez.png" } ); msj.AttachmentLayout = AttachmentLayoutTypes.List; await context.PostAsync(msj); context.Wait(MessageReceived);
It sends the response to the emulator but it also throws a SerializationException for the LuisResult Class, it says that it is not marked as serializable

It seems likely that you're storing the LuisResult as a class member within your dialog. Do you need it preserved while waiting for user input? If not, mark it with the [NonSerialized] attribute.
You are absolutely right, I had exactly that and I wasn't even using it. After I removed the unused field it works. Thanks!
[LuisIntent("YOUR_INTENT")]
public async Task METHOD(IDialogContext context, LuisResult result)
{
Activity response = ((Activity)context.Activity).CreateReply();
HeroCard card = new HeroCard(){ /* YOUR CARD CONTENT */};
response.Attachments.Add(card.ToAttachment());
await context.PostAsync(response);
}
I hope this helps!