简体   繁体   中英

How to send message after inactivity time with Bot Framework C# SDK?

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 tried to replace my PromptChoice with just a context.sendAsync("Hi"), no exception here but message never be sent to the emulator.

If somebody have an idea on the way to do this, i would be grateful.

EDIT:

i use this sample to do the job:

            using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
            {
                var botData = scope.Resolve<IBotData>();
                await botData.LoadAsync(CancellationToken.None);
                IDialogTask task = scope.Resolve<IDialogTask>();

                //interrupt the stack
                var dialog = new InactivityDialog();
                task.Call(dialog.Void<object, IMessageActivity>(), null);
                //stack.Post<InactivityDialog>(dialog, (c, item) => { return Task.CompletedTask; });
                await task.PollAsync(CancellationToken.None);

                //flush dialog stack
                await botData.FlushAsync(CancellationToken.None);

            }

and this in my static messageController:

    var builder = new ContainerBuilder();
builder.Register(c => ((ClaimsIdentity)HttpContext.Current.User.Identity).GetCredentialsFromClaims())
           .AsSelf()
           .InstancePerLifetimeScope();
builder.Update(Conversation.Container);

But the HttpContext.Current is null when it try to resolve IBotData from the scope

That functionality isn't in the bot framework right now. You would have to create your own custom code where you save the conversation information & update your own timer if there's been activity.

https://github.com/Microsoft/BotBuilder/issues/837

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM