Skip to main content

Python client for Telegram Gateway verification API

Project description

telegram-gateway-verification

Python-библиотека для отправки кодов верификации через Telegram Gateway API.

Возможности

  • Отправка кода верификации (sendVerificationMessage)
  • Проверка возможности отправки (checkSendAbility)
  • Проверка статуса верификации (checkVerificationStatus)
  • Отмена отправленного запроса (revokeVerificationMessage)
  • Проверка подписи webhook callback (X-Request-Timestamp, X-Request-Signature)

Установка

pip install telegram-gateway-verification

Установка для локальной разработки:

pip install -e '.[dev]'

Быстрый старт

import os

from telegram_gateway_verification import TelegramGatewayClient

client = TelegramGatewayClient(
    api_token=os.environ["TELEGRAM_GATEWAY_TOKEN"],  #https://gateway.telegram.org/account/api
)

status = client.send_verification_message(
    phone_number="+15551234567",
    code_length=6,
    ttl=60,
    callback_url="https://example.com/webhooks/telegram-gateway",
)

print(status.request_id)

API

send_verification_message(...) -> RequestStatus
check_send_ability(phone_number=...) -> RequestStatus
check_verification_status(request_id=..., code=...) -> RequestStatus
revoke_verification_message(request_id=...) -> bool

Проверка подписи callback

from telegram_gateway_verification import verify_callback_signature

ok = verify_callback_signature(
    api_token=os.environ["TELEGRAM_GATEWAY_TOKEN"],
    timestamp_header=request.headers["X-Request-Timestamp"],
    signature_header=request.headers["X-Request-Signature"],
    raw_body=request.get_data(),  # raw bytes тела запроса
)

if not ok:
    return "invalid signature", 403

Важные детали

  • phone_number должен быть в формате E.164 (например, +15551234567).
  • ttl для sendVerificationMessage: от 30 до 3600 секунд.
  • Если API отвечает {"ok": false, ...}, библиотека бросает TelegramGatewayAPIError.

Полезные ссылки

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_gateway_verification-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_gateway_verification-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file telegram_gateway_verification-0.1.1.tar.gz.

File metadata

File hashes

Hashes for telegram_gateway_verification-0.1.1.tar.gz
Algorithm Hash digest
SHA256 64da2feceaf5389e65fc5f95f103c9b1a807c9689eae96fbb5e7407488cc702c
MD5 dca1a86f232277f7880bc75b49c49525
BLAKE2b-256 d6e1af247b2ae995b2765721e89e360885f46dfff985aafbf795f20e36221e72

See more details on using hashes here.

File details

Details for the file telegram_gateway_verification-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_gateway_verification-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9ff88f15f2dacbe2db21e6fc449b4a92525e3ef27481e4a931ecc6dce496760
MD5 4528fb7d8047a9f99da646cd9db567e5
BLAKE2b-256 e1a6094841930e0512329e1bd108d94ee1ed48748eddaff237cec53f78d07816

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page