0
votes

I was trying to send a JSON stringified object or an attachment through the session using session.send, I got the following error in the console and do not get any response from the bot.

Error: Request to 'https://smba.trafficmanager.net/apis/v3/conversations/SOMEHASHCODE/activities' failed: [400] Bad Request

When I checked the Skype channel issues in Microsoft Bot Framework, I see the following message for JSON objects

Invalid XML in message text

and the following message for attachments.

Unknown attachment type

The bot is working perfectly in Slack and Emulator. So it must not be the issue with the code.

// 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',
    }));

The JSON object which was sent was {"name": "Philip John", "id": "444411111111", "phone": "54545454", "email": "[email protected]", "address": "Street 11 - 111, City , ", "job": "Software Tester", "date": "1st June 2017", "salary": "9000", "bankAccount": "DE121231231231231231" }

Any idea how to tackle this issue?

1
Can you share the JSON object that caused the error?nilsw
@NilsW please check. Added the JSON object.Philip John
for question #2 - Word file attachment, can you link to an example file that produces the error?nilsw

1 Answers

0
votes

Answer to question #1: Sending stringified JSON in Bot Framework message.

When you stringify JSON with the following settings:

JSON.stringify(inputJson, null, 2)

It produces output with new-line symbols, which is designed to "pretty print" console output in a terminal or browser console, but does not produce the same formatting when sending as a message via 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": "[email protected]",\n  "address": "Street 11 - 111, City , ",\n  "job": "Software Tester",\n  "date": "1st June 2017",\n  "salary": "9000",\n  "bankAccount": "DE121231231231231231"\n}';

To get proper line breaks in your bot message, you need to use two \n characters instead of one. For example:

// 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": "[email protected]",\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}';

Answer to question #2: Supported message attachment types in Bot Framework.

Currently, contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' is an unsupported content type. Use application/word instead.