Reputation: 83
I am using Heroku to host a Telegram Bot script in python using Flask.
I've gone through the process of setting everything up, including the git, the virtual enviroment ( #py -m venv env
+ #env\Scripts\activate
and the script... It gives no errors but it doesn't run...
I've installed Flask and Gunicorn in the env:
#pip install flask
#set FLASK_APP=app.py
#pip install gunicorn
FILES IN THE PROJECT:
.gitignore ->
env
Procfile ->
web: gunicorn deploy:app
deploy.py ->
import os
from flask import Flask, request
import telebot
TOKEN = 'My token here'
bot = telebot.TeleBot(TOKEN)
app = Flask(__name__)
@bot.message_handler(commands=['start'])
def start(message):
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
bot.reply_to(message, message.text)
@app.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
@app.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url='My Url here' + TOKEN)
return "!", 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
Upvotes: 0
Views: 1665
Reputation: 123
I Think problem associated with procfile .first check whether you add gunicorn
to requirements.txt
file or not .According to me instead of using Gunicorn just deploy with Common Procfile .
Try with this procfile
Procfile
-- web : python deploy.py
Upvotes: 1