nestjs-telegram icon indicating copy to clipboard operation
nestjs-telegram copied to clipboard

How does the sendDocument method work?

Open menelai opened this issue 4 years ago • 0 comments

Does not work:

this.telegramService.sendDocument({
  chat_id: 100500,
  document: fs.createReadStream('error.txt') // <--- need to have Buffer here, tried a lot of ways to make it
}).subscribe()

Telegram API answers with code 400 without explanation.

Works:

import * as FormData from 'form-data';
...
const form = new FormData();
form.append('chat_id', chat_id);
form.append('document', Buffer.alloc(text.length, text), {filename: 'error.txt'});
form.submit(`https://api.telegram.org/bot${settings.telegramBot.key}/sendDocument`, function(err, response) {
 console.log(err, response);
});

menelai avatar Nov 06 '20 11:11 menelai