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

时间:2018-04-19 18:08:58

标签: botframework direct-line-botframework adaptive-cards

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

最近我注意到我的机器人停止工作,我发现问题是直接线/僵尸连接器或中间的东西正在丢失我的AdaptiveCard的“动作”节点而不是直线。这是我的机器人(服务器)发送给客户端的消息(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"
}

请注意,我的消息中的“操作”节点被中间的东西弄坏了(僵尸连接器或直接线路,我不知道)。 有谁可以帮助我?

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

Microsoft.Bot.Builder version =“3.14.1.1” Microsoft.Bot.Connector“version =”3.14.1.1“

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

我使用以下示例代码进行测试以发送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节点:

enter image description here

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

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

actions节点将在消息实体中遗漏:

enter image description here