Just like the banking sector we need to KYC user account to verify the valid user. generally, we manage all the things either send the image via email or hand to hand or courier. but telegram brought amazing feature which will do your KYC online where your data encrypted so only you and KYC user can see those data. it has been a lot used in cryptocurrency industries.

let see how we can create this KYC bot using Telegram Passport API . since we are going to do on the web we use their javascript library. no worry we’ll see in a later section where we can download that library.

Step 1: Create telegram bot

Open your telegram and goto @BotFather to create a bot. click here

  • Type command /newbot
  • Enter your bot name
  • Enter your bot username
    • your bot username must end with bot either devnetworkbot or devnetwork_bot

Our bot is ready, now we need to add a public key in our bot let’s generate private and public key

Step 2: Generate private/public key

Generate a private key:
openssl genrsa 2048 > private.key
Generating your public key
openssl rsa -in private.key -pubout
openssl rsa -in private.key -pubout

Use the /setpublickey command with @BotFather to connect this public key with your bot.

Step 3: Privacy Policy

This option is optional but I am suggesting you add Privacy and Policy. you can do this by below command

Add a link to your Privacy Policy by using the /setprivacypolicy command. Users will see this link when offered to authorize you to access their data.

Step 4: Implement Passport

we can use one of these SDKs

Since I am using for the web I’ll use JavaScript SDK.

<script src="telegram-passport.js"></script>
<div id="telegram_passport_auth"></div>
  Telegram.Passport.createAuthButton('telegram_passport_auth', {
    bot_id:       548754, // place id of your bot here
    scope:        {
    			  	data: [
        			  		type: 'id_document',
        			  		selfie: true
      			v: 1
    public_key:   '-----BEGIN PUBLIC KEY----- ...', // place public key of your bot here
    nonce:        'ab2df83746a87d2f3bd6...', // place nonce here
    callback_url: 'https://devnetwork.com/callback/' // place callback url here

Request Parameters

Use the following parameters to request information with the SDK:

Parameters Type Required Description
bot_id Integer Yes Unique identifier for the bot. You can get it from bot token. For example, for the bot token,1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy the bot id is 1234567.
scope PassportScope Yes A JSON-serialized object describing the data you want to request
public_key String Yes Public key of the bot
nonce String Yes Bot-specified nonce. Important: For security purposes it should be a cryptographically secure unique identifier of the request. In particular, it should be long enough and it should be generated using a cryptographically secure pseudorandom number generator. You should never accept credentials with the same nonce twice.

Note: Remember one thing while adding your public key, escape all the necessary symbol. for example ‘/‘ we need to escape this symbol  like this ‘\/

For demo use this link

For more documentation use this link

Notify of
Inline Feedbacks
View all comments

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.