My program is supposed to reply Telegram messages the user's account receives with a user-defined text. This text can be changed by sending a message to a telegram bot.
For the bot, I've been using PyTelegramBotAPI, and for sending messages from the user's account I've been using Telethon.
I can run the bot by calling bot.polling()
and it works fine.
The Telethon Client also works fine separately, It has methods like:
async def run():
self.add_event_handler(self.message_handler, events.NewMessage)
while True:
#(Every Second the while is supposed to be checked)
if(condition):
do_something()
async def message_handler(self, event):
do_another_thing()
and to start running the client I would just:
loop = asyncio.get_event_loop()
loop.run_until_complete(client.run())
But I can't make them run simultaneously.
I've tried:
asyncio.get_event_loop().run_until_complete(asyncio.gather(
bot.bot.polling(none_stop=True, interval=0.1, timeout=15),
client.run()
))
to run both of them simultaneously, but this only runs the bot.
I've also tried:
executor = ProcessPoolExecutor(2)
loop = asyncio.get_event_loop()
boo = asyncio.create_task(loop.run_in_executor(executor, bot.bot.polling(none_stop=True, interval=0.5, timeout=15)))
baa = asyncio.create_task(loop.run_in_executor(executor, client.run()))
but it doesn't work either.
could you please tell me how to run the bot and client at the same time?