├── .github └── dependabot.yml ├── Procfile ├── README.md ├── bot.py ├── funding.json └── requirements.txt /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "pip" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: python3 bot.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram_bot_py_heroku 2 | Simple telegram bot in python that hosts on Heroku 3 | https://dspyt.com/simple-telegram-bot-in-python-hosted-easily-on-heroku/ 4 | ## Hosting on Heroku 5 | 6 | ```bash 7 | git init 8 | heroku create "app-name" 9 | git remote -v 10 | git add . 11 | git commit -m "commit" 12 | git push heroku master 13 | ``` 14 | -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | from telegram.ext import Updater, CommandHandler, MessageHandler, Filters 4 | 5 | # Enable logging 6 | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 7 | level=logging.INFO) 8 | 9 | logger = logging.getLogger(__name__) 10 | 11 | PORT = int(os.environ.get('PORT', '8443')) 12 | 13 | # Define a few command handlers. These usually take the two arguments update and 14 | # context. Error handlers also receive the raised TelegramError object in error. 15 | def start(update, context): 16 | """Send a message when the command /start is issued.""" 17 | update.message.reply_text('Hi!') 18 | 19 | 20 | def help(update, context): 21 | """Send a message when the command /help is issued.""" 22 | update.message.reply_text('Help!') 23 | 24 | 25 | def echo(update, context): 26 | """Echo the user message.""" 27 | update.message.reply_text(update.message.text) 28 | 29 | 30 | def error(update, context): 31 | """Log Errors caused by Updates.""" 32 | logger.warning('Update "%s" caused error "%s"', update, context.error) 33 | 34 | 35 | def main(): 36 | """Start the bot.""" 37 | # Create the Updater and pass it your bot's token. 38 | # Make sure to set use_context=True to use the new context based callbacks 39 | # Post version 12 this will no longer be necessary 40 | TOKEN = '' 41 | APP_NAME='https://app-name.herokuapp.com/' 42 | 43 | updater = Updater(TOKEN, use_context=True) 44 | 45 | # Get the dispatcher to register handlers 46 | dp = updater.dispatcher 47 | 48 | # on different commands - answer in Telegram 49 | dp.add_handler(CommandHandler("start", start)) 50 | dp.add_handler(CommandHandler("help", help)) 51 | 52 | # on noncommand i.e message - echo the message on Telegram 53 | dp.add_handler(MessageHandler(Filters.text, echo)) 54 | 55 | # log all errors 56 | dp.add_error_handler(error) 57 | updater.start_webhook(listen="0.0.0.0",port=PORT,url_path=TOKEN,webhook_url=APP_NAME + TOKEN) 58 | updater.idle() 59 | 60 | 61 | if __name__ == '__main__': 62 | main() -------------------------------------------------------------------------------- /funding.json: -------------------------------------------------------------------------------- 1 | { 2 | "opRetro": { 3 | "projectId": "0x1a26744683129e6e36c790c4d9ed2aba3fa08b02a1a127c5805241b9a442de3a" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | APScheduler==3.11.0 2 | cachetools==5.5.2 3 | certifi==2025.1.31 4 | python-telegram-bot==22.0 5 | pytz==2025.2 6 | six==1.17.0 7 | tornado==6.4.2 8 | tzlocal==5.3.1 9 | --------------------------------------------------------------------------------