【问题标题】:BotFramework Webchat channel cannot render cardBotFramework 微信频道无法渲染卡片
【发布时间】:2019-02-11 12:18:34
【问题描述】:

我在创建使用 AdaptiveShowCardAction 的卡片时遇到了困难。当我尝试创建一张简单的卡片时,它设法显示。

代码:

public override AdaptiveCard CherwellCard(UserProfile userProfile)
{
    try
    {
        foreach (var service in CherwellCategories)
        {
            var serviceCard = new AdaptiveShowCardAction()
            {
                Title = service.Name,
                Card = new AdaptiveCard()
                {
                    Body = new List<AdaptiveElement>()
                {
                    new AdaptiveTextBlock()
                    {
                        Text = TranslateHelper.GetText(userProfile.Locale, "ticket_category"),
                        Weight = AdaptiveTextWeight.Bolder,
                        Size =  AdaptiveTextSize.Medium
                    }
                },
                    Actions = new List<AdaptiveAction>()
                    {

                    }
                }
            };
            foreach (var category in service.Categories)
            {
                var categoryCard = new AdaptiveShowCardAction()
                {
                    Title = category.Name,
                    Card = new AdaptiveCard()
                    {
                        Body = new List<AdaptiveElement>()
                    {
                        new AdaptiveTextBlock()
                        {
                            Text = TranslateHelper.GetText(userProfile.Locale, "ticket_sub_category"),
                            Weight = AdaptiveTextWeight.Bolder,
                            Size =  AdaptiveTextSize.Medium
                        }
                    },
                        Actions = new List<AdaptiveAction>()
                        {
                        }
                    }
                };
                foreach (var subCategory in category.Categories)
                {
                    var subCategoryCard = new AdaptiveShowCardAction()
                    {
                        Title = subCategory.Name,
                        Card = new AdaptiveCard()
                        {
                            Body = new List<AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                Text = TranslateHelper.GetText(userProfile.Locale, "ticket_selection"),
                                Weight = AdaptiveTextWeight.Bolder,
                                Size =  AdaptiveTextSize.Medium
                            }
                        },
                            Actions = new List<AdaptiveAction>()
                            {
                            }
                        }
                    };
                    var ContinueDataJson = "{ \"Service\" : \"{0}\", \"Category\" : \"{1}\", \"SubCategory\" : \"{2}\"}";
                    ContinueDataJson = ContinueDataJson.Replace("{0}", service.Name).Replace("{1}", category.Name).Replace("{2}", subCategory.Name);

                    var finalCard = new AdaptiveShowCardAction()
                    {
                        Title = TranslateHelper.GetText(userProfile.Locale, "ticket_details"),
                        Card = new AdaptiveCard()
                        {
                            Body = new List<AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                Text = TranslateHelper.GetText(userProfile.Locale, "ticket_services"),
                                Weight = AdaptiveTextWeight.Bolder,
                                Size =  AdaptiveTextSize.Medium
                            },
                            new AdaptiveTextBlock()
                            {
                                Text = service.Name,
                                Weight = AdaptiveTextWeight.Lighter,
                                Size =  AdaptiveTextSize.Medium
                            },
                            new AdaptiveTextBlock()
                            {
                                Text = TranslateHelper.GetText(userProfile.Locale, "ticket_category"),
                                Weight = AdaptiveTextWeight.Bolder,
                                Size =  AdaptiveTextSize.Medium
                            },
                            new AdaptiveTextBlock()
                            {
                                Text = category.Name,
                                Weight = AdaptiveTextWeight.Lighter,
                                Size =  AdaptiveTextSize.Medium
                            },
                            new AdaptiveTextBlock()
                            {
                                Text = TranslateHelper.GetText(userProfile.Locale, "ticket_sub_category"),
                                Weight = AdaptiveTextWeight.Bolder,
                                Size =  AdaptiveTextSize.Medium
                            },
                            new AdaptiveTextBlock()
                            {
                                Text = subCategory.Name,
                                Weight = AdaptiveTextWeight.Lighter,
                                Size =  AdaptiveTextSize.Medium
                            }
                        },
                            Actions = new List<AdaptiveAction>()
                        {
                            new AdaptiveSubmitAction()
                            {
                                Title =  TranslateHelper.GetText(userProfile.Locale, "ticket_submit"),
                                DataJson = ContinueDataJson
                            }
                        }
                        }
                    };

                    subCategoryCard.Card.Actions.Add(finalCard);

                    categoryCard.Card.Actions.Add(subCategoryCard);
                }
                serviceCard.Card.Actions.Add(categoryCard);
            }
            serviceAction.Add(serviceCard);
        }

        AdaptiveCard card = new AdaptiveCard()
        {
            Body = new List<AdaptiveElement>()
        {
            new AdaptiveTextBlock()
            {
                Text = TranslateHelper.GetText(userProfile.Locale, "ticket_services"),
                Weight = AdaptiveTextWeight.Bolder,
                Size =  AdaptiveTextSize.Medium
            }
        },
            Actions = new List<AdaptiveAction>()
            {
            }
        };
        card.Actions.AddRange(serviceAction);

        return card;
    }
    catch (Exception ex)
    {

        throw;
    }

}

对于CherwellCategories 列表 - 它包含 3 个级别,服务(8 个数据) - 类别(20+)和子类别(118 个数据)。我怀疑这是因为卡片太大而无法处理。

点击按钮时卡片未显示。它没有给出任何回应。有什么限制吗?因为我能够创建一张简单的卡片并展示它,所以继续对话流程。

JsonValue:

[
  {
    "name": "Acquire and Develop Talent",
    "categories": [
      {
        "name": "Manage Learning and Development",
        "categories": [
          {
            "name": "Deliver Training"
          },
          {
            "name": "Develop Learning Programmes"
          },
          {
            "name": "Evaluate Training"
          },
          {
            "name": "Manage course cancellation requests"
          },
          {
            "name": "Manage Employee pre-book requests"
          },
          {
            "name": "Register interest for a course"
          },
          {
            "name": "Set-up Learning"
          }
        ]
      },
      {
        "name": "Manage Performance",
        "categories": [
          {
            "name": "Conduct Annual Review"
          },
          {
            "name": "Conduct Mid-Year Review"
          },
          {
            "name": "Create Team Objectives & Individual Performance Plan"
          },
          {
            "name": "Design Performance and Development Processes and Tools"
          },
          {
            "name": "Manage and Assign Competencies"
          }
        ]
      },
      {
        "name": "Manage Recruitment and New Hires",
        "categories": [
          {
            "name": "Create Job Requisition"
          },
          {
            "name": "Develop Recruitment Processes and Tools"
          },
          {
            "name": "Document Employee Data"
          },
          {
            "name": "Edit / Cancel Job Requisition"
          },
          {
            "name": "Manage Job Offer - Grade 33 and below"
          },
          {
            "name": "Manage Job Offer - Grade 34 and above"
          },
          {
            "name": "Manage Offer Withdrawal"
          },
          {
            "name": "Manage Referral Process"
          },
          {
            "name": "Post Job / Position"
          },
          {
            "name": "Prepare for New Hire"
          },
          {
            "name": "Prepare Rejection"
          },
          {
            "name": "Screen Candidates"
          },
          {
            "name": "Select Candidate"
          },
          {
            "name": "Source Candidate"
          }
        ]
      },
      {
        "name": "Manage Talent",
        "categories": [
          {
            "name": "Conduct Talent Review & Identify Talent"
          },
          {
            "name": "Develop & Maintain Succession Plan"
          },
          {
            "name": "Develop Talent Processes & Tools"
          }
        ]
      }
    ]
  },
  {
    "name": "Ad-hoc Request",
    "categories": [
      {
        "name": "Admin request",
        "categories": [
          {
            "name": "Perform specified Admin action"
          }
        ]
      },
      {
        "name": "Reporting",
        "categories": [
          {
            "name": "Create Report"
          },
          {
            "name": "Run Report"
          }
        ]
      }
    ]
  },
  {
    "name": "HR Systems",
    "categories": [
      {
        "name": "Cherwell",
        "categories": [
          {
            "name": "Defect"
          },
          {
            "name": "New Requirement"
          },
          {
            "name": "Question"
          }
        ]
      },
      {
        "name": "IVR",
        "categories": [
          {
            "name": "Defect"
          },
          {
            "name": "New Requirement"
          },
          {
            "name": "Question"
          }
        ]
      },
      {
        "name": "Kenexa",
        "categories": [
          {
            "name": "Create new users"
          },
          {
            "name": "Jobs Specifications Updates"
          },
          {
            "name": "Manage assessments"
          },
          {
            "name": "Manage Reports"
          },
          {
            "name": "Requisitions Incidents"
          }
        ]
      },
      {
        "name": "Opentext",
        "categories": [
          {
            "name": "Defect"
          },
          {
            "name": "New Requirement"
          },
          {
            "name": "Question"
          }
        ]
      },
      {
        "name": "SharePoint",
        "categories": [
          {
            "name": "Access"
          },
          {
            "name": "Defect"
          }
        ]
      },
      {
        "name": "Success Factors",
        "categories": [
          {
            "name": "Defect"
          },
          {
            "name": "New Requirement"
          },
          {
            "name": "Question"
          }
        ]
      },
      {
        "name": "System integration",
        "categories": [
          {
            "name": "Defect"
          },
          {
            "name": "New Requirement"
          },
          {
            "name": "Question"
          }
        ]
      },
      {
        "name": "Talent Portal",
        "categories": [
          {
            "name": "Log in issues"
          },
          {
            "name": "Manage Reports"
          },
          {
            "name": "Manage Talent Xchange Communities"
          }
        ]
      }
    ]
  },
  {
    "name": "Manage Employee Administration",
    "categories": [
      {
        "name": "Manage Absence and Health",
        "categories": [
          {
            "name": "Administer Leave of Absence"
          },
          {
            "name": "Administer Occupational Health"
          },
          {
            "name": "Manage Return to Work"
          },
          {
            "name": "Record and Manage Long Term Sickness Absence"
          },
          {
            "name": "Record and Manage Short Term Sickness Absence"
          }
        ]
      },
      {
        "name": "Manage Employee Changes",
        "categories": [
          {
            "name": "Administer Mass Data Changes"
          },
          {
            "name": "Change Employee Personal Data"
          },
          {
            "name": "Change Employee Work Data"
          },
          {
            "name": "Manage Personnel Files"
          },
          {
            "name": "Manage Promotion, Demotion & Lateral Moves"
          }
        ]
      },
      {
        "name": "Manage Exit",
        "categories": [
          {
            "name": "Conduct Exit Interviews & Communications"
          },
          {
            "name": "Manage Involuntary Exit"
          },
          {
            "name": "Manage Redundancy"
          },
          {
            "name": "Manage Voluntary Exit"
          }
        ]
      },
      {
        "name": "Manage Global Mobility",
        "categories": [
          {
            "name": "End or Extend Assignment"
          },
          {
            "name": "Initiate Assignment"
          },
          {
            "name": "Initiate Assignment - What If"
          },
          {
            "name": "Initiate Assignment Non-Aurora"
          },
          {
            "name": "Manage APRO Data Errors"
          },
          {
            "name": "Manage APRO Testing"
          },
          {
            "name": "Manage APRO Updates and Uploads"
          },
          {
            "name": "Manage APRO User Accounts"
          },
          {
            "name": "Manage Cost of Living Review"
          },
          {
            "name": "Manage Home Leave Review"
          },
          {
            "name": "Manage Immigration"
          },
          {
            "name": "Manage Processes on Assignment"
          },
          {
            "name": "Manage Relocation"
          }
        ]
      },
      {
        "name": "Manage Organisation & Positions",
        "categories": [
          {
            "name": "Close / Freeze position"
          },
          {
            "name": "Create / Maintain Organisation Design & Authorities"
          },
          {
            "name": "Create Position"
          },
          {
            "name": "Modify Position"
          }
        ]
      },
      {
        "name": "Manage Payroll",
        "categories": [
          {
            "name": "Collect Payroll Data"
          },
          {
            "name": "Manage Exception / Escalation Payment Process"
          },
          {
            "name": "Manage Payroll Reporting"
          },
          {
            "name": "Manage Third Party Payroll"
          },
          {
            "name": "Payroll and Taxation Set Up and Ongoing Administration - International Assignment Payroll"
          },
          {
            "name": "Payroll and Taxation Set up and Ongoing Administration - Shadow"
          },
          {
            "name": "Payroll Processing"
          }
        ]
      }
    ]
  },
  {
    "name": "Manage Organisational Development",
    "categories": [
      {
        "name": "Manage Employee & Labour Relations",
        "categories": [
          {
            "name": "Manage Appeals"
          },
          {
            "name": "Manage Conduct Cases"
          },
          {
            "name": "Manage Grievances"
          },
          {
            "name": "Manage Unions / Work Councils"
          }
        ]
      },
      {
        "name": "Manage Organisational Strategy",
        "categories": [
          {
            "name": "Develop Engagement Surveys"
          },
          {
            "name": "Manage Diversity"
          }
        ]
      }
    ]
  },
  {
    "name": "Manage People Strategy & Analytics",
    "categories": [
      {
        "name": "Manage Analytics and Insight",
        "categories": [
          {
            "name": "Manage Reporting"
          }
        ]
      },
      {
        "name": "Plan & Manage HR and Manage Strategic HR",
        "categories": [
          {
            "name": "Manage Reporting"
          }
        ]
      }
    ]
  },
  {
    "name": "Manage Reward and Benefits",
    "categories": [
      {
        "name": "Manage Benefits",
        "categories": [
          {
            "name": "Manage Benefit Enrolment and Amendments"
          },
          {
            "name": "Manage Pensions Administration"
          },
          {
            "name": "Process Benefit Costs"
          }
        ]
      },
      {
        "name": "Manage Compensation, Incentives & Recognition",
        "categories": [
          {
            "name": "Analyse and Evaluate Jobs / Roles"
          },
          {
            "name": "Design Reward Plans"
          },
          {
            "name": "External Reward Benchmarking"
          },
          {
            "name": "Manage Bonus Payments"
          },
          {
            "name": "Manage Compensation Review"
          },
          {
            "name": "Manage Off-Cycle Reward Changes"
          },
          {
            "name": "Manage One-off payments & Allowances"
          },
          {
            "name": "Manage Reward Communications"
          },
          {
            "name": "Manage Share Plans"
          }
        ]
      }
    ]
  }
] 

