somarkesen/telegram-gateway
Composer 安装命令:
composer require somarkesen/telegram-gateway
包简介
A Laravel package for sending verification codes via Telegram Gateway API
README 文档
README
This Laravel package provides an easy-to-use interface for sending verification codes via Telegram using the Telegram Gateway API.
Installation
- 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
.envfile:
TELEGRAM_API_TOKEN=your-telegram-api-token
Obtaining the 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
.envfile as shown above.
Ensure your account is funded and your API token is valid, as this token will be required for all API requests.
Configuration
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 ];
Usage
Sending a Verification Message
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.
Checking Send Ability
To check whether a verification message can be sent to a phone number:
$response = TelegramGateway::checkSendAbility('+1234567890');
Checking Verification Status
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.
Revoking a Verification Message
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.
Available Methods
- 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.
Testing
To run the tests:
composer test
Credits
License
This package is open-source and available under the MIT license.
somarkesen/telegram-gateway 适用场景与选型建议
somarkesen/telegram-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2024 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 somarkesen/telegram-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 somarkesen/telegram-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-15