【问题标题】:How to disable Adaptive Cards on clicking once?如何在单击一次时禁用自适应卡片?
【发布时间】:2020-11-10 03:21:19
【问题描述】:

我在 MSTeams Bot 中使用自适应卡,点击一次我想禁用提交按钮以防止用户再次点击它,因为后端正在为按钮点击事件运行。

自适应卡代码-

async specialRewards() {
const specialRewardCard = CardFactory.adaptiveCard({
  '$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
  'version': '1.2',
  'type': 'AdaptiveCard',
  'body': [
    {
      'type': 'TextBlock',
      'text': "Hey there! \n\n",
      'wrap': true,
    },
    {
      'type': 'TextBlock',
      'text': 'Your birthday???? :',
      'weight': 'Bolder',
      'wrap': true,
    },
    {
      'type': 'Input.Date',
      'id': 'birthday',
      'placeholder': 'Enter a date',
      'spacing': 'Padding',
    },
    {
      'type': 'TextBlock',
      'text': 'Your work anniversary???? :',
      'weight': 'Bolder',
      'wrap': true,
    },
    {
      'type': 'Input.Date',
      'id': 'anniversary',
      'placeholder': 'Enter a date',
      'spacing': 'Padding',
    },
  ],
  'actions': [
    {
      'type': 'Action.Submit',
      'title': 'Submit',
      'isPrimary': true,
    },
  ],
});
return specialRewardCard;

}

这就是它在 MSTeams 上的样子

【问题讨论】:

    标签: node.js botframework adaptive-cards


    【解决方案1】:

    我自己目前正在处理类似的场景,我发现 updateActivity() 函数运行良好。

      // Update the adaptive card so it cannot be used again
      async followUp() {
      const card = CardFactory.heroCard(
         'Your card results',
         '<b>Birthday:</b> ' + birthday + '<br>' + '<b>Anniversary:</b> ' + anniversary,
         null
         );
         card.id = step.context.activity.replyToId;
         const message = MessageFactory.attachment(card);
         message.id = step.context.activity.replyToId;
         await step.context.updateActivity(message);
       }
    

    【讨论】:

    • 是的,这是正确执行此操作的唯一方法。它几乎是用户点击提交 -> 更新卡 -> 做任何你需要的 -> 发送结果。 UI 会更新两次,更新卡片并显示你的最终结果。
    猜你喜欢
    • 2020-01-06
    • 2019-10-15
    • 2020-07-29
    • 2021-03-24
    • 1970-01-01
    • 2023-03-08
    • 2019-12-16
    • 2020-12-09
    相关资源
    最近更新 更多