Telegram Bot that converts some file types to native photo, audio or video Telegram messages.

revolter revolter Last update: Mar 29, 2022

File Convert Bot

Introduction

Telegram Bot that converts (for now) AAC, OPUS, MP3 and WebM files to voicemessages, HEVC and MP4 (MPEG4, VP6 and VP8) files to video messages or videonotes (rounded ones), video messages to video notes (rounded ones), videos fromsome websites to video messages, PDF files to photo messages (currently onlythe first page), image files to stickers. It also converts voice messages toMP3 files and stickers to photo messages. It works in groups too!

The bot currently runs as @FileConvertBot.

All the processing is done in-memory, so no file is ever saved on the disk,not even temporary!

Getting Started

These instructions will get you a copy of the project up and running on yourlocal machine for development and testing purposes.

Prerequisites

You need to install Homebrew by running:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing

Install the global dependencies by running:

sudo apt install ffmpeg poppler-utils

on Linux or

brew install ffmpeg poppler

on macOS.

Then clone the project and install the dependencies by running:

cd /desired/location/pathgit clone https://github.com/revolter/FileConvertBot.gitcd FileConvertBotcurl https://pyenv.run | bashexport PATH="$HOME/.pyenv/bin:$PATH"sudo apt updatesudo apt install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-devpyenv install 3.9.0pyenv global 3.9.0curl -sSL https://install.python-poetry.org | python -poetry shellpoetry installcd srccp config_sample.cfg config.cfg

Then, edit the file named config.cfg inside the src folder with the correctvalues and run it using ./main.py --debug.

Use exit to close the virtual environment.

Deploy

You can easily deploy this to a cloud machine usingFabric:

cd /project/location/pathpoetry shellcp fabfile_sample.cfg fabfile.cfg

Then, edit the file named fabfile.cfg inside the root folder with the correctvalues and run Fabric using:

fab setupfab deploy

You can also deploy a single file using fab deploy --filename=main.py or fab deploy --filename=pyproject.toml.

Dependencies

Currently, you have to manually install poppler in order for PDF to PNGconversion to work:

  • macOS: brew install poppler
  • Ubuntu: sudo apt-get install poppler-utils

Subscribe to our newsletter