定制 somarkesen/telegram-gateway 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Install the package via Composer:
composer require somarkesen/telegram-gateway
  1. Publish the configuration file:
php artisan vendor:publish --provider="SomarKesen\TelegramGateway\Providers\TelegramGatewayServiceProvider"
  1. Add your Telegram API token in the .env file:
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.

  1. Visit the Telegram Gateway API page: https://gateway.telegram.org/.
  2. Log in using your Telegram phone number.
  3. After logging in, you will be able to fund your account and view your API token.
  4. 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.

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 somarkesen/telegram-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 32
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-15