Telegram Gateway Python SDK is a lightweight and asynchronous client library designed to interface with the Telegram Gateway API. It provides a powerful and easy-to-use interface for sending and managing verification messages, checking their status, and revoking them. Alongside the SDK, the tgateway
library also includes a CLI tool for performing these operations directly from the command line.
- Send Verification Messages: Deliver verification codes to users' phone numbers.
- Check Delivery Status: Verify the status of sent messages and handle callbacks.
- Revoke Verification: Invalidate previously sent verification messages.
- Integrity Validation: Ensure authenticity of incoming reports using signature validation.
- Easy to Use: Designed with simplicity and usability in mind.
- Fully Asynchronous: Built on
asyncio
for high-performance integration. - Command Line Interface (CLI): Use the
TGateway CLI
to manage your interactions without writing code.
Install the SDK and CLI using pip:
pip install tgateway[cli]
Here's a basic example to get started with the TelegramGateway
client:
import asyncio
from tgateway import TelegramGateway
async def main():
async with TelegramGateway(access_token="<access-token>") as gateway:
result = await gateway.check_send_ability(
phone_number="+1234567890",
)
print(f"Verification ability: {result}")
asyncio.run(main())
import asyncio
from tgateway import TelegramGateway
async def main():
async with TelegramGateway(access_token="<access-token>") as gateway:
result = await gateway.send_verification_message(
phone_number="+1234567890",
code_length=6
)
print(f"Verification message sent: {result}")
asyncio.run(main())
import asyncio
from tgateway import TelegramGateway
async def main():
async with TelegramGateway(access_token="<access-token>") as gateway:
result = await gateway.check_verification_status(request_id="<request-id>")
print(f"Verification status: {result}")
asyncio.run(main())
import asyncio
from tgateway import TelegramGateway
async def main():
async with TelegramGateway(access_token="<access-token>") as gateway:
result = await gateway.revoke_verification_message(request_id="<request-id>")
print(f"Verification revoked: {result}")
asyncio.run(main())
To confirm the origin and integrity of incoming reports, you can use the validate_report_integrity
method provided by the SDK:
import asyncio
from tgateway import TelegramGateway
async def main():
async with TelegramGateway(access_token="<access-token>") as gateway:
try:
gateway.validate_report_integrity(
timestamp=123456789, # Timestamp from header
signature="report_signature", # Signature from header
body=b'{}' # Body of the report as bytes
)
print("Report integrity validated successfully.")
except Exception as e:
print(f"Validation failed: {e}")
asyncio.run(main())
The TGateway CLI is part of the tgateway
library and provides an easy way to interact with the Telegram Gateway API using simple commands. Below is an overview of the available commands and their usage.
The TGateway CLI provides several commands for interacting with the Telegram Gateway API:
send
: Send a verification message to a phone number.ability
: Check the ability to send a message to a phone number.check
: Check the status of a previously sent verification request.revoke
: Revoke a previously sent verification message.--version
: Display the current version of the CLI and its dependencies.
To send a verification message, use the send
command:
tgateway send --access-token "<access-token>" --phone-number "+1234567890" [OPTIONS]
Required Options:
--access-token
: Your Telegram Gateway API access token.--phone-number
: Phone number to send the verification message to, in E.164 format (e.g., "+1234567890").
Optional Parameters:
--request-id
: Use an existing request ID to resend a message free of charge.--sender-username
: Username of the Telegram channel from which the code will be sent.--code
: Custom verification code (4 to 8 characters, numeric).--code-length
: Length of the verification code (if auto-generated). Supports values between 4 to 8.--callback-url
: URL to receive delivery reports related to the sent message.--ttl
: Time-to-live for the message in seconds before it expires.
Example:
tgateway send --access-token "<access-token>" --phone-number "+1234567890" --code-length 6
To check if a verification message can be sent to a specific number:
tgateway ability --access-token "<access-token>" --phone-number "+1234567890"
Check the status of a previously sent verification message using its request-id
:
tgateway check --access-token "<access-token>" --request-id "<request-id>"
Revoke a sent verification message using the request-id
:
tgateway revoke --access-token "<access-token>" --request-id "<request-id>"
Check the version of the CLI, along with Python and system information:
tgateway --version
Example Output:
Running TGateway 0.1.0 with CPython 3.9.0 on Linux
Each command has its own help documentation. To view detailed information about a specific command, use:
tgateway <command> --help
For example:
tgateway send --help
The project is structured for ease of use and maintainability:
tgateway/
βββ client.py # Main client class.
βββ constants.py # Constants used throughout the SDK.
βββ enums.py # Enum definitions for API statuses.
βββ exceptions.py # Custom exception classes.
βββ integrity.py # Integrity validation utilities.
βββ methods.py # Implementation of Telegram Gateway API methods.
βββ types.py # Type definitions for API responses.
Currently, the project does not have test cases but this is planned for future releases. Contributions to add tests are welcome!
- Telegram Gateway Overview: Telegram Gateway Overview
- API Reference: Gateway API Reference
- Verification Tutorial: Verification Tutorial
- Manage Your Account: Gateway Account
- Terms of Service: Gateway Terms of Service
This project is licensed under the Apache License.
Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request. For major changes, open an issue first to discuss what you would like to change.
- Fork the repository.
- Create your feature branch:
git checkout -b feature/my-new-feature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/my-new-feature
. - Open a pull request.
For questions, support, or just to connect, reach out to the project maintainers:
- Email: [email protected]
- Telegram: @DeusDeveloper
- Chat: @tgateway
- GitHub Issues: GitHub Repository
Enjoy using the Telegram Gateway Python SDK and CLI! π