【问题标题】:Recognizing Adaptive Card Clicks on Web app bot识别 Web 应用程序机器人上的自适应卡片点击
【发布时间】:2019-12-03 22:05:34
【问题描述】:

我的自适应卡片无法识别网络应用程序机器人上的点击,但正在我的本地机器人模拟器上工作

受保护的覆盖异步任务 OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancelToken) { Logger.LogInformation("正在运行带有消息活动的对话框。");

        if (turnContext.Activity.Type == ActivityTypes.Message)
        {
            string temp1 = turnContext.Activity.ChannelData.ToString();
            string boolean = "false";
            Logger.LogInformation(temp1.Length.ToString());
            int len = temp1.Length;
            if (len > 70)
            {


                if (temp1.Substring(70, 4) != null)
                    boolean = temp1.Substring(70, 4);
                Logger.LogInformation(temp1.Substring(70, 4));
                if (boolean.Equals("true"))
                    boolean = "True";
                else { boolean = "True"; }
                Logger.LogInformation(boolean);
                bool entry = System.Convert.ToBoolean(boolean);

                if (entry)
                {
                    JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());

                    string command = commandToken["action"].Value<string>();
                    string commandPrompt = command;

/* 这是识别点击的地方*////

                    if (commandPrompt.Equals("order"))
                    {
                        string[] paths = { ".", "Cards", "orderCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);

                        await turnContext.SendActivityAsync(response, cancellationToken);
                    }
                    else if (command.ToLowerInvariant() == "inventory")
                    {
                        string[] paths = { ".", "Cards", "InventoryCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);
                    }
                    else if (command.ToLowerInvariant() == "somethingelse")
                    {
                        commandPrompt = "somethingelse";
                        await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
                    }
                    else if (command.ToLowerInvariant() == "ordernumber")
                    {
                        string[] paths = { ".", "Cards", "orderNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);
                    }
                    else if (command.ToLowerInvariant() == "upsordernumber")
                    {
                        string[] paths = { ".", "Cards", "upsOrderNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);

                    }
                    else if (command.ToLowerInvariant() == "trackingnumber")
                    {
                        string[] paths = { ".", "Cards", "trackingNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);

                    }
                    else if (command.ToLowerInvariant() == "trackingnumber")
                    {
                        string[] paths = { ".", "Cards", "trackingNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);

                    }
                    else if (command.ToLowerInvariant() == "skunumber")
                    {
                        string[] paths = { ".", "Cards", "skuNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);

                    }
                    else if (command.ToLowerInvariant() == "ponumber")
                    {
                        string[] paths = { ".", "Cards", "poNumberCard.json" };
                        string fullPath = Path.Combine(paths);
                        var welcomeCard = CreateAdaptiveCardAttachment(fullPath);
                        var response = CreateResponse(turnContext.Activity, welcomeCard);
                        await turnContext.SendActivityAsync(response, cancellationToken);

                    }
                    else
                    {
                        await turnContext.SendActivityAsync($"I'm sorry, I didn't understand that. Please try again", cancellationToken: cancellationToken);
                    }
                }
            }
            else
            {
                await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
            }
        }

        // Run the Dialog with the new message Activity.

    }
}

}

/*Json File*/
{
  "type": "AdaptiveCard",
  "selectAction": {
    "type": "Action.Submit"
  },
  "body": [
    {
      "type": "Container",
      "items": [
        {
          "type": "TextBlock",
          "size": "Medium",
          "weight": "Bolder",
          "text": "Hi How can I help you today?"
        }
      ]
    },
    {
      "type": "Container",
      "items": [
        {
          "type": "TextBlock",
          "text": "Please select one of the following options to get started",
          "wrap": true
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "id": "orderButton",
      "title": "Order",
      "data": {
        "action": "order"
      }
    },
    {
      "type": "Action.Submit",
      "id": "inventoryButton",
      "title": "Inventory",
      "data": {
        "action": "inventory"
      }
    },
    {
      "type": "Action.Submit",
      "id": "somethingelseButton",
      "title": "Something Else",
      "data": {
        "action": "somethingElse"
      }
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}

/Json 文件/

webappbot 上没有错误输出只是不会打开下一张卡片。但正在我的机器人模拟器上工作

【问题讨论】:

  • 您如何测试部署的机器人? Likely related
  • iframe 嵌入我的网站,由 azure 提供。

标签: c# visual-studio botframework


【解决方案1】:

问题是“网络聊天中的测试”和网络聊天 iFrame 代码仍然使用 WebChat V3,它不能很好地支持自适应卡片。 WebChat V4 应该会在接下来的几周内向这两个平台推出。

同时,您可以从&lt;embed&gt; 切换到WebChat Samples 之一

【讨论】:

    猜你喜欢
    • 2019-08-26
    • 2022-01-28
    • 2020-07-29
    • 2020-04-11
    • 2021-05-01
    • 1970-01-01
    • 2018-10-17
    • 2020-11-14
    • 2020-09-28
    相关资源
    最近更新 更多