estaheri/easytel
Composer 安装命令:
composer require estaheri/easytel
包简介
An easy to use php library for using telegram bot api
关键字:
README 文档
README
PHP Telegram Bot Library
An easy to use php library for using telegram bot api
Table of Contents
Introduction
This is a fully php classes structured and easy to use library for communicating with telegram bot api and managing your bots. 🤖
As it's just a library you can use it next to any framework for example Laravel, Codeigniter,... 🌐
Every Methods & Types has it's own description same as official telegram bot api document using standard phpdoc. 📄
Unlike other library this library full support object oriented structured any Methods and Types available on Telegram Bot API which means you can get full IDE auto complete/code suggestion when using library. (So feel free to use Ctl+Space 😉)
All requests to telegram will be sent async through GuzzleHttp ⚡
Quick Usage
- Require library in your project 📁
composer require estaheri/easytel
- Require composer autoload in your php code ⚓
require_once __DIR__.'/vendor/autoload.php';
- Instantiating
Telegramclass📡
use EasyTel\Telegram; $tg = new Telegram($bot_token,$updates,$botapi_url,$request_method,$guzzle_client_options,$output); #--------------------------------------------------------------------------------- $bot_token = '123456789:xxxxxxxxxxxxxxxx'; // Telegram bot token (You can get it from @botfather) $updates = file_get_contents('php://input'); // (Optional) Pure telegram webhook updates you can use any method you want to getting updates $botapi_url = 'https://api.telegram.org'; // (Optional) Your bot api url https://core.telegram.org/bots/api#using-a-local-bot-api-server (Mostly use telegram official server) $request_method = 'POST'; // (Optional) Request method of http requests sends to telegram bot api url, Can be POST or GET $guzzle_client_options = ['verify' => false]; // (Optional) Your custom guzzlehttp client options https://docs.guzzlephp.org/en/stable/request-options.html $output = Telegram::OUTPUT_ARRAY; // (Optional) Output result of your requests send and received by telegram when using methods
- Now you can use telegram request methods or telegram webhook update✅
use \EasyTel\Types\ReplyParameters; # ------------------------- Methods ------------------------- $methods = $tg->methods; // Access to all telegram methods $methods->sendMessage($chat_id, $text) ->parse_mode('markdown') ->reply_parameters(ReplyParameters::make($message_id, $chat_id)); # ------------------------- Updates ------------------------- $updates = $tg->updates; // Access to all webhook updates received // IDE will suggest every property you see here because of full structured properties from their classes $message = $updates->message; $chat_id = $message->chat->id; $message_id = $message->message_id; $text = $message->text; $reply_text = $message->reply_to_message->text;
Instructions
Here we explained step by step how to use this library and working with telegram bots.
Install composer
Note
If composer with php 8.2 installed on your system ignore this step
Linux based operating systems installation :
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }" php composer-setup.php php -r "unlink('composer-setup.php');"
Windows based operating systems installation :\
Download
Composer-Setup.exefrom link bellow than run it and follow installation steps.
https://getcomposer.org/Composer-Setup.exe
Require in project
Open terminal in your project folder and run this composer command :
composer require estaheri/easytel
Than include composer autoload.php file to load EasyTel library in your codes :
require_once __DIR__.'/vendor/autoload.php';
Getting Updates
Now you have to use a way for getting your bot updates from telegram.
Telegram gives us two options getUpdates method or Webhook.
-
Webhook (Recommended)
In this method you set a url to your webhook handler route or php file than telegram will send you any updates of messages or callback queries to it.
webhook.php :$updates = file_get_contents('php://input'); if(!empty($updates)) { $tg = new Telegram($bot_token, $updates); //... } else { http_response_code(400); echo 'Bad Request!'; }
Than set webhook to your webhook address :$tg = new Telegram($bot_token); $tg->webhook->setWebhook('https://example.com/webhook.php');
-
GetUpdates
In this method you don't need to set webhook or webhook file just request to telegram for getting updates using getUpdates method :$tg = new Telegram($bot_token); $tg->webhook->setWebhook('https://example.com/webhook.php'); $result = $tg->methods->getUpdates()->_result(); if ($result->success && $result->ok) { echo "Success"; } else { $error = $result->ok ? $result->response()->description : $result->fail()->error; echo "Error: $error"; }
estaheri/easytel 适用场景与选型建议
estaheri/easytel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「telegram」 「telegram bot api」 「telegram bot api sdk」 「Telegram bot library」 「easy telegram sdk」 「easy to use telegram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 estaheri/easytel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 estaheri/easytel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 estaheri/easytel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
Laravel 5.6 Monolog custom telegram channel
A PSR-7 compatible library for making CRUD API endpoints
PHP Wrapper for Telegram Bot API
VK driver for botman
Telegram bot integration with laravel
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-05