I’m working with the Telegram API in my application and I need to handle updates.
The last line of the Working with Updates documentation says that Telegram can send push notifications for updates.
To subscribe to the push notifications, I need call the account.registerDevice
method and pass in the token
in the below format:
{
endpoint: Absolute URL exposed by the push service where the application server can send push messages,
keys: {
p256dh: Base64url-encoded P-256 elliptic curve Diffie-Hellman public key
auth: Base64url-encoded authentication secret
}
}
I have a few question about this data:
- Is
endpoint
the URL in my application that receives updates? - What is
p256dh
andauth
?
2
Answers
Yes
You have to create your own public key for your endpoint, as the communication is cryptographically secured.
The keys generated by the commands Semnodime provided don’t seem to work. I believe they are too long. You can try using the public key from the online key generator I linked below to see if that was the problem. This could result in a
WEBPUSH_KEY_INVALID
error.Additionally, make sure to convert the
token
object to a string withJSON.stringify
if you use node.js:This has worked for me:
Note that
auth
is just a random sequence of 16 octets encoded inbase64url
which can be generated with the following:There is a online key generator. If the link is broken, here is an archived page.
For more info on the key system, check this.
More info on
auth
.