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(...)->RequestStatuscheck_send_ability(phone_number=...)->RequestStatuscheck_verification_status(request_id=..., code=...)->RequestStatusrevoke_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.
Ссылки
- API reference: https://core.telegram.org/gateway/api
- Overview: https://core.telegram.org/gateway
- Verification tutorial: https://core.telegram.org/gateway/verification-tutorial
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_gateway_verification-0.1.0.tar.gz.
File metadata
- Download URL: telegram_gateway_verification-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
523f085cf78a95a39a773e5d85df0ad7bb13274b3bb57b703532afd6d91c651c
|
|
| MD5 |
7d7dd9021d5c74421b133b7ef1e3e542
|
|
| BLAKE2b-256 |
8e83c7a442b1b82fb5d0c8ab4feb1e906e2c15b059a371dc00d8164944e79941
|
File details
Details for the file telegram_gateway_verification-0.1.0-py3-none-any.whl.
File metadata
- Download URL: telegram_gateway_verification-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
742630a887b55188ad09ad4d117d20ead1a5d8c22717b75e66f79efddf6369a8
|
|
| MD5 |
132684cee4debf4aa5885d5c93e7cd7c
|
|
| BLAKE2b-256 |
75b0c82506971326df82f67c9b7ff0c86d2458ffd81c8902e8b452609a4ffc57
|