gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:37:14 26 4
gpt4 key购买 nike

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);

如何在接收 Activity 事件时识别用户回答的是问题 1 还是问题 2?

最佳答案

解决这个问题的方法非常简单,您需要做的就是使 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);

关于c# - 如何识别我们得到答案的机器人回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47396225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com