diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2364b63 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/Lib +/Scripts +/Include +pyvenv.cfg \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..ab678e0 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python3 app.py \ No newline at end of file diff --git a/README.md b/README.md index b2ebc8c..13879fe 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -# PythonHerokuTutorial \ No newline at end of file +# Python-Heroku Tutorial + +This repository contains all the files required to deploy python application on Heroku. Heroku is a cloud plateform which enables the developers/user to deploy, scale, manage and montor +their application. + +In this project, a python telegram bot is deployed in Heroku. + +You can use the bot on telgram: @mimic_app_bot diff --git a/app.py b/app.py new file mode 100644 index 0000000..2a388ab --- /dev/null +++ b/app.py @@ -0,0 +1,56 @@ +from telegram.ext import Updater +from telegram.ext import CommandHandler, MessageHandler, Filters +import os +import json + +#telegram token +TOKEN = os.environ.get("TELEGRAM_ID") + +#commandhandler for start command +def start(update, context): + yourname = update.message.chat.first_name + + msg = "Hi "+yourname+"! Welcome to mimic bot." + context.bot.send_message(update.message.chat.id, msg) + +#Message handler for texts only +def mimic(update, context): + context.bot.send_message(update.message.chat.id, update.message.text) + + +#commandhandler for details command +def details(update, context): + context.bot.send_message(update.message.chat.id, str(update)) + +#Error handler +def error(update, context): + context.bot.send_message(update.message.chat.id, "Oops! Error encountered!") + +#main logic +def main(): + + #to get the updates from bot + updater = Updater(token=TOKEN, use_context=True) + + #to dispatch the updates to respective handlers + dp = updater.dispatcher + + #handlers + dp.add_handler(CommandHandler("start",start)) + dp.add_handler(CommandHandler("details", details)) + + dp.add_handler(MessageHandler(Filters.text, mimic)) + + + dp.add_error_handler(error) + + #to start webhook + updater.start_webhook(listen="0.0.0.0",port=os.environ.get("PORT",443), + url_path=TOKEN, + webhook_url="https://mimic-app.herokuapp.com/"+TOKEN) + updater.idle() + +#start application with main function +if __name__ == '__main__': + main() + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1d7bf0a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +APScheduler==3.6.3 +cachetools==4.2.2 +certifi==2021.10.8 +python-telegram-bot==13.8.1 +pytz==2021.3 +pytz-deprecation-shim==0.1.0.post0 +six==1.16.0 +tornado==6.1 +tzdata==2021.5 +tzlocal==4.1