I’m trying to send photos through telegram bot using ‘sendPhoto’ method with relative url (Image at file level). I’m not using any library, here is my call function:
let axiosImage = async (chatId, caption, res) => {
try {
await axios.post(`${TELEGRAM_API}/sendPhoto`,
{
headers:{'Content-Type': 'multipart/form-data'}
},{
body: {
'chat_id': chatId,
'caption': caption,
'photo': './image.jpeg'
}
})
return res.send()
} catch (e) {
console.log('nSTATUS RESPONSE: ' + e.response.status)
console.log('nMESSAGE RESPONSE: ' + e.response.statusText)
}}
but I’m getting this message back: {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"}
I tried with a web url and it sends normally.
What could I be missing? Do I have to upload the local images in some repository?
2
Answers
From the Telegram api docs
What you want to send is a file via file upload (3.). This is the answer to what you are trying to achieve:
https://stackoverflow.com/a/59177066/4668136
I had a similar issue recently, I managed to solve the problem using form-data npm package and built-in
fs
module.