I'm building a ChatBot in C# and I want that after some messages the conversation stop, but I don't know how to do it. I have already set a limit of messages, and I want that after the reach of this limit no more messages can be send. There is my code:
private int NombreDeMessages;
protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
{
var message = await item;
NombreDeMessages += 1;
if (message.Text != null && NombreDeMessages < 3)
{
await base.MessageReceived(context, item);
}
else
{
var reply = context.MakeMessage();
await context.PostAsync(reply);
context.Wait(this.MessageReceived);
}
}
I deleted the HeroCard part because it is useless here.
The thing that I want is after the context.Wait at the end, add a end of conversation so the user can't talk more to the chatbot.