botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Only handle latest message

Open srozga opened this issue 9 years ago • 6 comments

We have a C# Bot Builder bot that is sending 5 messages to the user with pauses in between. At the end of the 5th message, we use IDialogContext.Wait to receive the answer. Sometimes, during the 5 messages, a user would start typing in answers to IDialogs that do not expect an answer. The net effect is that by the time the 5th message comes and waits for an answer, the bot has built up a queue of messages from the user to answer to. Is there a way to ignore all messages from user except the last one?

srozga avatar Jan 17 '17 21:01 srozga

ugly workaround: you can define a bool in your messagescontroller, where you are recieving the messages. Use it to turn your message-handling on and off. Then you can turn your handling on and off from your Dialog by setting the bool.

fingejo avatar Jan 18 '17 08:01 fingejo

@fingejo this is my backup plan. was wondering if there is a better way to do this.

srozga avatar Jan 19 '17 15:01 srozga

i had a similar problem, where unrelated user answer returned from context.wait. and i did this:

.... request = DateTime.UtcNow; context.Wait(CheckName); .....

public async virtual Task CheckName(IDialogContext context, IAwaitable result) { if(context.Activity.Timestamp <= request) { context.Wait(CheckName); return; } ...

hlipa99 avatar Jan 22 '17 14:01 hlipa99

Thanks all. @hlipa99's approach is quite good for our use case and we've adopted it.

srozga avatar Feb 06 '17 15:02 srozga

@srozga @hlipa99 How do you manage this when you scale your bot?

ankitbko avatar Mar 13 '17 14:03 ankitbko

@ankitbko you could store the datetime in the conversation state.

srozga avatar Mar 26 '17 21:03 srozga