Skip to content

Instantly share code, notes, and snippets.

@richardokonicha
Created June 30, 2020 16:12
Show Gist options
  • Save richardokonicha/936ced177ff6903d9594134b2d48980a to your computer and use it in GitHub Desktop.
Save richardokonicha/936ced177ff6903d9594134b2d48980a to your computer and use it in GitHub Desktop.
A Telegram bot flask template - webhook, getMessage, Debug setu
import telebot
import os
from config import *
from flask import Flask, request
server = Flask(__name__)
@server.route('/'+ TOKEN, methods=['POST'])
def getMessage():
request_object = request.stream.read().decode("utf-8")
update_to_json = [telebot.types.Update.de_json(request_object)]
bot.process_new_updates(update_to_json)
return "got Message bro"
@server.route('/hook')
def webhook():
url=URL
bot.remove_webhook()
bot.set_webhook(url + TOKEN)
return f"Webhook set to {url}"
@server.route('/')
def index():
return f"This is a Telegram bot {url}"
if DEBUG==True:
bot.remove_webhook()
bot.polling()
else:
if __name__ == "__main__":
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment