M
M
MatiVip2022-04-11 03:59:45
Python
MatiVip, 2022-04-11 03:59:45

How to normally run a python bot on heroku?

I wanted to create a "single-cell" bot for telegrams. I found an elementary simple solution on the Internet, successfully adjusted it to my needs and tested it thanks to PyCharm on my hardware. After all of the above, a logical question arose: how to make the bot work 24/7. Useful to look for free hosting and stumbled upon Heroku. After I figured it out, it's time to test my work. And here it is the moment of truth: there are no errors, no warnings, everything seems to be fine. But I did not take into account one factor: when the bot connects from a new device, it needs authorization (it asks for a phone number, then a confirmation code). And that's it! This is where I hung. I tried different ways to avoid authorization, but I can't think of anything.
(I tried to run through the Heroku bash console, but this starts a separate session)

So the question itself is: How can I start the bot so that I can manually log into the account, and it will continue to work on its own or how to log in to the bot running hosting?

from telethon import TelegramClient, events
api_id = '5555555'
api_hash = 'a1a1a1a1aa1a1a1a1a1a1a1a'
client = TelegramClient('anon', api_id, api_hash)
client.start()
@client.on(events.NewMessage(-111111111111))
async def main(event):
   await client.send_message(-2222222222222, event.message)
client.run_until_disconnected()


62537b731f850659523204.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2022-04-11
@Dr_Elvis

You launch the bot on your PC, log in, the bot creates authorization files - you upload them to the server next to the bot and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question