nestjs-telegram
nestjs-telegram copied to clipboard
How does the sendDocument method work?
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);
});