-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Conversation
requestObj = { | ||
method: 'POST', | ||
formData: prepareFormdata, | ||
uri: 'https://' + api_host + '/v2.6/me/messages' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't used the upload api myself, but the docs say the url for uploads is:
v2.6/me/message_attachments
Ahh, misunderstood the purpose of this PR! Carry on 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonchurch you made me think to bring the functionality that you misunderstood to Botkit 😈
If you don't already start to work on 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello champion,
Thanks for this awesome work 👍
uri: 'https://' + api_host + '/v2.6/me/messages' | ||
}, | ||
function(err, res, body) { | ||
var requestObj = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about initializing requestObject with POST method and uri to avoid duplication ?
var requestObj = {
method: 'POST',
uri: 'https://' + api_host + '/v2.6/me/messages'
};
prepareFormdata[key] = facebook_message[key]; | ||
} | ||
} | ||
requestObj = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you initialised the requestObj with the http verbe POST and the uri, you just need to set here the formData :
requestObj.formData = prepareFormdata;
requestObj = { | ||
method: 'POST', | ||
formData: prepareFormdata, | ||
uri: 'https://' + api_host + '/v2.6/me/messages' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonchurch you made me think to bring the functionality that you misunderstood to Botkit 😈
If you don't already start to work on 😬
if ('filedata' in facebook_message) { | ||
var prepareFormdata = {}; | ||
for (key in facebook_message) { | ||
if (key !== 'filedata' && typeof facebook_message[key] === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code is really awesome, but what do you think about starting with checking for filedata to avoid a slightly duplication ?
if (key === 'filedata') {
if (!fs.existsSync(facebook_message[key])) return cb(new Error('filedata not exist'));
prepareFormdata[key] = fs.createReadStream(facebook_message[key]);
} else if (typeof facebook_message[key] === 'object') {
prepareFormdata[key] = JSON.stringify(facebook_message[key]);
} else {
prepareFormdata[key] = facebook_message[key];
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Solved #233
Use
filedata
to assign upload file/image describe on Content Types page in FB messenger doc. It will do a basic file validate (fs.existsSync) then stream the file using form-data.e.g., upload png file