Skip to content

Nikitatsivinsky/Telegram-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image alt

Typing SVG

Pet-project Telegram Bot for Shop

Written by: Nikita Tsivinsky

Contributors & Mentors: @klymenok and @acman

Description

This is the Pet-Project Telegram Bot Repository of the "Python Developer" course from robot_dream, student Nikita Tsivinsky.

Installation:

Follow the steps below to get started your tests of Telegram Bot:

  1. Create you own environment file.
    You need to create your environment variables. In file .env.template you can see example of your .env file:
#FLASK
SECRET_KEY - your secret key of Flask application.
DEBUG - Bool value of Flask application.
HOST - Address of your host of Flask application (default = 0.0.0.0)
PORT - Address of your port of Flask application (default = 8443)
#AUTO START POSTGRESQL SERVER AND NGROK WITH TELEGRAM WEBHOOK (TESTED ON UBUNTU)
AUTO_START - Bool value Auto Start Postgres Server (you need to install Server on your operating system) and NGROK (inside app.start_postgresql_ngrok.StartNGROK you can see function "register_webhook" - this function set WebHook to Telegram API)
#DATABASE
DATABASE_URI - Database Uniform Resource Identifier
SQLALCHEMY_TRACK_MODIFICATIONS - Bool variable of configuration keys for Flask application.
#POSTGRESQL SERVER AUTOSTART
USER_PASSWORD - Password of your Operational System User (inside app.start_postgresql_ngrok.StartProcess you can see function "startprocess" which start your Postgres Server from bash. So, to start Server App use "sudo", and password needs for this.)
#TELEGRAM
TG_TOKEN - Token of your Telegram Bot.
#NOVA POSHTA
NOVA_POSHTA_API_KEY - Your personal Nova Poshta Api Key (Get it!)
COMPANY_TELEPHONE - Your personal or your company telephone number for tracking parcels using Nova Poshta Api method getStatusDocuments.
  1. Install server Postgres
  • For Linux:
sudo apt update                           
sudo apt upgrade
sudo apt install postgresql

to check your server use:

sudo service postgresql status 
  • For Mac:
  1. Visit the PostgreSQL downloads page
  2. Download and open the downloaded package (.dmg) file.
  3. Follow the on-screen instructions to run the installer and complete the installation process. to check your server use:
psql --version  
  • For Windows::
  1. Visit the PostgreSQL downloads page
  2. Download and open the downloaded installer (.exe) file.
  3. Follow the on-screen instructions to run the installer and complete the installation process. Make sure to remember the password you set for the "postgres" user during the installation. to check your server use:
psql --version  
⚠️ You can use Docker container instead installing Postgresql on your OS.⚠️

  1. Set up server Postgres
⚠️ If you use Docker you need to do this inside container.⚠️

  1. Open a command prompt or terminal and log in as a user with superuser privileges (such as a root user or a user with sudo privileges).
    Run the psql command to enter an interactive Postgres shell:
sudo -u postgres psql
  1. Create a new table named tgbot:
CREATE DATABASE tgbot;
  1. Create a new user with the CREATE USER command:
CREATE USER "user" WITH PASSWORD "user";
  1. Assign the required privileges to the user. For example, to give it full rights to all databases, you can run the following command:
GRANT ALL PRIVILEGES ON DATABASE tgbot TO "user";
  1. Connect to the tgbot database:
\c tgbot
  1. Activate the uuid-ossp extension with the following command:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
  1. Exit the interactive Postgres shell by typing \q or pressing Ctrl+D.
\q
  1. Add test values in the database (possible via PyCharm or DataGrid)
    Connect via: bash postgresql://user:user@localhost:5432/tgbot

  2. Add the user entity to the profile table (leave telegram_id empty, it will be filled in automatically) specify the phone number that will connect to the Telegram bot.

  3. Add to the order table an order with a real TTN of Nova Poshta for tests.

  4. Install NGROK

  • For all OS - on Web Site - download and install NGROK.

6. Create Python Virtual Environment and install requirements.txt
pip install -r requirements.txt 

  1. Run Flask Web application
python run.py


Image alt


My statistic:

About

Telegram Bot for Shop.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages