├── Procfile ├── requirements.txt ├── .gitignore ├── .env.sample ├── ReadMe.md ├── TelethonBot ├── __init__.py ├── plugins │ └── start.py ├── utils.py └── __main__.py └── app.json /Procfile: -------------------------------------------------------------------------------- 1 | BotzHub: python -m TelethonBot -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-decouple 2 | telethon -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | __pycache__/ 3 | BotzHub.session 4 | BotzHub.session-journal 5 | -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | # By < @xditya > 2 | # // @BotzHub // 3 | 4 | # Add your vars here! 5 | 6 | API_ID= 7 | API_HASH= 8 | BOT_TOKEN= -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # Telethon Bot 2 | Simple base used to make a Telegram Bot in [telethon](https://github.com/LonamiWebs/Telethon). 3 | 4 | Join [@BotzHub](https://t.me/BotzHub)! 5 | 6 | Note: The `client`, here, is named `BotzHub`. 7 | 8 | Fork and add your plugins to [TelethonBot/plugins](./TelethonBot/plugins), and, thats it! 9 | 10 | # Deploying 11 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 12 | 13 | # Credits 14 | - [Telethon.](https://github.com/LonamiWebs/Telethon) 15 | - [Me.](https://t.me/xditya) 16 | -------------------------------------------------------------------------------- /TelethonBot/__init__.py: -------------------------------------------------------------------------------- 1 | # By < @xditya > 2 | # // @BotzHub // 3 | 4 | from telethon import TelegramClient 5 | from decouple import config 6 | import logging 7 | import time 8 | 9 | logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', 10 | level=logging.WARNING) 11 | 12 | # Basics 13 | APP_ID = config("APP_ID", default=None, cast=int) 14 | API_HASH = config("API_HASH", default=None) 15 | BOT_TOKEN = config("BOT_TOKEN", default=None) 16 | 17 | BotzHub = TelegramClient('BotzHub', APP_ID, API_HASH).start(bot_token=BOT_TOKEN) -------------------------------------------------------------------------------- /TelethonBot/plugins/start.py: -------------------------------------------------------------------------------- 1 | # By < @xditya > 2 | # // @BotzHub // 3 | from .. import BotzHub 4 | from telethon import events, Button 5 | 6 | @BotzHub.on(events.NewMessage(incoming=True, pattern="/start")) 7 | async def start(event): 8 | await event.reply("Hello!", 9 | buttons=[ 10 | [Button.url("ButtonUrl", url="https://t.me/xditya")], 11 | [Button.inline("Inline Button",data="example")] 12 | ]) 13 | 14 | @BotzHub.on(events.callbackquery.CallbackQuery(data="example")) 15 | async def ex(event): 16 | await event.edit("You clicked a button!") -------------------------------------------------------------------------------- /TelethonBot/utils.py: -------------------------------------------------------------------------------- 1 | # By < @xditya > 2 | # // @BotzHub // 3 | 4 | import sys 5 | import logging 6 | import importlib 7 | from pathlib import Path 8 | 9 | def load_plugins(plugin_name): 10 | path = Path(f"TelethonBot/plugins/{plugin_name}.py") 11 | name = "TelethonBot.plugins.{}".format(plugin_name) 12 | spec = importlib.util.spec_from_file_location(name, path) 13 | load = importlib.util.module_from_spec(spec) 14 | load.logger = logging.getLogger(plugin_name) 15 | spec.loader.exec_module(load) 16 | sys.modules["TelethonBot.plugins." + plugin_name] = load 17 | print("TelethonBot has Imported " + plugin_name) 18 | -------------------------------------------------------------------------------- /TelethonBot/__main__.py: -------------------------------------------------------------------------------- 1 | # By < @xditya > 2 | # // @BotzHub // 3 | 4 | import glob 5 | from pathlib import Path 6 | from TelethonBot.utils import load_plugins 7 | import logging 8 | from . import BotzHub 9 | 10 | logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', 11 | level=logging.WARNING) 12 | 13 | path = "TelethonBot/plugins/*.py" 14 | files = glob.glob(path) 15 | for name in files: 16 | with open(name) as a: 17 | patt = Path(a.name) 18 | plugin_name = patt.stem 19 | load_plugins(plugin_name.replace(".py", "")) 20 | 21 | print("Successfully deployed!") 22 | print("Enjoy! Do visit @BotzHub") 23 | 24 | if __name__ == "__main__": 25 | BotzHub.run_until_disconnected() 26 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TelethonBot", 3 | "description": "Simple basic code for a telegram bot in Telethon.", 4 | "logo": "", 5 | "keywords": [ 6 | "telegram", 7 | "telethon", 8 | "telegram-bot", 9 | "botzhub" 10 | ], 11 | "repository": "https://github.com/xditya/TelethonBot", 12 | "website": "xditya.me", 13 | "success_url": "https://t.me/BotzHub", 14 | "env": { 15 | "API_HASH": { 16 | "description": "You API HASH from my.telegram.org", 17 | "value": "" 18 | }, 19 | "APP_ID": { 20 | "description": "You API ID from my.telegram.org", 21 | "value": "" 22 | }, 23 | "BOT_TOKEN": { 24 | "description": "Bot token, get it from @BotFather.", 25 | "value": "" 26 | } 27 | }, 28 | "buildpacks": [ 29 | { 30 | "url": "heroku/python" 31 | } 32 | ] 33 | } --------------------------------------------------------------------------------