C# 捕捉卡片按钮单击活动。文本为空
我已经创建了一张新卡。当用户单击按钮时,应该会捕捉到C# 捕捉卡片按钮单击活动。文本为空,c#,botframework,azure-bot-service,C#,Botframework,Azure Bot Service,我已经创建了一张新卡。当用户单击按钮时,应该会捕捉到 var card = new HeroCard { Title = "Welcome ", Text = "Click the buttons below to update this card", Buttons = new List<CardAction>
var card = new HeroCard
{
Title = "Welcome ",
Text = "Click the buttons below to update this card",
Buttons = new List<CardAction>
{
new CardAction
{
Type= ActionTypes.MessageBack,
Title = "Update Card",
Text = "UpdateCardAction",
DisplayText = "UpdateCardAction",
Value = new JObject { { "count", 0 } }
},
new CardAction(ActionTypes.OpenUrl, "Get an overview", null, "Get an overview", "Get an overview", "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0"),
}
};
await turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment()));
var卡=新卡
{
Title=“欢迎”,
Text=“单击下面的按钮更新此卡”,
按钮=新列表
{
新名片
{
Type=ActionTypes.MessageBack,
Title=“更新卡”,
Text=“UpdateCardAction”,
DisplayText=“UpdateCardAction”,
值=新作业对象{{“计数”,0}
},
新的CardAction(ActionTypes.OpenUrl,“获取概览”,null,“获取概览”,“获取概览”https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0“,
}
};
等待turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment());
检查按钮的方法
messageActivityAsync上的受保护覆盖异步任务(iTurContext turnContext,CancellationToken CancellationToken)
{
turnContext.Activity.RemoveRecipientTitle();
开关(turnContext.Activity.Text.Trim())
{
................
问题
然而,当用户单击按钮时,它不会被捕获,因为turnContext.Activity.Text始终为空。当使用ActionTypes.MessageBack时,我们似乎无法获得Text属性
var card = new HeroCard
{
Title = "Welcome ",
Text = "Click the buttons below to update this card",
Buttons = new List<CardAction>
{
new CardAction
{
Type= ActionTypes.MessageBack,
Title = "Update Card",
Text = "UpdateCardAction",
DisplayText = "UpdateCardAction",
Value = new JObject { { "count", 0 } }
},
new CardAction(ActionTypes.OpenUrl, "Get an overview", null, "Get an overview", "Get an overview", "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0"),
}
};
await turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment()));
- 要获取值,您可以通过转到turnContext.Activity.value来访问它,在本例中,它将是作业对象{{“count”,0}
- 如果希望获得显示文本,可以执行以下操作
var channelData=JObject.FromObject(turnContext.Activity.channelData); var displayText=channelData[“messageBack”][“displayText”].ToString();