Download the twitter image at the webhook


#1

In the BOT when we send a DM with an Image we are triyng the bet the base64 image to post in a image repository.
I came across this message:
StatusMessage:“Authorization Required”

This the code at the webhook:
requestencodingnull.get(url, function (error2, response2, bodyimage) {
if (error2) {
console.log(error2);
callback(error2);
} else {
//console.log(result3)
var buff = new Buffer(bodyimage).toString(‘base64’)
var data = “data:image/png;base64,” + buff
var matches2 = data.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
var type2 = matches2[1];
var buffer2 = new Buffer(matches2[2], ‘base64’);


#2

This post makes zero sense.

You posted a what seems like a random snippet of code without any context.

What are you trying to do exactly?


#3

Suppose this situation: You have a insurance bot and among other things you want to register you could send image or photo that the bot might be able to send it to Azure blob file.
Yours PEdro


#4

We have done it:
We get the image message_event.message_create.message_data.attachment.media.media_url
and GET with twitter oauth:
var b = { url: url, oauth: twitter_oauth }
And we get the base64:
requestencodingnull.get(b, function (error2, response2, bodyimage) {
// console.log(response2)
if (error2) {
console.log(error2);
callback(error2);
} else {
//console.log(result3)
var buff = new Buffer(bodyimage).toString(‘base64’)
var data = “data:image/png;base64,” + buff
var matches2 = data.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
var type2 = matches2[1];
var buffer2 = new Buffer(matches2[2], ‘base64’);