Botframework AdaptiveCard 正在失去直线上的“动作”节点

Botframework AdaptiveCard is losing the “actions” node over directline

我正在使用带有 directlinejs 的 botframework C# 来构建我的机器人。

最近我注意到我的机器人停止工作,我发现问题是 directline/botconnector 或中间的东西正在通过直线丢失我的 AdaptiveCard 的 "actions" 节点.这是我的机器人(服务器)发送给客户端(botconnector 和 directlinejs)的消息。

{
  "$type": "Microsoft.Bot.Connector.Activity, Microsoft.Bot.Connector",
  "type": "message",
  "timestamp": "2018-04-19T17:57:14.565727+00:00",
  "serviceUrl": "https://directline.botframework.com/",
  "channelId": "directline",
  "from": {
    "$type": "Microsoft.Bot.Connector.ChannelAccount, Microsoft.Bot.Connector",
    "id": "Toro@Q7xWzEtd_lk",
    "name": "Toro Assistant"
  },
  "conversation": {
    "$type": "Microsoft.Bot.Connector.ConversationAccount, Microsoft.Bot.Connector",
    "id": "CfAgYrLQOuv9fDMPnfINDG"
  },
  "recipient": {
    "$type": "Microsoft.Bot.Connector.ChannelAccount, Microsoft.Bot.Connector",
    "id": "anonymous",
    "name": "anonymous"
  },
  "text": "",
  "attachments": {
    "$type": "System.Collections.Generic.List`1[[Microsoft.Bot.Connector.Attachment, Microsoft.Bot.Connector]], mscorlib",
    "$values": [
      {
        "$type": "Microsoft.Bot.Connector.Attachment, Microsoft.Bot.Connector",
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
          "$type": "AdaptiveCards.AdaptiveCard, AdaptiveCards",
          "type": "AdaptiveCard",
          "version": "1.0",
          "body": {
            "$type": "System.Collections.Generic.List`1[[AdaptiveCards.AdaptiveElement, AdaptiveCards]], mscorlib",
            "$values": [
              {
                "$type": "AdaptiveCards.AdaptiveTextBlock, AdaptiveCards",
                "type": "TextBlock",
                "text": "Não se preocupe, cadastrar um novo número é muito fácil. É só clicar no botão abaixo.\r\n\r\n"
              }
            ]
          },
          "actions": {
            "$type": "System.Collections.Generic.List`1[[AdaptiveCards.AdaptiveAction, AdaptiveCards]], mscorlib",
            "$values": [
              {
                "$type": "AdaptiveCards.AdaptiveOpenUrlAction, AdaptiveCards",
                "type": "imBack",
                "url": "http://toroinvestimentos.com.br/minhaconta/emailecelular/edit?q=phone&token=token",
                "title": "Falar com Assessor"
              },
              {
                "$type": "AdaptiveCards.AdaptiveSubmitAction, AdaptiveCards",
                "type": "imBack",
                "data": "Mudar de assunto",
                "title": "Mudar de assunto",
                "image": "https://toro.azureedge.net/bot/icon_list_default.svg"
              }
            ]
          },
          "style": "ToroCard1"
        }
      }
    ]
  },
  "entities": {
    "$type": "System.Collections.Generic.List`1[[Microsoft.Bot.Connector.Entity, Microsoft.Bot.Connector]], mscorlib",
    "$values": []
  },
  "replyToId": "CfAgYrLQOuv9fDMPnfINDG|0000011"
}

这里是 botconnector/directlinejs 传递给客户的消息:

{
  "type": "message",
  "id": "CfAgYrLQOuv9fDMPnfINDG|0000012",
  "timestamp": "2018-04-19T17:57:14.9161386Z",
  "localTimestamp": "2018-04-19T17:57:14.6134302+00:00",
  "channelId": "directline",
  "from": {
    "id": "Toro",
    "name": "Toro Assistant"
  },
  "conversation": {
    "id": "CfAgYrLQOuv9fDMPnfINDG"
  },
  "text": "",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "content": {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
          {
            "type": "TextBlock",
            "text": "Não se preocupe, cadastrar um novo número é muito fácil. É só clicar no botão abaixo.\r\n\r\n"
          }
        ],
        "style": "ToroCard1"
      }
    }
  ],
  "entities": [],
  "replyToId": "CfAgYrLQOuv9fDMPnfINDG|0000011"
}

请注意,我消息的 "Actions" 节点被中间的东西(botconnector 或 directlinejs,我不知道)裁剪掉了。 谁能帮帮我?

我正在使用以下版本的 botframework 库:

Microsoft.Bot.Builder 版本="3.14.1.1" Microsoft.Bot.Connector" 版本="3.14.1.1"

"type": "imBack" 不是有效的 AdaptiveAction 类型。

对于 AdaptiveOpenUrlAction 它应该是 "Action.OpenUrl" https://github.com/Microsoft/AdaptiveCards/blob/6700649f154cf12da6d02e063325b396026993c6/source/dotnet/Library/AdaptiveCards/AdaptiveOpenUrlAction.cs#L24

对于 AdaptiveSubmitAction 它应该是 “Action.Submit” https://github.com/Microsoft/AdaptiveCards/blob/6700649f154cf12da6d02e063325b396026993c6/source/dotnet/Library/AdaptiveCards/AdaptiveSubmitAction.cs#L22

我用下面的示例代码做了一个发送AdaptiveCard的测试,在我的directjs客户端中,我可以在消息实体中找到actions节点。所以我建议在我之前的评论中分享你的代码。

在我的机器人应用程序中:

var replymes = context.MakeMessage();

AdaptiveCard card = new AdaptiveCard();

// Add text to the card.
card.Body.Add(new TextBlock()
{
    Text = "This is an Adaptive Card",
    Size = TextSize.Large,
    Weight = TextWeight.Bolder
});

// Add buttons to the card.
card.Actions.Add(new OpenUrlAction()
{
    Url = "http://foo.com",
    Title = "Link1"
});

// Create the attachment.
Attachment attachment = new Attachment()
{
    ContentType = AdaptiveCard.ContentType,
    Content = card
};
replymes.Attachments.Add(attachment);

Console.WriteLine(card.ToString());
await context.PostAsync(replymes);

在directlinejs客户端中,消息实体包含actions节点:

此外,正如 Eric Dahlvang 提到的,"type": "imBack" 不是有效的 AdaptiveAction 类型。如果我们明确指定类型为 "imBack",如下所示:

card.Actions.Add(new OpenUrlAction()
{
    Url = "http://foo.com",
    Title = "Link1",
    Type= "imBack"
});

消息实体中的actions节点将丢失: