This Laravel package provides an easy-to-use interface for sending verification codes via Telegram using the Telegram Gateway API.
- Install the package via Composer:
composer require somarkesen/telegram-gateway
- Publish the configuration file:
php artisan vendor:publish --provider="SomarKesen\TelegramGateway\Providers\TelegramGatewayServiceProvider"
- Add your Telegram API token in the
.env
file:
TELEGRAM_API_TOKEN=your-telegram-api-token
To use this package, you need to get an API token from Telegram Gateway.
- Visit the Telegram Gateway API page: https://gateway.telegram.org/.
- Log in using your Telegram phone number.
- After logging in, you will be able to fund your account and view your API token.
- Copy the token and add it to your Laravel
.env
file as shown above.
Ensure your account is funded and your API token is valid, as this token will be required for all API requests.
After publishing, you can find the configuration file at config/telegram_gateway.php
. This file contains the API URL and timeout settings.
return [
'api_url' => env('TELEGRAM_API_URL', 'https://gatewayapi.telegram.org/'),
'token' => env('TELEGRAM_API_TOKEN'),
'timeout' => 30, // Timeout for API requests in seconds
];
To send a verification message, you can use the TelegramGateway
facade:
use SomarKesen\TelegramGateway\Facades\TelegramGateway;
$response = TelegramGateway::sendVerificationMessage('+1234567890', [
'code' => '1234',
'ttl' => 300,
'callback_url' => 'https://yourapp.com/callback',
]);
The sendVerificationMessage
method accepts the following parameters:
phone_number
(string, required): The phone number to which the verification message will be sent.code
(string, optional): The verification code to send. If omitted, Telegram will generate a random code.ttl
(integer, optional): Time-to-live in seconds for the message before it expires.callback_url
(string, optional): URL to receive delivery status updates.
To check whether a verification message can be sent to a phone number:
$response = TelegramGateway::checkSendAbility('+1234567890');
To check the status of a verification message that was sent previously:
$response = TelegramGateway::checkVerificationStatus('request-id', '1234');
The checkVerificationStatus
method accepts:
request_id
(string, required): The unique identifier of the verification request.code
(string, optional): The code entered by the user. This can verify if the code is valid.
To revoke a previously sent verification message:
$response = TelegramGateway::revokeVerificationMessage('request-id');
The revokeVerificationMessage
method accepts:
request_id
(string, required): The unique identifier of the verification request to revoke.
- sendVerificationMessage: Sends a verification message.
- checkSendAbility: Checks if a verification message can be sent to a phone number.
- checkVerificationStatus: Checks the status of a previously sent verification message.
- revokeVerificationMessage: Revokes a previously sent verification message.
To run the tests:
composer test
This package is open-source and available under the MIT license.