I am trying to host two bots on one local machine. For simplicity, let’s call one “Bot A” and other “Bot B”.
I made route for one as “mydomain.io/a”, for other as “mydomain.io/b”:
bot = TeleBot(TOKEN)
app = Flask(__name__)
bot.remove_webhook()
bot.set_webhook('mydomain.io/a')
@app.route('/a', methods=['POST'])
def tovc_webhook():
if request.headers.get('content-type') == 'application/json':
json_string = request.get_data().decode('utf-8')
update = types.Update.de_json(json_string)
bot.process_new_updates([update])
return ''
else:
abort(403)
...sum working code...
if __name__ == '__main__':
app.run()
And same code for another one, but bot.set_webhook(‘mydomain.io/b’), @app.route(‘/b’, methods=[‘POST’]) etc.
Any of the bots work by itself, but when i try to start both at the same time, – one, that was started first continues to work, but later one does not do anything.
(triple-checked that routes and webhooks and etc are not same, basically triple-checked everything)
Later I’ve come up with an idea. I’ve created one more file, “C.py”:
from a import bot as abot
from b import bot as bbot
app = Flask(__name__)
abot.remove_webhook()
abot.set_webhook('mydomain.io/a')
bbot.remove_webhook()
bbot.set_webhook(mydomain.io/b)
@app.route('/a', methods=['POST'])
def tovc_webhook():
if request.headers.get('content-type') == 'application/json':
json_string = request.get_data().decode('utf-8')
update = types.Update.de_json(json_string)
abot.process_new_updates([update])
return ''
else:
abort(403)
@app.route('/b', methods=['POST'])
def tovc_webhook():
if request.headers.get('content-type') == 'application/json':
json_string = request.get_data().decode('utf-8')
update = types.Update.de_json(json_string)
bbot.process_new_updates([update])
return ''
else:
abort(403)
if __name__ == '__main__':
app.run()
i.e. transferred and merged some of code of both bots into C.py.
Surprisingly, that did work, but I got two more problems with that.
Problem 1 – I can’t start bots separately now.
Problem 2 – for some reason, exceptions and error don’t show up anymore, as like I did try: <code> except: pass
.
What am i doing wrong?
Also, please, don’t ask why I need two bots at the same time on ngrok. Trust me.
(oh and also I don’t want to make bots on different ports for one reason)
heavennborn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.