forked from xtrime-ru/TelegramApiServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- server - parsing - json encoding
- Loading branch information
Showing
11 changed files
with
877 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SWOOLE | ||
SWOOLE_SERVER_ADDRESS=127.0.0.1 | ||
SWOOLE_SERVER_PORT=9503 | ||
SWOOLE_WORKER_NUM=1 | ||
SWOOLE_HTTP_COMPRESSION=1 | ||
|
||
# TELEGRAM CLIENT | ||
TELEGRAM_API_ID= | ||
TELEGRAM_API_HASH= | ||
|
||
# TELEGRAM SOCKS5 PROXY (optional) | ||
TELEGRAM_PROXY_ADDRESS= | ||
TELEGRAM_PROXY_PORT= | ||
TELEGRAM_PROXY_USERNAME= | ||
TELEGRAM_PROXY_PASSWORD= | ||
|
||
# CURL PROXY (optional) | ||
# address of your socks5 proxy user:[email protected]:12000 | ||
CURL_PROXY= | ||
# value of CURLPROXY_SOCKS5_HOSTNAME const | ||
CURL_PROXY_TYPE=7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,97 @@ | ||
# TelegramSwooleClient | ||
Fast async php telegram client: MadelineProto + Swoole Server | ||
Fast, simple, async php telegram client and parser: MadelineProto + Swoole Server | ||
|
||
* Online server for tests (previous version, different request syntax): http://tg.i-c-a.su/?format=json&images=0&url=breakingmash | ||
* My content aggregator: [https://i-c-a.su](https://i-c-a.su) | ||
|
||
**Features** | ||
* Fast async swoole server | ||
* Use as micro-service | ||
* Get any public telegram posts from groups as json | ||
|
||
**TODO** | ||
* RSS output | ||
* flood protection (for use in public) | ||
* logging | ||
|
||
**Installation** | ||
|
||
1. Get app_id and app_hash at [my.telegram.org](https://my.telegram.org/) | ||
1. Swoole extension required: [Install swoole](https://github.com/swoole/swoole-src#%EF%B8%8F-installation) | ||
1. Install this package: | ||
|
||
a. Standalone: | ||
|
||
1. download files from github and extract. | ||
2. Run `composer install` inside unpacked directory | ||
|
||
b. Existing project: | ||
|
||
1. Add following into your project's composer.json | ||
``` | ||
"repositories": [ | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/xtrime-ru/TelegramSwooleClient.git" | ||
} | ||
], | ||
"require": { | ||
"xtrime-ru/telegramswooleclient": "dev-master", | ||
} | ||
``` | ||
**Usage** | ||
1. Install | ||
1. Fill options in .env file (see .env.example) | ||
1. Run server/parser | ||
``` | ||
php server.php [--help] [-a|--address=127.0.0.1] [-p|--port=9503] | ||
Options: | ||
--help Show this message | ||
-a --address Server ip (optional) (example: 127.0.0.1 or 0.0.0.0 to listen all hosts) | ||
-p --port Server port (optional) (example: 9503) | ||
Also all options can be set in .env file (see .env.example) | ||
``` | ||
1. Get posts from any open channel | ||
* Get 10 latests posts from any open channel via GET request: | ||
`http://%address%:%port%/json/%channel%` | ||
Example: | ||
`http://127.0.0.1:9503/json/breakingmash` | ||
* Get posts from multiple channels via POST: | ||
Url: `http://127.0.0.1:9503/json/` | ||
Headers: `Content-Type: application/json` | ||
`form-data` and `x-www-form-urlencoded` should work, | ||
but was not tested | ||
Body: | ||
``` | ||
{ | ||
"getHistory": [ | ||
{ | ||
"peer":"channel#1259060275" | ||
}, | ||
{ | ||
"peer": "breakingmash", | ||
"limit": 30, | ||
"max_id": 200, | ||
} | ||
] | ||
} | ||
``` | ||
You can use any other options from https://docs.madelineproto.xyz/API_docs/methods/messages_getHistory.html | ||
peer name can be provided in different formats: https://docs.madelineproto.xyz/API_docs/types/InputPeer.html | ||
**Contacts** | ||
* Telegram: [@xtrime](tg://resolve?domain=xtrime) | ||
* Email: alexander(at)i-c-a.su |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
//Check if autoload has been already loaded (in case plugin installed in existing project) | ||
if (!class_exists('TelegramSwooleClient')) { | ||
require __DIR__ . '/vendor/autoload.php'; | ||
} | ||
//Check if root env file hash been loaded (in case plugin installed in existing project) | ||
if (!getenv('SWOOLE_SERVER_ADDRESS')){ | ||
(new Dotenv\Dotenv(__DIR__))->load(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
return [ | ||
'swoole' => [ | ||
'server' => [ | ||
'address' => (string) getenv('SWOOLE_SERVER_ADDRESS'), | ||
'port' => (string) getenv('SWOOLE_SERVER_PORT'), | ||
], | ||
'options'=> [ | ||
'worker_num' => (int) getenv('SWOOLE_WORKER_NUM'), | ||
'http_compression' => (bool) getenv('SWOOLE_HTTP_COMPRESSION'), | ||
] | ||
], | ||
'telegram' => [ | ||
'app_info' => [ // obtained in https://my.telegram.org | ||
'api_id' => getenv('TELEGRAM_API_ID'), | ||
'api_hash' => getenv('TELEGRAM_API_HASH'), | ||
], | ||
'logger' => [ // Logger settings | ||
'logger' => 3, // Logs disabled. | ||
'logger_level' => 5, // Logging level, available logging levels are: ULTRA_VERBOSE - 0, VERBOSE - 1 , NOTICE - 2, WARNING - 3, ERROR - 4, FATAL_ERROR - 5. | ||
], | ||
'updates' => [ | ||
'handle_updates' => false, // Should I handle updates? | ||
'handle_old_updates' => false, // Should I handle old updates on startup? | ||
], | ||
'connection_settings' => [ | ||
'all' => [ | ||
'proxy' => '\SocksProxy', | ||
'proxy_extra' => [ | ||
'address' => getenv('TELEGRAM_PROXY_ADDRESS'), | ||
'port' => getenv('TELEGRAM_PROXY_PORT'), | ||
'username' => getenv('TELEGRAM_PROXY_USERNAME'), | ||
'password' => getenv('TELEGRAM_PROXY_PASSWORD'), | ||
] | ||
] | ||
] | ||
], | ||
'curl' => [ | ||
'proxy' => [ | ||
'address' => getenv('CURL_PROXY_ADDRESS'), | ||
'port' => getenv('CURL_PROXY_PORT'), | ||
'username' => getenv('CURL_PROXY_USERNAME'), | ||
'password' => getenv('CURL_PROXY_PASSWORD'), | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/bootstrap.php'; | ||
|
||
if (PHP_SAPI !== 'cli') { | ||
throw new \Exception('Start in CLI'); | ||
} | ||
|
||
$shortopts = 'a::p::'; | ||
$longopts = [ | ||
'address::', // ip адресс сервера, необязательное значение | ||
'port::', // порт сервера, необязательное значение | ||
'help', //нужна ли справка? | ||
]; | ||
$options = getopt($shortopts, $longopts); | ||
$options = [ | ||
'address' => $options['address'] ?? $options['a'] ?? '', | ||
'port' => $options['port'] ?? $options['p'] ?? '', | ||
'id' => $options['id'] ?? $options['i'] ?? '', | ||
'hash' => $options['hash'] ?? $options['h'] ?? '', | ||
'help' => isset($options['help']), | ||
]; | ||
|
||
if ($options['help']) { | ||
$help = 'Fast, simple, async php telegram parser: MadelineProto + Swoole Server | ||
usage: php server.php [--help] [-a|--address=127.0.0.1] [-p|--port=9503] | ||
Options: | ||
--help Show this message | ||
-a --address Server ip (optional) (example: 127.0.0.1) | ||
-p --port Server port (optional) (example: 9503) | ||
Also all options can be set in .env file (see .env.example) | ||
Example: | ||
php server.php | ||
'; | ||
echo $help; | ||
exit; | ||
} | ||
|
||
$client = new \TelegramSwooleClient\Client(); | ||
new TelegramSwooleClient\Server($client, $options); |
Oops, something went wrong.