如何识别我们得到答案的机器人回复

时间:2017-11-20 16:06:05

标签: c# botframework

Bot按顺序使用来自网络聊天的后门事件生成多个问题  没有得到用户的回答。下面是两个问题的例子:

 //Question 1
 var reply = ((Activity)activity).CreateReply("Question 1");
 reply.Type = ActivityTypes.Message;
 reply.TextFormat = TextFormatTypes.Plain;

 reply.SuggestedActions = new SuggestedActions()
 {
      Actions = new List<CardAction>()
                   {
                        new CardAction() {Title = "Ans 1", Type = ActionTypes.ImBack, Value = "Ans 1"},
                        new CardAction() {Title = "Ans 2", Type = ActionTypes.ImBack, Value = "Ans 2"}
                     }
                };
 await connectorClient.Conversations.ReplyToActivityAsync(reply);   


 //Question 2 after 10 sec
 var reply = ((Activity)activity).CreateReply("Question 2");
 reply.Type = ActivityTypes.Message;
 reply.TextFormat = TextFormatTypes.Plain;

 reply.SuggestedActions = new SuggestedActions()
 {
      Actions = new List<CardAction>()
                   {
                        new CardAction() {Title = "Ans 1", Type = ActionTypes.ImBack, Value = "Ans 1"},
                        new CardAction() {Title = "Ans 2", Type = ActionTypes.ImBack, Value = "Ans 2"}
                     }
                };
 await connectorClient.Conversations.ReplyToActivityAsync(reply);   

如何在接收活动活动时识别用户在问题1或问题2上回答的问题?

1 个答案:

答案 0 :(得分:3)

解决方案非常简单,您需要做的就是使Value参数唯一。在代码中,它看起来像下面的代码段。您可能还想考虑使用ActionTypes.PostBack而不是ActionTypes.ImBack,这样用户实际上看不到Value

var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));
                var reply = ((Activity)activity).CreateReply("Question 1");
                reply.Type = ActivityTypes.Message;
                reply.TextFormat = TextFormatTypes.Plain;

                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = new List<CardAction>()
                    {
                        new CardAction() {Title = "Ans 1", Type = ActionTypes.PostBack, Value = "question 1 Ans 1"},
                        new CardAction() {Title = "Ans 2", Type = ActionTypes.PostBack, Value = "question 1 Ans 2"}
                    }
                };
                await connectorClient.Conversations.ReplyToActivityAsync(reply);


                //Question 2 after 10 sec
                reply = ((Activity)activity).CreateReply("Question 2");
                reply.Type = ActivityTypes.Message;
                reply.TextFormat = TextFormatTypes.Plain;

                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = new List<CardAction>()
                    {
                        new CardAction() {Title = "Ans 1", Type = ActionTypes.PostBack, Value = "question 2 Ans 1"},
                        new CardAction() {Title = "Ans 2", Type = ActionTypes.PostBack, Value = "question 2 Ans 2"}
                    }
                };
                await connectorClient.Conversations.ReplyToActivityAsync(reply);