Activity.Text null 的抓取卡片按钮点击
Catching card button click with Activity.Text null
我创建了一张新卡片。当用户点击按钮时应该被捕获。
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()));
检查按钮的方法
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
turnContext.Activity.RemoveRecipientMention();
switch (turnContext.Activity.Text.Trim())
{
................
问题
为什么它没有捕捉到,因为当用户单击按钮时 turnContext.Activity.Text 始终为 null。
当使用ActionTypes.MessageBack时,似乎无法获取Text 属性
- 要获取 值,您可以通过转至 turnContext.Activity.Value 访问它,在本例中它将是JObject { { "count", 0 } }
如果您希望获得 DisplayText,您可以执行以下操作
var channelData = JObject.FromObject(turnContext.Activity.ChannelData);
var displayText = channelData["messageBack"]["displayText"].ToString();
我创建了一张新卡片。当用户点击按钮时应该被捕获。
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()));
检查按钮的方法
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
turnContext.Activity.RemoveRecipientMention();
switch (turnContext.Activity.Text.Trim())
{
................
问题
为什么它没有捕捉到,因为当用户单击按钮时 turnContext.Activity.Text 始终为 null。
当使用ActionTypes.MessageBack时,似乎无法获取Text 属性
- 要获取 值,您可以通过转至 turnContext.Activity.Value 访问它,在本例中它将是JObject { { "count", 0 } }
如果您希望获得 DisplayText,您可以执行以下操作
var channelData = JObject.FromObject(turnContext.Activity.ChannelData); var displayText = channelData["messageBack"]["displayText"].ToString();