micromagicman/laravel-telegram-webapp
Composer 安装命令:
composer require micromagicman/laravel-telegram-webapp
包简介
Laravel middleware for Telegram WebApp data validation
README 文档
README
Laravel package that allows you to process commands from Telegram MiniApp with user verification according to Telegram MiniApp developer documentation, as well as obtaining information about the Telegram user who sent the request
Requirements
| Laravel | micromagicman/laravel-telegram-webapp |
|---|---|
| 10.x | 1.x.x |
| 11.x | 2.x.x |
| 12.x | 3.x.x |
Install
Via composer
composer require micromagicman/laravel-telegram-webapp
Publishing
Publish to your Laravel application:
php artisan vendor:publish --provider="Micromagicman\TelegramWebApp\TelegramWebAppServiceProvider"
Configure
All package configuration available in config/telegram-webapp.php file after publish command execution:
| Config name | Description | Environment | Default value |
|---|---|---|---|
enabled |
Telegram MiniApp data validation switch | TELEGRAM_WEBAPP_DATA_VALIDATION_ENABLED |
true |
webAppScriptLocation |
Path to script (.js) which initializes Telegram MiniApp on your frontend app | - | https://telegram.org/js/telegram-web-app.js |
botToken |
Your Telegram bot token | TELEGRAM_BOT_TOKEN |
- |
error.status |
HTTP status code when Telegram MiniApp data validation fails | - | 403 (Forbidden) |
error.message |
Error message returned when Telegram MiniApp data validation fails | - | 403 (Forbidden) |
authDateLifetimeSeconds |
The lifetime of the Telegram initData auth_date parameter in seconds. The request to the server must be made within this interval, otherwise the data transmitted from Telegram will be considered invalid. The values of the parameter <= 0 imply that there is no verification of the lifetime of data from telegram and the auth_date parameter is not validated | - | 0 |
Example in code:
View
This package provides a root view for Telegram MiniApp frontend applications.
Telegram WebApp script is automatically includes to this view or its
inheritors if telegram-webapp.enabled switch is true
Example:
@extends('telegram-webapp::main') @section('lang', 'CN') @section('head') // some scripts, css, meta @endsection @section('title', 'My title') @section('content') <div id="app-content"> // My spa content </div> @endsection
Integration with TelegramBot\Api\BotApi
Our service integrates with TelegramBot\Api\BotApi, allowing you to access all of the methods provided by the Telegram Bot API. This integration is available either through a Facade or directly through the service.
You can find the repository for TelegramBot\Api\BotApi here.
Using the Facade
To use the Telegram Bot API methods, you can leverage the TelegramWebAppFacade facade. This provides a simple and convenient way to interact with the Telegram Bot API.
Example usage with the Facade:
use Micromagicman\TelegramWebApp\Facades\TelegramWebApp; $response = TelegramWebApp::getMe();
This allows you to call methods like getMe(), sendMessage(), getUpdates(), and any other method from the BotApi class directly through the facade.
Using the Service Directly
You can also interact with the Telegram Bot API directly through the service. Inject the TelegramWebAppService into your components, and call the Bot API methods via the service instance.
Example usage in a controller:
use Micromagicman\TelegramWebApp\Services\TelegramWebAppService; class MyController extends Controller { protected $telegram; public function __construct(TelegramWebAppService $telegram) { $this->telegram = $telegram; } public function getBotInfo() { $response = $this->telegram->getMe(); return response()->json($response); } }
Both the facade and the service offer full access to the BotApi class methods,
allowing you to work seamlessly with the Telegram Bot API in your Laravel application.
micromagicman/laravel-telegram-webapp 适用场景与选型建议
micromagicman/laravel-telegram-webapp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.51k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2023 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bot」 「laravel」 「telegram」 「miniapp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 micromagicman/laravel-telegram-webapp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 micromagicman/laravel-telegram-webapp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 micromagicman/laravel-telegram-webapp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
Laravel 5.6 Monolog custom telegram channel
PHP Wrapper for Telegram Bot API
Alfabank REST API integration
VK driver for botman
Telegram bot integration with laravel
统计信息
- 总下载量: 4.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-21