1. Go to this page and download the library: Download nullform/telegram-gateway library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Nullform\TelegramGateway\Client;
use Nullform\TelegramGateway\Parameters\SendVerificationMessageParameters;
use Nullform\TelegramGateway\AbstractException;
$token = 'API Token';
$number = '+19999999999'; // The phone number to which you want to send a verification message.
$client = new Client($token);
$client->setCurlOption(CURLOPT_TIMEOUT, 10); // You can set your own cURL option...
$client->setCurlOptions([CURLOPT_TIMEOUT => 10]); // ... or multiple options.
$parameters = new SendVerificationMessageParameters();
$parameters->code_length = 6; // Set your own code or code length.
$parameters->payload = 'custom data'; // Custom payload.
$parameters->ttl = 60; // Time-to-live (1 minute) before the message expires.
$parameters->callback_url = 'https://example.com/webhook/telegram-gateway'; // Your callback URL.
$parameters->sender_username = 'my_tg_channel'; // Channel from which the code will be sent.
try {
// Instance of RequestStatus.
$requestStatus = $client->sendVerificationMessage($number, $parameters);
// Last request info.
$curlInfo = $client->getCurlInfo();
} catch (AbstractException $exception) { // Unable to send or error during sending.
// ...
}
use Nullform\TelegramGateway\Client;
use Nullform\TelegramGateway\Parameters\SendVerificationMessageParameters;
use Nullform\TelegramGateway\AbstractException;
$token = 'API Token';
$number = '+19999999999';
$client = new Client($token);
try {
// Throws an exception if there is no ability.
$abilityStatus = $client->checkSendAbility();
try {
$parameters = new SendVerificationMessageParameters();
// The unique identifier of a previous request from checkSendAbility.
// If provided, this request will be free of charge.
$parameters->request_id = $abilityStatus->request_id;
$parameters->code = '123456'; // Your custom code. A fully numeric string of 4-8 chars.
$requestStatus = $client->sendVerificationMessage($number, $parameters);
// ...
} catch (AbstractException $exception) { // Can't send.
// ...
}
} catch (AbstractException $exception) { // No ability.
// ...
}
use Nullform\TelegramGateway\Client;
use Nullform\TelegramGateway\AbstractException;
use Nullform\TelegramGateway\Types\VerificationStatus;
$token = 'API Token';
$client = new Client($token);
$requestId = 'request id';
$code = $_POST['code'];
try {
$status = $client->checkVerificationStatus($requestId, $code);
if ($status->verification_status->status == VerificationStatus::STATUS_CODE_VALID) {
// Success.
}
} catch (AbstractException $exception) {
// ...
}
use Nullform\TelegramGateway\ReportHandler;
use Nullform\TelegramGateway\AbstractException;
$token = 'API Token';
$handler = new ReportHandler($token);
try {
// Instance of RequestStatus.
$requestStatus = $handler->receive();
} catch (AbstractException $exception) {
// ...
}
shell
php composer.phar test tests
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.