Genome
Genome

Reputation: 15

Need to enter telegram code after starting python bot

I choose heroku for use my simple python script that gets telegram messages and parses them. So when i start the script on heroku it asked for telegram number and confirmation code, but i cant to enter them because i started it by command: heroku ps:scale bot=1 and have no access to heroku terminal. Is there a solution to this problem?

Upvotes: 0

Views: 524

Answers (3)

ArnabXD
ArnabXD

Reputation: 519

Official Docs

Process -

  • You need to generate a session and save it somewhere like Environmental Variables
  • You use the saved session we need StringSession

Generate Session :

from telethon.sync import TelegramClient
from telethon.sessions import StringSession

with TelegramClient(StringSession(), api_id, api_hash) as client:
    print(client.session.save())

Save this printed session in environmental variables

Use the printed session :

from telethon.sync import TelegramClient
from telethon.sessions import StringSession

with TelegramClient(StringSession(string), api_id, api_hash) as client:
    # ....

By doing this you don't need to generate session again and again

Upvotes: 0

Artis7eer
Artis7eer

Reputation: 1

I think you need to pass your session string in telethon

Upvotes: 0

AJTimePyro
AJTimePyro

Reputation: 26

You don't need to enter code everytime, because once you logged in, it will create a session file. So use that session file.

Upvotes: 1

Related Questions