当用户点击任何按钮时,我想得到按钮的标题。我如何实现这一点。我正在尝试找到解决方案,但找不到合适的解决方案。 我知道了
IActionActivity
用于在按钮点击上执行操作但我不知道如何实现该界面以在用户点击时获取按钮的标题
图片链接在下面给出
[BotAuthentication]
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.Message)
{
Options(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private void Options(Activity reply)
{
reply.Attachments = new List<Attachment>();
List<CardAction> cardButtons = new List<CardAction>();
CardAction Button1 = new CardAction()
{
Value = "Product is an interesting career choice.",
Type = "postBack",
Title = "Product"
};
CardAction Button2 = new CardAction()
{
Value = "Design is an interesting career choice.",
Type = "postBack",
Title = "Design"
};
CardAction Button3 = new CardAction()
{
Value = "Development is an interesting career choice.",
Type = "postBack",
Title = "Development"
};
CardAction Button4 = new CardAction()
{
Value = "Marketing is an interesting career choice.",
Type = "postBack",
Title = "Marketing"
};
CardAction Button5 = new CardAction()
{
Value = "Sales is an interesting career choice.",
Type = "postBack",
Title = "Sales"
};
CardAction Button6 = new CardAction()
{
Value = "Administration is an interesting career choice.",
Type = "postBack",
Title = "Administration"
};
cardButtons.Add(Button1);
cardButtons.Add(Button2);
cardButtons.Add(Button3);
cardButtons.Add(Button4);
cardButtons.Add(Button5);
cardButtons.Add(Button6);
HeroCard jobCard = new HeroCard()
{
Buttons = cardButtons
};
Attachment jobAttachment = jobCard.ToAttachment();
reply.Attachments.Add(jobAttachment);
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
}
}
答案 0 :(得分:0)
点击后,您将获得按钮的Value
。 Activity.Text
应该包含该值。
无论如何,我发现你正在控制器中完成所有工作。我建议改为使用Dialog
。