How to setup Telegram Verification Platform

Telegram’s new Verification Platform allows services to authenticate user identities via Telegram, offering an alternative to traditional SMS. This API-based service significantly reduces verification costs, enhances security, and ensures rapid, reliable message delivery to Telegram’s vast user base. Besides lowering costs, it allows businesses to monitor performance through detailed statistics, boost audience trust, and connect with over 950 million active users. If you're looking to implement this platform, we can guide you through the setup process in our detailed instructions to make the process seamless.

For more information, see Telegram Gateway.

This guide will walk you through the setup of Telegram’s Verification Platform, providing detailed steps and code snippets for implementing each part of the process.


1. Account Setup and API Access

Begin by registering on the Telegram Gateway platform and logging in with your Telegram number. Once logged in, fund your account to cover verification costs and obtain your API token, which is required to authenticate each API request.


2. Sending Verification Codes

To initiate verification, use the sendVerificationMessage endpoint, which sends a message with a unique verification code to the user. Here’s a Python example to get you started:


import requests

def send_verification_message(user_id, api_token, message_text="Your verification code is: 1234"):
    url = "https://api.telegram.org/gateway/sendVerificationMessage"
    payload = {
        "user_id": user_id,
        "api_token": api_token,
        "message_text": message_text
    }
    response = requests.post(url, data=payload)
    return response.json()

This function takes in a user ID, API token, and an optional message text. It sends a request to Telegram’s server, returning a response that indicates whether the message was successfully sent.


3. Optional: Check if a User Can Receive Messages

Using checkSendAbility ensures that the user is eligible to receive Telegram messages before sending a verification code, which can help avoid failed deliveries.


def check_send_ability(user_id, api_token):
    url = "https://api.telegram.org/gateway/checkSendAbility"
    payload = {"user_id": user_id, "api_token": api_token}
    response = requests.post(url, data=payload)
    return response.json()

This function sends a request to check if the user is available to receive messages. If the response indicates they can’t receive messages, you may want to handle this situation by notifying the user or retrying later.


4. Receiving Delivery Status Updates

Telegram allows you to set a callback_url where it sends delivery reports for verification messages. Configure this URL to automatically track the status of sent messages. Here’s an example of handling such a callback on a server:


from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/callback', methods=['POST'])
def delivery_status_callback():
    data = request.get_json()
    user_id = data.get("user_id")
    status = data.get("status")
    # Handle the status update, e.g., log it or update the user's record
    return jsonify({"status": "received"})
    
if __name__ == '__main__':
    app.run(port=5000)

This script uses Flask to create a simple server to receive status updates, which you can configure on Telegram’s platform. The callback URL provides updates on message delivery and allows you to handle errors or retries if needed.


5. Verifying User Responses

Once the user enters the verification code they received, you need to check if it matches. The checkVerificationStatus method will confirm the code’s validity. Here’s how you can set it up:


def check_verification_status(user_id, api_token):
    url = "https://api.telegram.org/gateway/checkVerificationStatus"
    payload = {"user_id": user_id, "api_token": api_token}
    response = requests.post(url, data=payload)
    return response.json()

This function verifies if the user-entered code is correct by sending the user_id and api_token to Telegram’s server. The server’s response will confirm if the code is valid, allowing the user access to authenticated actions.

Additional Resources

By following these steps, you’ll have a fully functional verification system using Telegram’s platform. For further customization and advanced settings, refer to the official Telegram Verification Platform Guide.


1 Comments

Leave a Comment