Error 400 Facebook Bad Request due to base 64 image url
Hi, first of all kudos for the awesome efforts behind this library.
I keep getting this error
Error: Request to 'https://facebook.botframework.com/v3/conversations/1264345230303892-1796187950602259/activities/mid.1483439756417%3Ad109a06b06' failed: [400] Bad Request
2017-01-03T10:35:59.778714+00:00 app[web.1]: at Request._callback (/app/node_modules/botbuilder/lib/bots/ChatConnector.js:413:46)
2017-01-03T10:35:59.778715+00:00 app[web.1]: at Request.self.callback (/app/node_modules/request/request.js:186:22)
2017-01-03T10:35:59.778716+00:00 app[web.1]: at emitTwo (events.js:106:13)
2017-01-03T10:35:59.778717+00:00 app[web.1]: at Request.emit (events.js:191:7)
2017-01-03T10:35:59.778717+00:00 app[web.1]: at Request.<anonymous> (/app/node_modules/request/request.js:1081:10)
2017-01-03T10:35:59.778718+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-01-03T10:35:59.778719+00:00 app[web.1]: at Request.emit (events.js:188:7)
2017-01-03T10:35:59.778719+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1001:12)
2017-01-03T10:35:59.778720+00:00 app[web.1]: at IncomingMessage.g (events.js:291:16)
2017-01-03T10:35:59.778720+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-01-03T10:35:59.778721+00:00 app[web.1]: at IncomingMessage.emit (events.js:185:7)
2017-01-03T10:35:59.778722+00:00 app[web.1]: at endReadableNT (_stream_readable.js:974:12)
2017-01-03T10:35:59.778723+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
2017-01-03T10:35:59.778723+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:98:9)
This is what dev.botframework facebook connector says
{"error":{"message":"(#100) [elements][0][image_url] should represent a valid URL","type":"OAuthException","code":100,"fbtrace_id":"EKAMtvX8s9M"}}
The code that causes the above error looks like this
let msg = new builder.Message(session)
.text(question)
.attachments([
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"images": [
{
"url": url
}
],
"buttons": [
{
"title": "What is it?",
"type": "postBack",
"value": "PAYLOAD_WHAT_IS_IT"
},
{
"title": "Hint",
"type": "postBack",
"value": "PAYLOAD_HINT"
}
]
}
}
]);
session.send(msg)
Since it doesnt take an Einstein to figure out that the image url is the issue, in my case it is a BASE 64 generated image url, it works on the emulator but not on Messenger, any ideas how I can make it work at both places?
UPDATE 1
The code works perfectly well on Messenger if I change my code like this
let attachments = [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"buttons": [
{
"title": "What is it?",
"type": "postBack",
"value": "PAYLOAD_WHAT_IS_IT"
},
{
"title": "Hint",
"type": "postBack",
"value": "PAYLOAD_HINT"
}
]
}
}
]
attachments.push(
{
"contentType": "image/png",
"contentUrl": url
}
)
msg = new builder.Message(session)
.text(question)
.attachments(attachments);
Any ideas why 👍
Can you verify if Facebook allows you to send Base64 encoded images? My guess is they don't allow using Base64 as image source (reading documentation) because I don't see any way of doing inline attachments. Try providing an http://... URL and see if that works.
I am sending base64 images and they are working on facebook with this code
let attachments = []
attachments.push(
{
"contentType": "image/png",
"contentUrl": url
}
)
attachments.push({
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"text": question,
"buttons": buttons
}
})
msg = new builder.Message(session)
.attachments(attachments)
```;
The url above is the base 64 url and it works on facebook on my phone. If it isnt too much to ask, can you confirm that the above code will actually work?
Update 1
I am running a quiz prompt where I generate a base 64 image for each question, on the emulator as I scroll down, I notice nothing but on Facebook when I scroll down, the images for the questions above disappear big time. Should I generate all the base 64 image urls in advance and store it inside session.dialogData?
Storing everything in dialogData might not be a good idea since it's a limited space (something around < 64K). I would suggest just store a UUID (or any unique identifier) and store the URLs in your own key-value store. If you have just few URLs then dialogData might be fine but I would never recommend storing actual data in dialogData. Keep meta-data information that you can use to lookup actual information in your own storage.
@nwhitmont So facebook channel doesnt support base 64 images through CardImage????????Is it so?