Skip to main content

Python client for Telegram Gateway verification API

Project description

telegram-gateway-verification

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

Установка

pip install telegram-gateway-verification

Для разработки локально:

pip install -e .[dev]

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

from telegram_gateway_verification import TelegramGatewayClient

client = TelegramGatewayClient(api_token="YOUR_GATEWAY_TOKEN")

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)

Основные методы

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

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

Telegram отправляет заголовки X-Request-Timestamp и X-Request-Signature.

from telegram_gateway_verification import verify_callback_signature

ok = verify_callback_signature(
    api_token="YOUR_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

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

  • 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.0.tar.gz (7.7 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.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for telegram_gateway_verification-0.1.0.tar.gz
Algorithm Hash digest
SHA256 523f085cf78a95a39a773e5d85df0ad7bb13274b3bb57b703532afd6d91c651c
MD5 7d7dd9021d5c74421b133b7ef1e3e542
BLAKE2b-256 8e83c7a442b1b82fb5d0c8ab4feb1e906e2c15b059a371dc00d8164944e79941

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for telegram_gateway_verification-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 742630a887b55188ad09ad4d117d20ead1a5d8c22717b75e66f79efddf6369a8
MD5 132684cee4debf4aa5885d5c93e7cd7c
BLAKE2b-256 75b0c82506971326df82f67c9b7ff0c86d2458ffd81c8902e8b452609a4ffc57

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