Skip to content

Midblyte/tmnetbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmnetbot - share your telegram channel by allowing other people to post into it through a bot

Setup and run

Step 1

First, clone this repository. Type:

git clone https://github.com/Midblyte/tmnetbot

Step 2

Install the dependencies (let the project root be tmnetbot):

cd tmnetbot && pip install -r requirements.txt 

Step 3

Set the needed environment variables. You can also create a .env file at the root of the project and put them into it:

MacOS, Linux:
touch .env
Windows (Powershell):
New-Item ".env"

Step 4

Run the provided script. You'll see a .session file to be created in the folder:

MacOS, Linux:
./bin/start_bot.py
Windows:
python .\bin\start_bot.py

Environment variables

TELEGRAM_CHANNEL

It's the @username (for public channels) or the numeric ID (both for public and private channels). All messages will be forwarded here.


TELEGRAM_BOT_TOKEN  

Get it from https://telegram.me/botfather. Here's how you can get it:

  • Send the /start command
  • Type /newbot
  • Send your bot's name
  • Send your bot's username

TELEGRAM_API_ID
TELEGRAM_API_HASH

Get them from https://my.telegram.com/apps. Here's how you can get it:

  • Login with your phone number
  • Create a new application: write the app title and a short name. The URL is not required
  • Click on Create application, then the api_id and the api_hash will show up.
  • See also: why not just the bot token?

MONGO_URL

Get it from https://mongodb.com. Here's how you can get it:

  • Register on https://www.mongodb.com/cloud/atlas/signup (MongoDB Atlas is MongoDB over the cloud: this way, you won't have to worry about installing and configuring your databases locally)
  • Create a new cluster (shared clusters are free)
  • Select the cloud provider and platform (AWS, GCP or Azure) and the cluster name
  • In Security » Network Access, whitelist your IP
  • In Security » Database Access, create a new username (use Password as the authentication method)
  • In Data storage » Cluster, click on Connect, then Connect your application
  • Select Python as the driver and 3.6 or later as the version
  • The connection string will show up. It starts with mongo+srv://

NETWORK_SHORT_NAME

Let it be anything you want (optional, defaults to tmnetbot). It is used both as database name and prefix of the session file

The correct format of the .env file is KEY = VALUE. For each variable give it its own line.

Description

tmnetbot is a Telegram bot. It allows your users to forward messages from their channel into yours. Useful for Telegram networks which do have a "best posts of the network" channel.

  • Can handle waiting threshold, so admins of the same channel can't flood.
  • Allows to set time ranges for when to send your messages, both for the network and the users.

Requirements

  • It has been tested on Python 3.8.2, but should work for every Python 3.6+ version.
  • Also, check out the requirements.txt file.
  • Everything else you need has been previously specified in the environment variables section.

Limitations

The entire bot has been coded in the the english language as my personal habit. However, since it was initially a private commitment, it has been designed to be used by Italians only. Every text is written in the Italian language, every date is therefore converted in CET/CEST (it depends on DST).

Internationalization is not yet a priority, but any help is welcome.

Special thanks

To atsetilam, who agreed to make it open source.

License

Copyright (C) 2020 Midblyte

Licensed under the terms of the GNU General Public License v3 or later (GPLv3+)