Reputation: 280
I am using IActivityLogger to log the conversation between bot and user. Here the logger is logging all the messages except the text is being generated by PromptDialog.Choice()
I have tested for other methods of PromptDialog like
PromptDialog.Confirm()
PromptDialog .Text()
These are working i meant text from these methods are being logged, only the PromptDialog.Choice text is not hitting the IActivityLogger.
Logger.cs
public class Logger : IActivityLogger
{
public async Task LogAsync(IActivity activity)
{
Debug.WriteLine(activity.AsMessageActivity()?.Text);
}
}
RootDialog.cs
public async Task StartAsync(IDialogContext context)
{
string[] choices = new string[]{ "choice 1" , "choice 2"};
PromptDialog.Choice(context, resumeAfterPrompt, choices, "please choose an option.");
}
private async Task resumeAfterPrompt(IDialogContext context, IAwaitable<object> result)
{
await context.PostAsync((await result).ToString());
context.Done<object>(null);
}
Every other to and from messages are going through the Logger class except the PromptDialog.Choice() from the RootDialog.
Upvotes: 1
Views: 178
Reputation: 3426
I very briefly tested this, but it should work. If inside your IActivityLogger
implementation you drill down farther than just activity.text
. Some Activities may need and you can do it by simply using some if statements. I think there are more cases you will need to drill down into an activity for more than just the activity.text property than just this case. So using a similar strategy to log the information you would like to log for other unique types of content should work for you.
Something like this for example:
public class Logger : IActivityLogger
{
public async Task LogAsync(IActivity activity)
{
IMessageActivity a = activity.AsMessageActivity();
//loop through for cases there are multiple attachments
for (int i = 0; i < a.Attachments.Count; i++)
{
//in the case of herocard
if (a.Attachments[i].ContentType == "application/vnd.microsoft.card.hero")
{
//log something, i randomly picked a property
Debug.WriteLine(a.Attachments[i].Name);
}
//another case
if (a.Attachments[i].ContentType.Contains("image"))
{
//Maybe save the image somewhere
}
}
Debug.WriteLine(activity.AsMessageActivity()?.Text);
}
}
Upvotes: 1
Reputation: 27805
the PromptDialog.Choice text is not hitting the IActivityLogger
I create a sample and try to reproduce the issue, I find that it can hit the logger when I selected a option from PromptDialog.Choice
options list.
RootDialog:
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
string[] choices = new string[] { "choice 1", "choice 2" };
PromptDialog.Choice(context, resumeAfterPrompt, choices, "please choose an option.");
}
private async Task resumeAfterPrompt(IDialogContext context, IAwaitable<string> result)
{
string choice = await result;
await context.PostAsync($"You sent {choice}");
//context.Done<object>(null);
}
}
Logger:
public class DebugActivityLogger : IActivityLogger
{
public async Task LogAsync(IActivity activity)
{
Debug.WriteLine(activity.AsMessageActivity()?.Text);
}
}
Emulator test result:
VS Output window:
Besides, if you set breakpoint inside your Logger to debug and trace the activity, you would find the activity.AsMessageActivity()?.Text
will be ""
when it renders a HeroCard to prompt user for one of a set of choices.
So a empty string will be written to VS Output window.
Upvotes: 3