chipslays/tas-wrapper
Composer 安装命令:
composer require chipslays/tas-wrapper
包简介
Simple API wrapper for easy manage TelegramApiServer.
README 文档
README
Simple API wrapper for easy manage TelegramApiServer in your project.
Install
composer require chipslays/tas-wrapper
Example
Client
All methods from MadelineProto supported, methods list here.
use TelegramApiServer\Client; require 'vendor/autoload.php'; $client = new Client([ 'host' => '127.0.0.1', 'port' => '9503', 'session' => 'session_name', ]); $response = $client->get('getSelf')->execute(); // GET request $response = $client->post('getSelf')->execute(); // POST request $response = $client->get('messages.sendMessage', [ 'peer' => '@chipslays', 'message' => 'Hello from tas-wrapper! 👋', 'parse_mode' => 'html', ])->execute();
Also, you can define curl option by option(NAME_OPTION, 'value') method.
$response = $client ->get('getSelf') ->option(CURLOPT_TIMEOUT, 60) ->option(CURLOPT_HEADER, false) ->execute();
Map your own methods (aliases), it so simple:
$client->map('sendMessage', fn($peer, $text) => $client->get('messages.sendMessage', [ 'peer' => $peer, 'message' => $text, ])->execute()); $response = $client->sendMessage('@chipslays', 'so simple!');
Each time the sendMessage method is called, the function from the second parameter will be executed again.
If you need the function to work only once, and then return only the result of execution in subsequent times, use the mapOnce() method instead of map().
$client->mapOnce('getSelf', fn() => $client->get('getSelf')->execute()); $me = $client->getSelf();
Session
Manage TelegramApiServer session, more detail here.
use TelegramApiServer\Session; require 'vendor/autoload.php'; // This is example of default config // NOTE: If you have the same data, you can skip this Session::setConfig([ 'host' => '127.0.0.1', 'port' => '9503', 'schema' => 'http', ]); // Get sessions list $response = Session::list(); // Adding new session $response = Session::add('session_name'); // Removing session (session file will remain) $response = Session::remove('session_name'); // Remove session file // WARNING: Don`t forget to logout and call `removeSession` first! $response = Session::unlink('session_name');
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-12