Skip to content

Instantly share code, notes, and snippets.

@bakirillov
Last active April 10, 2020 08:36
Show Gist options
  • Save bakirillov/e66d6769858453d2a90f7b6031fb5e23 to your computer and use it in GitHub Desktop.
Save bakirillov/e66d6769858453d2a90f7b6031fb5e23 to your computer and use it in GitHub Desktop.
Minimal telegram bot that works on Heroku
import os
import json
import telebot
from flask import Flask
ih = open("config.json", "r")
config = json.load(ih)
ih.close()
TOKEN = config["bot_token"]
URL = config["bot_url"]
bot = telebot.TeleBot(TOKEN)
server = Flask(__name__)
@server.route('/'+TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return("!", 200)
@server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url=URL+TOKEN)
return("!", 200)
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