Run flask and telebot at the same time

This commit is contained in:
Administrator 2022-03-12 19:44:58 +01:00
parent 3f2b2379fe
commit e043fcda7f
2 changed files with 27 additions and 7 deletions

17
app.py
View File

@ -1,12 +1,25 @@
import multiprocessing as mp
import time
from flask import Flask
from bot import bot
app = Flask(__name__)
@app.route('/')
def hello_world(): # put application's code here
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
proc1 = mp.Process(target=app.run, args=())
proc1.start()
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
print(f"[EXCEPTION] {e}")
time.sleep(15)

17
bot.py
View File

@ -3,25 +3,31 @@
# text bot at t.me/projektaktienbot
# API Documentation https://core.telegram.org/bots/api
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
import os
import telebot
import time
import sys
import logging
from telebot import types
bot = telebot.TeleBot("5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs")
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Thank you for using this bot")
bot.reply_to(message, "Thank you for using this bot")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
answer = message.text + ' ID: ' + str(message.from_user.id)
bot.reply_to(message, answer)
answer = message.text + ' ID: ' + str(message.from_user.id)
bot.reply_to(message, answer)
telebot.logger.setLevel(logging.DEBUG)
@bot.inline_handler(lambda query: query.query == 'text')
def query_text(inline_query):
try:
@ -31,6 +37,7 @@ def query_text(inline_query):
except Exception as e:
print(e)
def main_loop():
bot.infinity_polling()
while 1: