- Get the document
Check if file is epub else reject file
Document {
_fileId: 'BQADBAADigMAAlO0OFN7fDAlnFZSHQI',
_thumb: null,
_fileName: 'Purpose And Power Of Authority - Myles Munroe.epub',
_mimeType: 'application/epub+zip',
_fileSize: 298287 }
const fileId = $.message.document.fileId;
const fileName = $.message.document.fileName;
- Get the file from telegram
const file = await bot.api.getFile(fileId);
- Make request to get the raw file from the api
https://api.telegram.org/file/bot<token>/<file_path>
, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again `
-
Save rawfile to computer using the
fileName
as the name of the file -
Convert file from epub to pdf using an API
-
Get the file and send to the user as pdf
- Stackoverflow / Downloading files from telegram api: https://stackoverflow.com/questions/31096358/how-do-i-download-a-file-or-photo-that-was-sent-to-my-telegram-bot