Skip to content

alexyurchuk/telegram_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tutor Telegram Bot

Tutor Telegram Bot logo

Tutor Telegram Bot is a telegram bot that manages educational material ads and posts them on a given channel. After a given period, it automatically deletes this post in the telegram channel.

Overview

  1. Requirements
  2. Installation and setup
  3. How to start telegram bot
  4. How to stop telegram bot

Requirements

To use this bot, you need Windows or Linux, an internet connection and Python (tested on Windows 10 and Python version 3.10.4).
To download Python:

  • Go to the official python website;
  • Choose Downloads;
  • In the "Looking for a specific release?" section, choose the Python version you want, but it's recommended to use the same version of Python that was used during development and testing;
  • Scroll to the bottom of the page and in the "Files" section, choose Windows installer for 32-bit or 64-bit system (guide to check if PC is running in 64-bit or 32-bit Windows version);
  • After downloading, open this file, check the "Add Python 3.10 to path" check box and follow the instructions.

Installation and config

For Windows:
To install all required python libraries, just run (click on) setup.cmd and wait until it says Press any key to continue.

For Linux:
To install all required python libraries grant executable permissions for setup.sh file, run it and wait until it says Press any key to continue.

To set up Tutor Telegram Bot, go to the data directory where you will see bot_config.py, logging_config.py and message_config.py files.

  1. bot_config.py is a main configuration file. There you should edit next things:

    1. INSP_API_ID and INSP_APP_HASH

      INSP_API_ID and INSP_APP_HASH are app details received from an official website of Telegram.
      You will need to login into your telegram account and create an app. After you create an app, you should see something like this:

      App id and hash

      Now you can put "App api_id" into INSP_API_ID and "App api_hash" into INSP_APP_HASH.

    2. TOKEN

      TOKEN is a bot token you can get through the officially implemented telegram bot. To create a new bot type or choose command /newbot, answer all questions, and you should see something like this:

      BotFather bot token

      Now you can copy the token and put it into TOKEN field. Also, remember to add this bot to your admin group in your telegram channel.

    3. LIQPAY_STRIPE_TOKEN

      For the next move, you should have LiqPay business account. After you've done setting up your LiqPay account, go to the API tab, where you should see something like this:

      LiqPay tokens

      LIQPAY_STRIPE_TOKEN is another token you can get through @BotFather. Type or choose command /mybots, then go to the bot you've created in step #2. There you should go to Payments and search for LiqPay. After you click on the LiqPay button, click on Connect LiqPay Live button. You should be redirected to LiqPay official bot. Copy the Public key you got from the LiqPay site and send a command like this:
      /mykey_i************ (Where i
      *********** should be your Public key)
      After you do this, you should find out that your Payments tab in @BotFather has been renewed.

      LiqPay token

      Now you can copy that token and put it into LIQPAY_STRIPE_TOKEN field.

    4. TELEGRAM_CHANNEL_ID

      TELEGRAM_CHANNEL_ID is a channel id you can get through the Telegram Web. There you should go to your telegram channel, and in the URL bar, you should see something like this:

      telegram channel id or username

      Copy @******** (e.g. @u_now_ua like on the photo above) and put it into TELEGRAM_CHANNEL_ID field. In the end, it should look like this:
      TELEGRAM_CHANNEL_ID = '@********'

    5. DONATION and DANATION_LINK

      DONATION can be True or False. If DONATION is True, you need to provide a URL to your Monobank Банка. Monobank Банка URL

    6. Payments

      FREE determines whether material posts are free or not. It can be True or False. If it is False, you need to provide the desired price in POST_PRICE field.

    Other constants inside the bot_config.py file are already provided. You can change them ONLY if you totally understand what they do.

  2. message_config.py is about all messages inside the telegram bot. If you want to change the look or the content of some messages, you can freely do so*.
    *But not the FINAL_VARIANT_MESSAGE_1 or ADD_ANOTHER_MESSAGE. They have a specific structure that you should follow:

    • For FINAL_VARIANT_MESSAGE_1, {subject_name}, {subject_idea}, {material_format}, {material_level}, {material_description}, {material_price}, {username} and {material_hashtag} MUST be there;
    • For ADD_ANOTHER_MESSAGE, {n} MUST be there.
  3. Do not touch session_string.py file. It will be generated once you launch the bot for the first time. It contains your telegram credentials, so DO NOT SHARE THIS FILE WITH ANYBODY.

  4. logging_config.py file is about logging everything. Please, only touch this file if you are familiar with the python logging library.

How to start a telegram bot

For Windows:
To start the telegram bot, just run (click on) run.cmd file.

For Linux:
To start the telegram bot, grant executable permissions to run.sh file and run it.

For the first time you will run run.cmd or run.sh files, you will be asked for your telegram phone number and password.

Please, do not worry, your credential don't go anywhere but to telegram and are stored like hash inside the session_config.py file. So if nobody has access to this file, nobody apart from you won't have access to your telegram account.

The script automatically schedules the inspector task, which deletes expired posts.

How to stop the telegram bot

To stop the telegram bot click on the command prompt (or terminal for Linux) and press Ctrl-C. After that, you will be asked whether you want to delete the inspector task or not:
If you want to delete this task, press y and then ENTER; if you do not want to delete it, press n and ENTER.

About

Python telegram bot to publish tutor worksheets, ads in telegram channel. Also, it will automatically delete them after specified time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages