Skip to content

Instantly share code, notes, and snippets.

@rotimi-best
Last active January 1, 2019 21:46
Show Gist options
  • Save rotimi-best/21caae0403d405933f2a31b9e41ff326 to your computer and use it in GitHub Desktop.
Save rotimi-best/21caae0403d405933f2a31b9e41ff326 to your computer and use it in GitHub Desktop.
A todo for creating a file converting telegram bot.

Todos - Conversion bot - Epub to pdf

  • 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

Materials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment