My goal is to send a pdf file from an input to my telegram bot after the submit button has been clicked. According to the telegram bot api documentation (https://core.telegram.org/bots/api#sending-files), the way to achieve this is to upload a file using multipart/form-data.
Here is what I did:
document.querySelector('#sumbitButton').onclick = () => { // my submit button
const input = document.querySelector('#file-input'); // my input
const formData = new FormData();
formData.append('pdf-file', input.files[0])
fetch(`https://api.telegram.org/bot<my token>/sendDocument?chat_id=<my chat_id>`, {
method: 'POST',
body: formData
}).then((success) => {
console.log(success)
}).catch((error) => {
console.log(error)
});
}
But I’m running into 400 error.