1

我正在使用带有 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"
}

请注意,我的消息的“Actions”节点被中间的某些东西裁剪(botconnector 或 directlinejs,我不知道)。谁能帮助我?

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

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

4

2 回答 2

2
于 2018-04-24T21:58:34.403 回答
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节点:

在此处输入图像描述

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

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

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

在此处输入图像描述

于 2018-04-25T08:29:05.310 回答