Unable to exchange Telegram

Well, after struggling a bit to change the file permissions to update it via FTP transfer, I was able to update the user ID in

gladys-production.db

I restart Gladys and then update the token.
And that’s where it gets interesting: I reconnect to Telegram and bam it still doesn’t work!
I check the ID in the db again and there, surprise, the .0 is back
As if it gets added when the link is generated.
So I create the GitHub issue. (Or at least I try :blush: )
Thanks

Issue GitHub created Error User with telegram_user_id “xxxxxxxxxxx” not found

Shoot! We’ll have to debug this, but it’s going to be very complicated because it’s a bug that only happens with your account due to your identifier…

Do you have any Node.js development skills or not at all?

We use this library in Gladys:

I wouldn’t be surprised if the cast happens on their end during the parsing of the data returned by the Telegram API, so we’ll need to write a piece of code that tests only the library’s code?

I’m not very familiar with it, but I’ll try to see what I can do to debug :slight_smile:

Okay, let us know if you need help :slight_smile:

Hello!
Thank you for this thread, I have exactly the same problem as described above… I did the same checks, and bingo! My userid also has a .0 at the end :frowning:

Crazy, that confirms the issue! Thanks for your feedback @Christophe_LOCHON :slight_smile:

Do you have some technical skills to help us see where the problem comes from? The issue is that not having a Telegram account with an ID that causes problems (ending with 0), I can’t reproduce the issue at home

Hello @pierre-gilles! Apart from providing you with logs, I unfortunately have few skills in the field of programming…

Okay, we’ll wait for @Mazshaka’s return then.

It works :slight_smile: I also tried recreating everything, the behavior is the same.

Hello,
First of all, thanks to @Christophe_LOCHON that confirms the bug :slight_smile:
As for the rest, to be honest, I haven’t really made progress in debugging because I don’t really know how to go about it.
If I understand the operation correctly, when the API key is entered in Gladys, there is a call to Telegram which parses the key, confirms that it is valid and returns (or deduces) the associated user ID.
During initialization, this user ID is saved in the Gladys database.
It is then used to make the link during Telegram/Gladys exchanges.

For me there are 2 problems:
1/ during initialization the user ID is returned (or at least saved) with a .0 at the end
We also notice that even if we delete the .0 at the end of the ID in the database and we do another connection test with Telegram, the ID is then modified again with a .0.
Hence problem 2:
2/ The Telegram ID is saved during each exchange instead of simply « matching » with the one available in the database…

Now I don’t know how to « monitor » these exchanges to confirm all this and find out where the problem comes from.

@Mazshaka Actually, I suspect the library we are using is making a mistake when parsing the Telegram API response, as the library already returns a « Number » in JavaScript.

Therefore, you would need to run a test with just a piece of JavaScript on your machine using the library’s example code: GitHub - yagop/node-telegram-bot-api: Telegram Bot API for NodeJS · GitHub

The example code is the one in the README:

const TelegramBot = require('node-telegram-bot-api');

// replace the value below with the Telegram token you receive from @BotFather
const token = 'YOUR_TELEGRAM_BOT_TOKEN';

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});

// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
  const chatId = msg.chat.id;

  console.log(msg);
});

You would need to run this piece of code on your machine, then send a message to the bot with your user.

Otherwise, another possibility is that you send me your API key (privately, from a dummy bot created for the test) and I do the test on my machine, but this implies that you are in front of your phone at the time I do the test to be able to send a message :slight_smile:

Thanks @pierre-gilles!

It’s clearer now. I’ll look into it this weekend and keep you posted.

Worst case, we can always coordinate for testing if I get stuck.

Have a good day

Re,
I need a little help.
I don’t know where to put the .js file.
Unless I’m mistaken, Gladys uses URL routes to access the file.
So I don’t know where I can put the file to access it.
Or maybe I can run it via a command.
But I’m not sure about that either…
So if you could guide me :innocent:
Thanks!
Best regards,
Lionel

In fact, that has nothing to do with Gladys, what I was talking about :slight_smile: I suggested installing the library on your computer and running a test. After that, you need a Node.js development environment on your machine. If you’ve never done that before, the step might be a bit high.

Hello @pierre-gilles,

So to be complete, I did think about running the pi script. I understood that it didn’t work like that. However, I did install Node.js on the instance to be able to run npm commands. But I don’t know if it’s useful and/or sufficient?

I admit that from there I wouldn’t know how to go any further without more in-depth help… like step by step :sweat_smile:

Or a link to a tutorial?

Otherwise, I can always send you my API key so you can test it.

Thanks

It might be easier if you send me:

  • your API key in a private message
  • your Telegram ID
  • you send a message to the bot

Thanks for the message! I have received all the information on my side.

Fortunately, the bug is not on the side of the lib that sends a well-formatted chatId but indeed as a Number.

We need to investigate on Gladys’s side now.

If someone has a bit of time here and would like to work on the bug, the issue with the information is here:

Hello everyone!

I just worked on the bug this morning. I isolated the cause of the bug on Gladys’s side, indeed we were receiving the ID as a JS Number, except that the cast to a String for the DB was done automatically by Sequelize, and I think it thought our Number was a float.

By doing the cast ourselves in the Telegram service with a .toString(), the bug is no longer present.

I wrote a whole battery of tests to make sure the problem doesn’t happen again.

The fix is in this PR:

https://github.com/GladysAssistant/Gladys/pull/1442

Thanks to those who took the time to give me the right information, it’s a pretty funny bug because it only affected 10% of users, because the cast seems to take this number for a float only if your Telegram ID ends with a 9! 1 in 10 chance :stuck_out_tongue:

For information, I’ve merged the PR and made a Docker build on the dev tag (gladysassistant/gladys:dev)

The fix will be included in the next release of Gladys!