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

Expected Call have Wait

Open dashell-James opened this issue 9 years ago • 2 comments

I'm using the C# SDK for Bot Framework to develop a bot and i want my bot send a satisfaction message after a time without activity from the client.

I tried with Task but at first Task are not serializable so i can't store the task to Dispose it if i recieve a new message, and second PrompChoice throw a 'Microsoft.Bot.Builder.Internals.Fibers.InvalidNeedException' with the message : " invalid need: expected Call, have Wait"

i understand why , bot can be in both mode wait and call , but i don't know how to do this : Send a message if i don't receive message during 10s , and if i recieve a message during this timer , answer and reset the timer.

dashell-James avatar Mar 24 '17 10:03 dashell-James

I have the same scenario which I handle like that (with change variable names):

Have a static Dicitonary with ConversationId as Key and a System.Threading.Tasks.Timer as Value. When the conversation starts I add a timer:

var timer = new Timer(callbackMethod, dialogContext, timeoutVariable, -1);
timersDictionary.Add(conversationId, timer);

With the dialogContext I can create a normal response with:

private async void Callback(object state)
{
    var context = (IDialogContext) state;
    context.PostAsync("timeout");`
}

Whenever a message comes in I reset the timer:

if (timersDictionary.TryGetValue(context.GetConversationId(), out Timer timer))
{
    timer.Change(timeoutVariable, Timeout.Infinite);
}

ThisWillDoIt avatar Mar 24 '17 11:03 ThisWillDoIt

Note: Please only submit Bot Builder SDK bugs here. If you have general questions or implementation issues, please submit a question on Stack Overflow at http://stackoverflow.com/questions/tagged/botframework

tomlm avatar Mar 30 '17 15:03 tomlm