I try to use telegram bot connect website, when I open the website, I get the query and hash when I validate throw node.js and not equal
const key = crypto.createHash('sha256').update(my_bot_token).digest()
const validateHash = crypto.createHmac('sha256', key).update('auth_date=1646xxxnfirst_name=namexxxnid=1231xxxxnAusername=alexLxxx').digest('hex')
console.log(hash === validateHash) false
I don’t know where I am going wrong I try to use the npm package telegram-checking-authorization, but the same error
2
Answers
You should add all field data you receive from the request callback but remove the
hash
field.Ex:
I try and succeed.
It happened to me as well, I described it in My question. You might copy the response from this API:
https://oauth.telegram.org/auth/get?bot_id=xxx
sometimes the response works with the function, sometimes it doesn’t, and honestly, I don’t understand why. Try to printuser
to console and check if the two hashes match!What I have done is as follow:
I changed my bot’s domain to
https://www.w3schools.com/
and go to w3school online editorhttps://www.w3schools.com/js/tryit.asp?filename=tryjs_string_indexof
for example, printuser
object to console (replace the javascript in the online editor with code bellow and then replace YOUR-BOT-NAME in the code with the name of your bot):