gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

Is a sessionString required when logging in as a bot?

Open markfaulk350 opened this issue 4 years ago • 4 comments

I am using this NPM package in conjunction with node-telegram-bot-api. I need this package to get the Telegram ID's of all users in a group.

Up till now I've just assumed that I needed a sessionString when logging in as a bot.

Is this true? Is a sessionString required when logging in as a bot or can I leave it an empty string?

I tested locally without a sessionString and I was able to get a group roster. Is there any reason this shouldn't work in production?

Up till now I've been deploying my API to a Firebase serverless cloud function assuming that I needed a sessionString when logging in as a bot. I just realized that it doesn't work out of the box because cloud functions have dynamic IP's. From what I gather, making requests from different IP's using the same sessionString causes problems.

I get this error, same as issue #189 RPCError: 406: AUTH_KEY_DUPLICATED

I know there is a way to assign a static IP address to a Firebase Cloud Function but it is a bit tricky to setup.

Thank you!

markfaulk350 avatar Nov 15 '21 06:11 markfaulk350

I tested in production without a sessionString and it doesn't seem to work, so I guess my next question is if I can easily generate a new sessionString or authenticate in some way from inside a serverless function with a dynamic IP.

I don't want to have to setup a static IP if I don't have to.

markfaulk350 avatar Nov 15 '21 07:11 markfaulk350

If you don't use a StringSession (or StoreSession) the library will make a new login attempt each time you run the script.

for example, if you go to Settings> Privacy and Security you'll see that your account has multiple Active Sessions. Each time you login without a StringSession you create a new Session. if you do it a lot of times that may interfere with receiving updates from Telegram.

The easiest way is to generate a new Session locally. Use that in Firebase only and never use it locally after that.

painor avatar Nov 15 '21 11:11 painor

That is extremely helpful, thank you for responding so quickly!

I've been using the same session string to test locally and in production. I'll have to test and see if that solves the issue.

I'm not sure if the difference in IP is caused by going from local host to production or by cloud functions having dynamic IP's. I would assume both situations cause the same error but testing is the only way to find out.

markfaulk350 avatar Nov 15 '21 13:11 markfaulk350

never use it locally after that. Does using it once on a different IP completely destroy usage after that?

My home box came off VPN for 2 seconds and now login fails repeatedly.

humanbeingonearth avatar Jan 14 '22 08:01 humanbeingonearth