2017-04-26 4 views
0

私はformflowを使用しています。ユーザーが既に挨拶されているかどうかを知るためにプロパティを設定しようとしています。問題なくデータを設定します。( "Greet" true);)、 私は通常、設定後にプロパティをチェックしますが、次の実行時にプロパティの値を取得しようとしたときに(userData.GetProperty( "Greet"))保存されません。ユーザーが挨拶した後、フォームフローを終了し、qnadialogを試してみるように、これが必要です。Botdata.SetPropertyはその値を保存しません

MessageController

public async Task<HttpResponseMessage> Post([FromBody]Activity activity) 
    { 
     if (activity.Type == ActivityTypes.Message) 
     { 
      //ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
      //await Conversation.SendAsync(activity,() => new QnADialog()); 

      #region Formflow 

      // Get any saved values 
      StateClient sc = activity.GetStateClient(); 
      BotData userData = sc.BotState.GetPrivateConversationData(
       activity.ChannelId, activity.Conversation.Id, activity.From.Id); 
      var boolProfileComplete = userData.GetProperty<bool>("ProfileComplete"); 
      if (!boolProfileComplete) 
      { 
       // Call our FormFlow by calling MakeRootDialog 
       await Conversation.SendAsync(activity, MakeRootDialog); 
      } 
      else 
      { 
       //Check if Personalized Greeting is done 
       if (userData.GetProperty<bool>("Greet")) 
       { 
        ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
        await Conversation.SendAsync(activity,() => new QnADialog()); 
       } 
       else 
       { 
        // Get the saved profile values 
        var Name = userData.GetProperty<string>("Name"); 
        userData.SetProperty<bool>("Greet", true); 
        sc.BotState.SetUserData(activity.ChannelId, activity.From.Id, userData); 
        ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
        Activity replyMessage = activity.CreateReply(string.Format("Hi {0}!", Name)); 
        await connector.Conversations.ReplyToActivityAsync(replyMessage); 
       } 
      } 
      #endregion 
     } 
     else 
     { 
      HandleSystemMessage(activity); 
     } 
     var response = Request.CreateResponse(HttpStatusCode.OK); 
     return response; 
    } 

FormFlow

[Serializable] 
public class ProfileForm 
{ 
    // these are the fields that will hold the data 
    // we will gather with the form 
    [Prompt("What is your name? {||}")] 
    public string Name; 

    // This method 'builds' the form 
    // This method will be called by code we will place 
    // in the MakeRootDialog method of the MessagesControlller.cs file 
    public static IForm<ProfileForm> BuildForm() 
    { 
     return new FormBuilder<ProfileForm>() 
       .Message("Welcome to the profile bot!") 
       .OnCompletion(async (context, profileForm) => 
       { 
        // Set BotUserData 
        context.PrivateConversationData.SetValue<bool>("ProfileComplete", true); 
        context.PrivateConversationData.SetValue<string>("Name", profileForm.Name); 
        // Tell the user that the form is complete 
        await context.PostAsync("Your profile is complete."); 
       }) 
       .Build(); 
    } 
} 
+0

はsetuserdataを追加しました。しかし、まだエラーが残る – anonymous1110

答えて

0

あなたのコントローラでは、あなたが最初のプライベートな会話のデータストアを取得し、その後のuserdataデータストアに設定します。このように、プライベートな会話ストアへの変更は、プライベートな会話データストアに保存されることはありません。

sc.BotState.SetPrivateConversationData(activity.ChannelId, activity.Conversation.Id, activity.From.Id, userData); 

変更

sc.BotState.SetUserData(activity.ChannelId, activity.From.Id, userData); 

+0

これは魅力のように動作します!また、これが会話をqnadialogに転送する正しい方法であれば、私を助けることができますか?それは動作しないようです。それでもフォームダイアログが表示されます(この選択はあなたの選択ですか?) Conversation.SendAsync(activity、()=> new QnADialog()); – anonymous1110

+0

それは動作しないようです。それでもフォームダイアログが作成されます。だから私の名前を尋ね続けます。 – anonymous1110

+0

あなたのコントローラには 'Conversation.SendAsync(..)'しかありません。 このメソッドを初めて呼び出すと、会話スタックにルートダイアログが作成されます。その最初の呼び出しの後、アクティビティを会話スタックの最上部(これはあなたのフォームです)に転送します。正しく行うには、フォーム呼び出しのResumeAfterメソッドでQnADialogを開始する必要があります。 –

関連する問題