Unable to exchange Telegram

Hello,
I just installed the latest version of Gladys.
I wanted to test the Telegram integration.
I can’t « talk » to Gladys.

I did:
docker logs gladys
I see an error in the logs:
User with telegram_user_id "xxxxxxxxxx" not found

Do you have any idea what the problem might be?

Thanks for your help,

Best regards,
Lionel

Hello.

Have you followed the documentation here? Envoyer des notifications Gladys sur Telegram | Gladys Assistant
Are you sure about your username? You can send the /start message to the bot @userinfobot and it’s the ID you need to retrieve.

Indeed, I think you didn’t click on the link in Gladys that sends the /start message!

Hello,
Thank you for your extremely quick feedback.
This time, I created a new bot and redid the procedure to be sure. To no avail.
So, I don’t know what to do.
I will check the ID via @userinfobot tonight.
But is there a way to modify it manually?
Thank you
Best regards,
Lionel

Easily, no. You shouldn’t have to do that if the configuration works properly.

But this could help us debug.

@Mazshaka The problem isn’t the bot, it’s that you probably didn’t complete the process of linking Telegram and Gladys

Did you click on the link in Gladys, which redirected you to Telegram, and then send a message by clicking on a « start » button?

Good evening,

I have checked that the ID given in the error message is indeed mine.
So I understand that it is the telegram/gladys synchronization that is causing the problem.
When initializing, I downloaded Telegram on my PC. It offered me to scan a QR code with my phone, which I did.
I created my bot, entered the API key in Gladys, clicked on the link generation and clicked on send message.
It is possible that I missed something even if I think I did things right.
Still, I am stuck without much idea of how to solve this problem … :sweat_smile:

I just deleted my bot and did the same manipulations again and it works.
Is the first message you send to the bot indeed /start?

It seems fine to me. Out of curiosity, which Telegram application do you use when you click on « send message »?

When you send the first message, does Gladys reply with a « 👋 » message? Do you have any special logs?

What we don’t see during initialization is that when you are redirected to Telegram with the link generated from Gladys, a special token is added. When you send the /start message, the token is then sent in your startup message. It’s not just a message containing /start (Telegram hides the token), and Gladys then uses it to link your Gladys account to your Telegram account.

So it is very important to open the link on the same device where Telegram is installed. Is that what you are doing?

Your link should look like this:

https://telegram.me/YOUR_BOT_NAME?start=df6268b3aac5c14b6316935e428c7d98

The key at the end is the one used for deep linking.

Hello,
Thank you again for the quick responses. I tried to read a bit of the Telegram API documentation yesterday to better understand, but I quickly got lost :sweat_smile:.
During the two bot creations, I did get the handshake :waving_hand:.
I first tried to exchange with Telegram on PC (following the page opening during initialization) and then via the phone.
I will try again tonight by creating a new bot and a new API key.
In the meantime, I read that Telegram has updates. Notably on the authentication side. But I don’t know if this has any impact.
Thank you
Lionel

Very strange because if you have the hand emoji :waving_hand:, it means the linking was successful!

Do you have a screenshot of your conversation with the bot?



Here are screenshots of the 2 handshakes created by the bots.
I will try a third bot and keep you informed.
Thanks
Lionel

Another unsuccessful attempt.

Same error message:
2022-01-11T22:47:04+0100 index.js:16 (process.) NotFoundError: User with telegram_user_id « xxxxxxxxxx » not found
at User.getByTelegramUserId (/src/server/lib/user/user.getByTelegramUserId.js:33:11)
at async MessageHandler.newMessage (/src/server/services/telegram/lib/message.new.js:26:16)

Telegram Update:
https://core.telegram.org/bots/api#december-30-2021

December 30, 2021

Bot API 5.6

Ok @Mazshaka, let’s try to do the link manually!

Go to the Telegram integration page, and copy-paste the link to Telegram, it should look like this:

https://telegram.me/NOM_DE_TON_BOT?start=UNE_CLE

Copy-paste the key at the end, and send this message to Gladys via your Telegram:

/start UNE_CLE

This should redo the linking…

After that, I’m not sure this will improve the situation, because from what I see, you already have the emoji :waving_hand: which means Gladys is able to do the link.

Other possibility, try to restart your Gladys instance, by doing in SSH:

docker restart gladys

(it’s a bit the last resort, but well…)

@pierre-gilles thanks for the tips.
I did get the handshake but still no response from Gladys.
I still receive the same message in the logs even after a docker restart

NotFoundError: User with telegram_user_id « 508xxxxxx59 » not found
at User.getByTelegramUserId (/src/server/lib/user/user.getByTelegramUserId.js:33:11)
at async MessageHandler.newMessage (/src/server/services/telegram/lib/message.new.js:26:16)
}
2022-01-12T21:46:57+0100 index.js:16 (process.) NotFoundError: User with telegram_user_id « 508xxxxxx59 » not found
at User.getByTelegramUserId (/src/server/lib/user/user.getByTelegramUserId.js:33:11)
at async MessageHandler.newMessage (/src/server/services/telegram/lib/message.new.js:26:16)
2022-01-12T21:47:12+0100 index.js:15 (process.) unhandledRejection catched: Promise {
NotFoundError: User with telegram_user_id « 508xxxxxx59 » not found
at User.getByTelegramUserId (/src/server/lib/user/user.getByTelegramUserId.js:33:11)
at async MessageHandler.newMessage (/src/server/services/telegram/lib/message.new.js:26:16)
}
2022-01-12T21:47:12+0100 index.js:16 (process.) NotFoundError: User with telegram_user_id « 508xxxxxx59 » not found
at User.getByTelegramUserId (/src/server/lib/user/user.getByTelegramUserId.js:33:11)
at async MessageHandler.newMessage (/src/server/services/telegram/lib/message.new.js:26:16)
2022-01-12T21:48:06+0100 index.js:19 (Object.start) Starting Telegram service

I’m completely stuck on this one… I can’t reproduce your issue, and everything seems to be working fine on your end regarding the linking.

I don’t know how familiar you are with this, but a last option would be to check the database to see what is saved.

If you’re familiar enough, you can do this:

The Gladys database is located in the folder:

/var/lib/gladysassistant

If you stop Gladys:

docker stop gladys

You can then retrieve the file:

/var/lib/gladysassistant/gladys-production.db

This is a SQLite file that you can open with any software (ex: https://tableplus.com/)

Then you can go to the « t_user » table, and check if your « telegram_user_id » is correct :slight_smile:

After that, if it is the correct one, honestly, I’m lost, I don’t have any other ideas :confused:

Telegram ID
Hello,
@pierre-gilles thank you for taking the time to study the problem.
I followed your instructions. I connected via FTP to retrieve the file and open it with TablePlus.
The advantage of all this is that I’m learning a lot of things :slight_smile:
Screenshot attached.
The ID is correct except for the .0 at the end
Could this be the cause?
Thank you
Lionel

That’s great! You should take it that way :grin:

The ID is correct except for the .0 at the end
Could that be the cause?

Clearly! There must be a bug either in the Telegram library we’re using or on Gladys’s side when the ID is being saved…

Could you replace the ID in TablePlus with your user’s correct ID and save it?

Stop Gladys.

Then replace the SQLite file on your Pi.

Restart Gladys:

docker restart gladys

We’ll then investigate why this bug occurs (if you could create an issue on the Gladys GitHub, that would be great).

But at least we’ve found it!

Maybe we should replace the STRING with an INTEGER here?

No, on the contrary! It must be a string from start to finish, definitely not an integer :slight_smile: There must be a bad conversion somewhere.