In Telegram, when the user presses a button, the bot receives this information in JSON:
'update':
{
'callback_query':
{
'from':
{
'id':420220883
}
}
}
There are more information in this JSON object, but I’m only interested in the id
part.
Now when I want to access it like update.callback_query.from.id
, it obviously gives an SyntaxError
error, since from
is a Python keyword.
So my quetion is; How can I go about using this information?
Note that I have tried using it like a dictionary update['callback_query']['from']['id']
, but it gives an odd-looking error.
2
Answers
I suppose my question is duplicate!
The problem has been fixed by the author of the library. I should've simply changed
from
tofrom_user
!I found the answer here.
The data structure you have posted is not a valid JSON nor a valid dict. After converting it to a valid dict you can easily get the ‘id’
Output