Skip to content

Development Setup

Kanishk Singh edited this page Feb 13, 2019 · 5 revisions

Cloning the repository

Clone the repository by running (in Documents or some other directory, whichever you created the vagrant VM in the previous step):

https://github.com/ArionMiles/MIS-Bot/

Open the project directory in terminal with

cd MIS-Bot/

Run the below command to create folders which will be required by our bot:

mkdir -p files/captcha/

Setting environment variables

Rename example.env to .env:

mv example.env .env

Edit .env and enter your Bot Token, your Chat ID (See Pre-requisites page), and if you are gonna run it with webhooks, you'll need to enter your server address as URL (without HTTP:// or trailing /, like this: X.X.X.X).

Enter SPLASH_INSTANCE as http://splash:8050

Running with Long Polling

If you're testing this locally, change DEBUG value to True in this file which allows you to use long-polling instead of webhooks and makes development easier.

Running with Webhooks

If you're gonna deploy this on a remote server, and are expecting lots of users, it's better to use webhooks rather than long-polling.

You need SSL certificates in order to use webhooks. Telegram servers communicate only via HTTPS, with long polling, the telegram servers take care of it, but since we're using webhooks, we need to take care of it. We'll be using a self-signed certificate. To create a self-signed SSL certificate using openssl, run the following command:

openssl req -newkey rsa:2048 -sha256 -nodes -keyout private.key -x509 -days 3650 -out cert.pem

The openssl utility will ask you a few details. Make sure you enter the correct FQDN! If your server has a domain, enter the full domain name here (eg. sub.example.com). If your server only has an IP address, enter that instead. If you enter an invalid FQDN (Fully Qualified Domain Name), you won't receive any updates from Telegram but also won't see any errors!

-Source

Move the private.key and cert.pem generated to the files/ directory so that they're picked up by telegram_bot.py:

mv private.key cert.pem files/

Running the docker container

On the first run, docker will build an image for our container, it can take significant amount of time depending on your internet connection, so wait while docker downloads the python, splash images and installs all the dependencies.

Start the container by running this from the root directory of the project:

docker-compose up

and after everything is installed, the bot should be up.

Cool! Now you've got the bot running, start experimenting, create new features, the possibilities are endless!