My PythonAnywhere webhook for Telegram Bot API triggers a ‘Bad Request’ error. How can I adjust the webhook setup to resolve this issue? See below snippet:
import time
from flask import Flask, request
import custombot
API_KEY = 'your_api_key_here'
HOST_NAME = 'user.pythonanywhere.com'
PORT_NUM = 9000
app = Flask(__name__)
bot_obj = custombot.Bot(API_KEY)
@app.route('/' + API_KEY, methods=['POST'])
def process_update():
payload = request.get_json(force=True)
update_instance = custombot.Update.from_dict(payload, bot_obj)
bot_obj.send_message(chat_id=update_instance.message.chat_id, text='Hi there!')
return 'Success'
if __name__ == '__main__':
time.sleep(3)
app.run(host='0.0.0.0', port=PORT_NUM, debug=False)
import sys
project_folder = '/home/user/telegram_project'
if project_folder not in sys.path:
sys.path.insert(0, project_folder)
from app_main import app as application