Created
June 7, 2019 16:02
-
-
Save SilencerWeb/1a2532e5bc4faddc6f09c229c763f2d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
telegram.getUserProfilePhotos(user.id, 0, 1).then((response) => { | |
const photos = response.photos; | |
const photo = photos[0]; | |
const largePhoto = photo[2]; | |
telegram.getFileLink(largePhoto.file_id).then((avatarLink) => { | |
axios.get(avatarLink).then((avatar) => { | |
const form = new FormData(); | |
form.append('data', new Buffer.from(avatar.data), { | |
filename: 'example.jpg', | |
}); | |
return new Promise((resolve, reject) => { | |
form.submit('https://telegra.ph/upload', (err, res) => { | |
if (err) return reject(err); | |
let data = ''; | |
const onData = chunk => { | |
data += chunk; | |
}; | |
const onEnd = () => { | |
res.removeListener('data', onData); | |
res.removeListener('error', reject); | |
res.removeListener('end', onEnd); | |
console.log(JSON.parse(data)); | |
resolve(JSON.parse(data)); | |
}; | |
res.on('data', onData); | |
res.on('end', onEnd); | |
res.on('error', reject); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment