简体   繁体   English

如何使用自适应卡中的数据?

[英]How can I use the data from an adaptive Card?

I have a chatbot that sends an adaptive card asking a question that looks like this.我有一个聊天机器人,它发送一张自适应卡片,询问一个看起来像这样的问题。 Adaptive Card自适应卡

When an option is pressed, I want to be able to use the data from this card inside of my code.当按下一个选项时,我希望能够在我的代码中使用这张卡中的数据。 The JSON file for my card is this:我的卡的 JSON 文件是这样的:

  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "speak": "Somone is trying to take your session.",
  "body": [
    {
      "type": "TextBlock",
      "text": "Someone is taking your session!"
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Allow",
      "data": {
        "Value": "allow"
      }
    },
    {
      "type": "Action.Submit",
      "title": "Deny",
      "data": {
        "Value": "deny"
      }
    }
  ]
}

I know the bot is receiving something from the card as the event OnMessageActivityAsync is being raised.我知道当OnMessageActivityAsync事件被引发时,机器人正在从卡中接收一些东西。 When I use this bot in the bot framework emulator, it shows here that it IS returning a value.当我在机器人框架模拟器中使用这个机器人时,它在这里显示它正在返回一个值。 JSON Response JSON 响应

How can I use this data in my program for a task such as deciding whether the session can be taken in C#?如何在我的程序中将这些数据用于一项任务,例如决定 session 是否可以在 C# 中使用?

I solved It by using我通过使用解决了它

var val = turnContext.Activity.Value;
            string value = Convert.ToString(val);
            return value;

I was using strings and because of the conversion issue I could not find how to access this.我使用的是字符串,由于转换问题,我找不到如何访问它。 By switching it to var solved the issue.通过将其切换为var解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM