Created
April 16, 2021 07:12
-
-
Save clsung/f1ca7aeb8e2474e8afd825c10a6038ad 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
function handleImage(message, replyToken) { | |
axios.get(`https://api-data.line.me/v2/bot/message/${message.id}/content`, { | |
headers: { | |
'Authorization': `Bearer ${process.env.CHANNEL_ACCESS_TOKEN}` | |
}, responseType: 'stream' | |
}).then((res) => { | |
const tmp = tempfile(); | |
const writer = fs.createWriteStream(tmp); | |
res.data.pipe(writer); | |
writer.on('finish', () => { | |
imgur.setAccessToken(`${process.env.IMGUR_ACCESS_TOKEN}`); | |
imgur | |
.uploadFile(tmp) | |
.then((json) => { | |
return client.replyMessage(replyToken, { | |
"type": "text", | |
"text": `${JSON.stringify(json)}` | |
}); | |
}) | |
.catch((err) => { | |
console.error(err.message); | |
}); | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment