c#bot framework - resumeafter中的DeleteStateForUser

时间:2017-04-18 12:34:22

标签: c# botframework

在表单构建器对话框后,是否可以在DeleteStateForUser中使用resumAfter来保留当前对话框?

    context.Call(searchFormDialog, this.ResumeAfterBuildSatisfactionForm);


    private IForm<SatisfactionQuery> BuildSatisfactionForm()
    {
        OnCompletionAsyncDelegate<SatisfactionQuery> processSearch = async (context, state) =>
        {
            await context.PostAsync($"Thx");
        };

        return new FormBuilder<SatisfactionQuery>()
            //.Message("")
            .AddRemainingFields()
            .OnCompletion(processSearch)
            .Build();
    }

private async Task ResumeAfterBuildSatisfactionForm(IDialogContext context, IAwaitable<SatisfactionQuery> result)
{
  //but i don't have Activity here :-(
activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId,activity.From.Id);
}

1 个答案:

答案 0 :(得分:1)

您可以使用ServiceUrl创建StateClient:

private async Task ResumeAfterBuildSatisfactionForm(IDialogContext context, IAwaitable<SatisfactionQuery> result)
{
    var msg = context.MakeMessage();
    var stateClient = new StateClient(new Uri(msg.ServiceUrl));
    stateClient.BotState.DeleteStateForUser(msg.ChannelId, msg.From.Id);
}