Now the default example works with bots, too

This commit is contained in:
Daniil Gentili 2018-03-21 12:24:38 +01:00
parent 7aafde0d8d
commit 33af309f7a
3 changed files with 33 additions and 16 deletions

View File

@ -27,15 +27,21 @@ $api_hash = '';
$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => $api_id, 'api_hash' => $api_hash]]); $MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => $api_id, 'api_hash' => $api_hash]]);
$MadelineProto->start(); $MadelineProto->start();
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]); $me = $MadelineProto->get_self();
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
try { \danog\MadelineProto\Logger::log($me);
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
} catch (\danog\MadelineProto\RPCErrorException $e) { if (!$me['bot']) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
try {
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
} }
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
echo 'OK, done!'.PHP_EOL; echo 'OK, done!'.PHP_EOL;
``` ```

View File

@ -31,15 +31,21 @@ $api_hash = '';
$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => $api_id, 'api_hash' => $api_hash]]); $MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => $api_id, 'api_hash' => $api_hash]]);
$MadelineProto->start(); $MadelineProto->start();
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]); $me = $MadelineProto->get_self();
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
try { \danog\MadelineProto\Logger::log($me);
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
} catch (\danog\MadelineProto\RPCErrorException $e) { if (!$me['bot']) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
try {
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
} }
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
echo 'OK, done!'.PHP_EOL; echo 'OK, done!'.PHP_EOL;
``` ```

View File

@ -5,15 +5,20 @@ require 'vendor/autoload.php';
$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => false]]); $MadelineProto = new \danog\MadelineProto\API('session.madeline', ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => false]]);
$me = $MadelineProto->start(); $me = $MadelineProto->start();
echo 'MadelineProto was started!';
$me = $MadelineProto->get_self();
\danog\MadelineProto\Logger::log($me);
if (!$me['bot']) { if (!$me['bot']) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']); $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'Testing MadelineProto from a browser :D']);
try { try {
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']); $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
} }
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']); $MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
} }
echo 'OK, done!'.PHP_EOL;