Tmirror

How To Host Telegram Bot on Digital Ocean


How To Host Telegram Bot on Digital Ocean

How to host telegram Marie bot on Digital Ocean with Unlimited Filters by hosting a Postgres server ourselves

  • No Dyno Issus
  • Unlimited Filter
  • Better Speed
  • Less response time

Your BOT will be up and running as long as you pay for VPS 😋

Lets create a Digital Ocean Account first!

Digital Ocean: https://cloud.digitalocean.com/registrations/new

Enter required details and signup with Digital Ocean!

Card verification is required for signup! You’ll be charged some amount for verification and the same will be refunded within few hours. So don’t worry.

To avail digital ocean 100$ free credits promo offer, register and sign in through this link : https://m.do.co/c/aa2ff0eeaa5e

Making an instance in Digital Ocean

Creating a SSH key

Download PuTTY ; https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Create a new SSH Public key and copy paste it in Instance config page.

Save it as our Private key.

Deploy instance.

Connecting to the instance!

  • Connecting to instance with our ssh key

    1
    
      hostname : root@IPV4address
    
  • You’ll be logged in as a root user!

  • Create a new user with sudo privileges ( cause it’s better that way)

    1
    
      sudo adduser <newusername>
    

Enter a new username and password (typed password will be invisible) and press enter for all other values to leave it to default

1
2
3
    sudo usermod -aG sudo <newusername>

    su - newusername
  • Now whenever you login to your instance, change to your user by;

    1
    
      su - newusername
    

Setting up your repository

Configure Marie Bot Repo;

Clone the source code of Marie

Source Code : https://github.com/prgofficial/Marie-2.0-English

Create config.py file from sample_config.py

1
2
3
4
5
    Bot Token : from Bot Father

   Owner ID : from Rose ( /id )

    Owner username : Any name

Database Url : Install postgres server in our Instance and get

Install and setup a Postgres Server

Connect to your instance, then run;

1
2
3
    sudo apt-get update

    sudo apt-get install postgresql postgresql-contrib

Give sudo permission to user

1
    sudo usermod -aG sudo postgres

Set a new password

1
    sudo passwd postgres

password will be invisible, dont worry!

Login to postgres

1
    su - postgres

Create new user for psql

1
2
3
4
5
6
7
    createuser --interactive --pwprompt

    - enter a name for user

    - enter a password for user

    - give superuser power

you can give any name and password!!

Create a database and assign user

1
    createdb -O <username> <newdbname>

Allow remote access

1
    nano /etc/postgresql/12/main/postgresql.conf

Uncomment, and change the value

1
2
    - listen_addresses = 'localhost'  To 
     listen_addresses = '*'

this will allow Postgres connections from anyone.

USE CTRL + O and press enter to save the file and CTRL + X to exit the editor

Allow Connections from everyone

1
    nano /etc/postgresql/12/main/pg_hba.conf

Modify this section;

1
2
3
4
5
    - IPv4 local connections:

    host all all 127.0.0.1/32 md5 TO;
    - IPv4 local connections: 
    host all all 0.0.0.0/0 md5

this will allow anyone to connect to your DB using the username and password!

USE CTRL + O and press enter to save the file and CTRL + X to exit the editor

Allow port 5432

1
        sudo ufw allow 5432/tcp

Restart postgres to apply changes

1
    sudo systemctl restart postgresql

Now, your DB URL will be;

1
    postgres://username:pw@hostname:port/dbname

Hosting Marie REPO

Connect to your instance using putty

connect again using putty or;

Press CTRL + A + D to go back to your user from our current screen

Using screens is a better way to run your programs.

1
    screen -S marie

This will open a new screen inside our main terminal.

Clone your source code to your instance

1
    git clone your_repo_url

Enter your github username and password and hit enter!

Change your current dirrectory

1
    cd reponame

Install required dependencies.

1
2
3
    sudo apt install python3-pip

    pip3 install -r requirements.txt

Start your BOT !

1
    python3 -m tg_bot

Your BOT is ready to use :)

Now your bot is ready with nearly Unlimited Filters….

Some Usefull commands;

To detach from current screen Ctrl + a + d ( hold Ctrl and press a and d sequentially )

To see all active screens screen -ls

To attach to a screen screen -r number

To detach from a screen screen -d number

To logout from terminal with BOT running in screen Ctrl + a + d

Credit: @PrGofficial Documented by: @PrGofficial

comments powered by Disqus