簡體   English   中英

識別Web應用程序機器人上的自適應卡點擊

[英]Recognizing Adaptive Card Clicks on Web app bot

我的自適應卡無法識別對Web應用程序機器人的點擊,但正在使用我的本地機器人模擬器

受保護的重寫異步任務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上沒有錯誤輸出,只是不會打開下一張卡。 但是正在使用我的機器人模擬器

問題是“在Web聊天中測試”和Web聊天iFrame代碼仍然使用WebChat V3,它不能很好地支持自適應卡。 WebChat V4應該在接下來的幾周內同時推廣到這兩個平台。

同時,您可以從<embed>切換到WebChat示例之一

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM