Please improve doc and diagnostics on `api_id` and `api_hash` to prevent login rejection with misleading "User is already connected!"
Trying to login to my Telegram account via my newly installed bridge,
I got on the client side just a pretty generic message:
Unhandled exception while requesting code. Check console for more details.
The telegrambot console contained User is already connected!
This sounds like my Matrix user address is not accepted because I had connected it before to some other telegram bridge bot?
Does Telegram not like users being connected to more than one bridge? If so, I am stuck because the bridge that I had been using is defunct and I cannot even logout there.
Exception details from the console:
[2025-02-16 19:38:43,034] [[email protected]] Request caused struct.error: 'i' format requires -2147483648 <= number <= 2147483647: InvokeWithLayerRequest(layer=183, query=InitConnectionRequest(api_id=8073176532, device_model='mautrix-telegram', system_version='1.37.0a1', app_version='0.15.2', system_lang_code='en', lang_pack='', lang_code='en', query=GetConfigRequest(), proxy=None, params=None))
[2025-02-16 19:38:43,035] [[email protected].@....] Exception connecting to Telegram, retrying in 5s...
Traceback (most recent call last):
File "/opt/mautrix-telegram/lib/python3.10/site-packages/mautrix_telegram/abstract_user.py", line 331, in start
await self.client.connect()
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/telegrambaseclient.py", line 584, in connect
await self._sender.send(functions.InvokeWithLayerRequest(
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/network/mtprotosender.py", line 183, in send
state = RequestState(request)
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/network/requeststate.py", line 17, in __init__
self.data = bytes(request)
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/tlobject.py", line 194, in __bytes__
return self._bytes()
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/functions/__init__.py", line 357, in _bytes
self.query._bytes(),
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/functions/__init__.py", line 127, in _bytes
struct.pack('<i', self.api_id),
struct.error: 'i' format requires -2147483648 <= number <= 2147483647
[2025-02-16 19:38:48,044] [[email protected]] User is already connected!
[2025-02-16 19:38:48,044] [[email protected].@....] @... connected: True
[2025-02-16 19:38:48,180] [[email protected].@.....] Unknown RPC error in start(): <class 'telethon.errors.rpcerrorlist.ConnectionNotInitedError'>: Connection not initialized (caused by GetStateRequest)
[2025-02-16 19:38:48,269] [[email protected]] Error requesting phone code
Traceback (most recent call last):
File "/opt/mautrix-telegram/lib/python3.10/site-packages/mautrix_telegram/commands/telegram/auth.py", line 234, in _request_code
await evt.sender.client.sign_in(phone_number)
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/auth.py", line 328, in sign_in
me = await self.get_me()
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 175, in get_me
me = (await self(
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 30, in __call__
return await self._call(self._sender, request, ordered=ordered)
File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 91, in _call
result = await future
telethon.errors.rpcerrorlist.ConnectionNotInitedError: Connection not initialized (caused by GetUsersRequest)
The error seems to be saying the api_id is misconfigured
Thanks for the immediate response.
If the api_id is misconfigured, the error message should be clear on that.
At first, I had tried getting that api_id as documented from https://my.telegram.org/apps but that wonderful page just gives ERROR.
Then I tried using https://t.me/BotFather as suggested elsewhere, and this way I got:
Use this token to access the HTTP API:
8073...:AAHd...
I inserted this in config.yaml as follows:
telegram:
# Get your own API keys at https://my.telegram.org/apps
api_id: 8073...
api_hash: AAHd...
# (Optional) Create your own bot at https://t.me/BotFather
bot_token: disabled
Is this fine, or how to adapt?
BotFather is for creating bots, it can't be used to get api keys
So I tried again using https://my.telegram.org/apps
this time choosing the 'iOS' option (rather than 'Android' or 'Web' as I tried before).
This time, I got no ERROR but correct api_id and api_hash which worked fine!
So, problem solved for me - thank you 👍
Still,
- user guidance on https://docs.mau.fi/bridges/general/initial-config.html how to obtain the
api_idandapi_hashfrom Telegram should be improved (see PR), and - the poor and even misleading diagnostic output of the telegram bridge that I quoted in my OP should be fixed.