Improve docs
This commit is contained in:
parent
236fefabc1
commit
34f7047d73
@ -1,4 +1,4 @@
|
|||||||
MTPROTO_SETTINGS={"app_info":{"api_id":6,"api_hash":"eb06d4abfb49dc3eeb1aeb98ae0f581e"}}
|
MTPROTO_SETTINGS={}
|
||||||
TEST_USERNAME=@danogentili
|
TEST_USERNAME=@danogentili
|
||||||
TEST_DESTINATION_GROUPS=["@pwrtelegramgroup","@pwrtelegramgroupita"]
|
TEST_DESTINATION_GROUPS=["@pwrtelegramgroup","@pwrtelegramgroupita"]
|
||||||
TEST_SECRET_CHAT=@danogentili
|
TEST_SECRET_CHAT=@danogentili
|
||||||
|
@ -27,9 +27,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]];
|
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
|
||||||
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
|
|
||||||
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setEventHandler('\EventHandler');
|
$MadelineProto->setEventHandler('\EventHandler');
|
||||||
@ -50,4 +48,4 @@ And click them:
|
|||||||
$button->click();
|
$button->click();
|
||||||
```
|
```
|
||||||
|
|
||||||
<form action="https://docs.madelineproto.xyz/docs/DIALOGS.html"><input type="submit" value="Previous section" /></form><form action="https://docs.madelineproto.xyz/docs/CALLS.html"><input type="submit" value="Next section" /></form>
|
<form action="https://docs.madelineproto.xyz/docs/DIALOGS.html"><input type="submit" value="Previous section" /></form><form action="https://docs.madelineproto.xyz/docs/CALLS.html"><input type="submit" value="Next section" /></form>
|
||||||
|
@ -65,15 +65,8 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
|
||||||
try {
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
|
||||||
unlink('bot.madeline');
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
}
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setEventHandler('\EventHandler');
|
$MadelineProto->setEventHandler('\EventHandler');
|
||||||
$MadelineProto->loop();
|
$MadelineProto->loop();
|
||||||
@ -112,15 +105,8 @@ Note that multiprocessing is not the same as multithreading, and should be avoid
|
|||||||
|
|
||||||
## Webhook
|
## Webhook
|
||||||
```php
|
```php
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
|
||||||
try {
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
|
||||||
unlink('bot.madeline');
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
}
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setWebhook('http://mybot.eu.org/madelinehook.php');
|
$MadelineProto->setWebhook('http://mybot.eu.org/madelinehook.php');
|
||||||
$MadelineProto->loop();
|
$MadelineProto->loop();
|
||||||
@ -146,6 +132,9 @@ This way, each update could be managed faster.
|
|||||||
|
|
||||||
## Long polling
|
## Long polling
|
||||||
```php
|
```php
|
||||||
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
$MadelineProto->start();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$updates = $MadelineProto->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
$updates = $MadelineProto->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||||
\danog\MadelineProto\Logger::log($updates);
|
\danog\MadelineProto\Logger::log($updates);
|
||||||
@ -163,7 +152,7 @@ while (true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$MadelineProto->messages->sendMessage(['peer' => $update['update']['_'] === 'updateNewMessage' ? $update['update']['message']['from_id'] : $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
|
$MadelineProto->messages->sendMessage(['peer' => $update, 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
|
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
|
||||||
}
|
}
|
||||||
@ -179,15 +168,8 @@ The get_updates function accepts an array of options as the first parameter, and
|
|||||||
## Callback
|
## Callback
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
|
||||||
try {
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
|
||||||
unlink('bot.madeline');
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
}
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setCallback(function ($update) use ($MadelineProto) { \danog\MadelineProto\Logger::log("Received an update of type ".$update['_']); });
|
$MadelineProto->setCallback(function ($update) use ($MadelineProto) { \danog\MadelineProto\Logger::log("Received an update of type ".$update['_']); });
|
||||||
$MadelineProto->loop();
|
$MadelineProto->loop();
|
||||||
|
@ -60,15 +60,8 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]]; //, 'connection_settings' => ['all' => ['test_mode' => true]]];
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
|
||||||
try {
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
|
||||||
unlink('bot.madeline');
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
|
||||||
}
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setEventHandler('\EventHandler');
|
$MadelineProto->setEventHandler('\EventHandler');
|
||||||
$MadelineProto->loop(-1);
|
$MadelineProto->loop(-1);
|
||||||
|
@ -99,13 +99,8 @@ if (file_exists('.env')) {
|
|||||||
echo 'Loading settings...'.PHP_EOL;
|
echo 'Loading settings...'.PHP_EOL;
|
||||||
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
|
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
|
||||||
|
|
||||||
try {
|
$MadelineProto = new \danog\MadelineProto\API('s.madeline', $settings);
|
||||||
$MadelineProto = new \danog\MadelineProto\API('s.madeline', $settings);
|
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
|
||||||
unlink('s.madeline');
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('s.madeline', $settings);
|
|
||||||
}
|
|
||||||
$MadelineProto->start();
|
$MadelineProto->start();
|
||||||
$MadelineProto->setEventHandler('\EventHandler');
|
$MadelineProto->setEventHandler('\EventHandler');
|
||||||
$MadelineProto->loop();
|
$MadelineProto->loop();
|
||||||
|
Loading…
Reference in New Issue
Block a user