Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

How do i host telegram bot which is made using by python and uses webhook

$
0
0

I want to host my Telegram bot, which is built using Python, Flask, and utilizes webhooks. Currently, I am running it on a local server using ngrok. I have not found any proper articles on this. Can someone please help me out?

from flask import Flask, requestimport telebotfrom telebot import typesfrom supaHelper import SupaHelperimport osimport contantsimport timefrom datetime import datetime, timedeltaimport textwrap# Initialize Flask appapp = Flask(__name__)# Initialize the botbot = telebot.TeleBot(contants.BOT_ACCESS_TOKEN, parse_mode=None)obj = CheggHelper()supabase = SupaHelper()@app.route('/'+ contants.BOT_ACCESS_TOKEN, methods=['POST'])def webhook():    update = telebot.types.Update.de_json(request.stream.read().decode('utf-8'))    bot.process_new_updates([update])    return '', 200@app.route("/")def index():    return "Hello, this is your Telegram bot!"# Define message handlers@bot.message_handler(chat_types="private")def send_msg_to_bot(message):    try:        bot.send_message(message.chat.id,"Join group to get started or contact Admin 😊👍",reply_to_message_id=message.message_id)    except Exception as e:        bot.reply_to(message, str(e))# Run the Flask appif __name__ == "__main__":    bot.set_webhook(url=f"https://ngrockurl.app/{contants.BOT_ACCESS_TOKEN}")    app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>