【问题标题】:Skype bot error on sending attachments/JSON发送附件/JSON 时出现 Skype 机器人错误
【发布时间】:2017-11-08 11:58:11
【问题描述】:

我尝试使用session.send 通过会话发送 JSON 字符串化对象或附件,我在控制台中收到以下错误,但未收到机器人的任何响应。

错误:对“https://smba.trafficmanager.net/apis/v3/conversations/SOMEHASHCODE/activities”的请求失败:[400] 错误请求

当我在 Microsoft Bot Framework 中检查 Skype 频道问题时,我看到 JSON 对象的以下消息

消息文本中的 XML 无效

以及以下附件消息。

未知的附件类型

机器人在 Slack 和 Emulator 中运行良好。所以应该不是代码的问题。

// JSON object
session.send(JSON.stringify(session.conversationData.inputData, null, 2));

// Attachment message
session.send(new builder.Message(session)
    .text(`Here's the document:`)
    .addAttachment({
      contentUrl: `http://host:port/${filePath}`,
      contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      name: 'Document.docx',
    }));

发送的 JSON 对象是{"name": "Philip John", "id": "444411111111", "phone": "54545454", "email": "philip@john.com", "address": "Street 11 - 111, City , ", "job": "Software Tester", "date": "1st June 2017", "salary": "9000", "bankAccount": "DE121231231231231231" }

知道如何解决这个问题吗?

【问题讨论】:

  • 你能分享导致错误的JSON对象吗?
  • @NilsW 请检查。添加了 JSON 对象。
  • 对于问题 #2 - Word 文件附件,您能否链接到产生错误的示例文件?

标签: bots botframework skype


【解决方案1】:

问题 #1 的答案:在 Bot Framework 消息中发送字符串化 JSON。

当您使用以下设置对 JSON 进行字符串化时:

JSON.stringify(inputJson, null, 2)

它生成带有换行符的输出,旨在“漂亮地打印”终端或浏览器控制台中的控制台输出,但在通过 Bot Framework SDK 作为消息发送时不会产生相同的格式。

// string output of JSON.stringify(inputJson, null, 2)
var stringified = = '{\n  "name": "Philip John",\n  "id": "444411111111",\n  "phone": "54545454",\n  "email": "philip@john.com",\n  "address": "Street 11 - 111, City , ",\n  "job": "Software Tester",\n  "date": "1st June 2017",\n  "salary": "9000",\n  "bankAccount": "DE121231231231231231"\n}';

要在机器人消息中获得正确的换行符,您需要使用两个 \n 字符而不是一个。例如:

// bot formatted message string with line breaks
var botJsonMessage = '{\n\n  "name": "Philip John",\n\n  "id": "444411111111",\n\n  "phone": "54545454",\n\n  "email": "philip@john.com",\n\n  "address": "Street 11 - 111, City , ",\n\n  "job": "Software Tester",\n\n  "date": "1st June 2017",\n\n  "salary": "9000",\n\n  "bankAccount": "DE121231231231231231"\n\n}';

回答问题 #2:Bot Framework 中支持的消息附件类型。

目前,contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' 是不受支持的内容类型。请改用application/word

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2019-12-10
    • 2015-03-08
    相关资源
    最近更新 更多