【问题讨论】:

  • 旧的 HeroCard 过去常常会在输入一定数量的字符后被剪掉,这些字符因通道而异,并且在任何地方都没有真正记录 - 只有通过实验才能找出限制。
  • 我根据您提供的代码 sn-p 进行测试,the adaptive card display well in web chat。您可以检查网络聊天收到的活动是否是有效的自适应卡。此外,如果可能的话,您可以分享您存储在变量CherwellCategories 中的实际数据,以便我们可以使用它来重现问题。
  • @FeiHan Yup。我从 7 个服务中删除了 3 个(以及属于删除的 3 个服务的后续类别和子类别),它也可以工作。如果我只删除 2 个,那么它就不能再渲染了。
  • @FeiHan 我已经添加了json值供你测试
  • 嗨@ArifSam,我可以根据您的数据重现同样的问题。不确定活动/自适应卡是否超出某些限制,因为找不到任何有关此的文档。此外,您可以尝试我分享的解决方法,使用多个自适应卡来实现需求。

标签: c# botframework adaptive-cards


【解决方案1】:

我从 7 个服务中删除了 3 个(以及属于删除的 3 个服务的后续类别和子类别),它也可以工作。如果我只删除 2 个,那么它就不能再渲染了。

我使用与您提供的 json 值相同的数据进行测试,我可以在网络聊天中重现相同的问题。我检查了包含生成的自适应卡片作为附件的活动的大小,大约是 430kb

正如您所提到的,如果我从服务列表中删除一些项目(服务),则可以呈现卡片并按预期工作。似乎是活动或自适应卡的一些限制导致了这个问题,目前我们找不到任何关于类似问题的文档解释,如果可能,您可以create an issue 报告它。

此外,您在一张自适应卡片中显示了许多服务、类别和子类别供用户选择,作为一种解决方法,您可以尝试将它们分开在许多自适应卡片中,然后您可以基于动态显示子自适应卡片关于用户的选择和您在以前的自适应卡中收集的回传值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多