2016-08-09 22:28:50 +02:00
#!/usr/bin/env php
2016-06-23 23:51:08 +02:00
< ? php
2016-11-16 15:18:35 +01:00
/*
2017-01-25 23:16:22 +01:00
Copyright 2016 - 2017 Daniil Gentili
2016-11-16 15:18:35 +01:00
( https :// daniil . it )
This file is part of MadelineProto .
MadelineProto is free software : you can redistribute it and / or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation , either version 3 of the License , or ( at your option ) any later version .
MadelineProto is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU Affero General Public License for more details .
You should have received a copy of the GNU General Public License along with MadelineProto .
If not , see < http :// www . gnu . org / licenses />.
*/
2017-01-22 15:50:35 +01:00
chdir ( dirname ( __FILE__ ) . '/../' );
2016-08-07 23:23:10 +02:00
require_once 'vendor/autoload.php' ;
2016-12-26 18:23:46 +01:00
if ( file_exists ( 'web_data.php' )) {
2016-12-26 20:24:24 +01:00
require_once 'web_data.php' ;
2016-12-26 18:23:46 +01:00
}
2017-04-10 13:49:32 +02:00
2017-01-20 21:02:21 +01:00
echo 'Deserializing MadelineProto from session.madeline...' . PHP_EOL ;
2017-02-11 14:59:38 +01:00
$MadelineProto = false ;
try {
$MadelineProto = \danog\MadelineProto\Serialization :: deserialize ( 'session.madeline' );
} catch ( \danog\MadelineProto\Exception $e ) {
2017-04-21 13:13:24 +02:00
var_dump ( $e -> getMessage ());
2017-02-11 14:59:38 +01:00
}
2017-01-17 14:29:37 +01:00
if ( file_exists ( '.env' )) {
2017-01-25 23:16:22 +01:00
echo 'Loading .env...' . PHP_EOL ;
2017-01-22 15:50:35 +01:00
$dotenv = new Dotenv\Dotenv ( getcwd ());
2017-01-15 17:38:04 +01:00
$dotenv -> load ();
2017-01-17 14:29:37 +01:00
}
2017-01-25 23:16:22 +01:00
echo 'Loading settings...' . PHP_EOL ;
2017-01-17 14:29:37 +01:00
$settings = json_decode ( getenv ( 'MTPROTO_SETTINGS' ), true ) ? : [];
if ( $MadelineProto === false ) {
2017-01-25 23:16:22 +01:00
echo 'Loading MadelineProto...' . PHP_EOL ;
2016-12-26 18:23:46 +01:00
$MadelineProto = new \danog\MadelineProto\API ( $settings );
2017-01-27 13:19:16 +01:00
if ( getenv ( 'TRAVIS_COMMIT' ) == '' ) {
$checkedPhone = $MadelineProto -> auth -> checkPhone ( // auth.checkPhone becomes auth->checkPhone
[
'phone_number' => getenv ( 'MTPROTO_NUMBER' ),
]
);
2017-05-16 15:12:04 +02:00
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $checkedPhone ], \danog\MadelineProto\Logger :: NOTICE );
2017-01-27 13:19:16 +01:00
$sentCode = $MadelineProto -> phone_login ( getenv ( 'MTPROTO_NUMBER' ));
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $sentCode ], \danog\MadelineProto\Logger :: NOTICE );
2017-01-27 13:19:16 +01:00
echo 'Enter the code you received: ' ;
$code = fgets ( STDIN , ( isset ( $sentCode [ 'type' ][ 'length' ]) ? $sentCode [ 'type' ][ 'length' ] : 5 ) + 1 );
$authorization = $MadelineProto -> complete_phone_login ( $code );
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $authorization ], \danog\MadelineProto\Logger :: NOTICE );
2017-01-27 20:04:42 +01:00
if ( $authorization [ '_' ] === 'account.noPassword' ) {
throw new \danog\MadelineProto\Exception ( '2FA is enabled but no password is set!' );
}
if ( $authorization [ '_' ] === 'account.password' ) {
\danog\MadelineProto\Logger :: log ([ '2FA is enabled' ], \danog\MadelineProto\Logger :: NOTICE );
2017-01-27 22:05:24 +01:00
$authorization = $MadelineProto -> complete_2fa_login ( readline ( 'Please enter your password (hint ' . $authorization [ 'hint' ] . '): ' ));
2017-01-27 20:04:42 +01:00
}
2017-02-21 19:04:37 +01:00
if ( $authorization [ '_' ] === 'account.needSignup' ) {
\danog\MadelineProto\Logger :: log ([ 'Registering new user' ], \danog\MadelineProto\Logger :: NOTICE );
2017-04-21 13:13:24 +02:00
$authorization = $MadelineProto -> complete_signup ( readline ( 'Please enter your first name: ' ), readline ( 'Please enter your last name (can be empty): ' ));
2017-02-21 19:04:37 +01:00
}
2017-04-21 13:14:21 +02:00
2017-01-27 13:19:16 +01:00
echo 'Serializing MadelineProto to session.madeline...' . PHP_EOL ;
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'session.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2017-01-27 22:05:24 +01:00
} else {
$MadelineProto -> bot_login ( getenv ( 'BOT_TOKEN' ));
}
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
}
2017-04-24 12:41:41 +02:00
$message = ( getenv ( 'TRAVIS_COMMIT' ) == '' ) ? 'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' : ( 'Travis ci tests in progress: commit ' . getenv ( 'TRAVIS_COMMIT' ) . ', job ' . getenv ( 'TRAVIS_JOB_NUMBER' ) . ', PHP version: ' . getenv ( 'TRAVIS_PHP_VERSION' ));
2017-03-31 17:35:20 +02:00
2017-03-11 19:54:51 +01:00
echo 'Serializing MadelineProto to session.madeline...' . PHP_EOL ;
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'session.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2017-05-17 17:29:29 +02:00
2017-06-05 12:23:23 +02:00
if ( stripos ( readline ( 'Do you want to make the secret chat tests? (y/n): ' ), 'y' ) !== false ) {
2017-04-21 13:13:24 +02:00
/*
2017-04-02 16:42:17 +02:00
$call = $MadelineProto -> API -> request_call ( getenv ( 'TEST_SECRET_CHAT' ));
2017-04-05 02:09:45 +02:00
2017-04-02 16:42:17 +02:00
echo 'Waiting for ' . getenv ( 'TEST_SECRET_CHAT' ) . ' to accept the call...' . PHP_EOL ;
while ( $MadelineProto -> call_status ( $call ) !== $MadelineProto -> API -> READY ) {
$MadelineProto -> get_updates ();
}
var_dump ( $MadelineProto -> get_call ( $call ));
2017-04-21 13:13:24 +02:00
*/
2017-06-01 18:53:05 +02:00
var_dump ( getenv ( 'TEST_SECRET_CHAT' ));
$secret = $MadelineProto -> API -> request_secret_chat ( getenv ( 'TEST_SECRET_CHAT' ));
echo 'Waiting for ' . getenv ( 'TEST_SECRET_CHAT' ) . ' (secret chat id ' . $secret . ') to accept the secret chat...' . PHP_EOL ;
2017-04-21 13:14:21 +02:00
while ( $MadelineProto -> secret_chat_status ( $secret ) !== 2 ) {
$MadelineProto -> get_updates ();
}
2017-06-02 14:43:30 +02:00
$offset = 0 ;
2017-03-31 17:35:20 +02:00
2017-04-21 13:14:21 +02:00
$InputEncryptedChat = $MadelineProto -> get_secret_chat ( $secret )[ 'InputEncryptedChat' ];
$sentMessage = $MadelineProto -> messages -> sendEncrypted ([ 'peer' => $InputEncryptedChat , 'message' => [ '_' => 'decryptedMessage' , 'media' => [ '_' => 'decryptedMessageMediaEmpty' ], 'ttl' => 10 , 'message' => $message , 'entities' => [[ '_' => 'messageEntityCode' , 'offset' => 0 , 'length' => mb_strlen ( $message )]]]]); // should work with all layers
2017-06-01 18:53:05 +02:00
\danog\MadelineProto\Logger :: log ([ $sentMessage ], \danog\MadelineProto\Logger :: NOTICE );
2017-06-02 14:43:30 +02:00
while ( true ) {
$updates = $MadelineProto -> API -> 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]);
foreach ( $updates as $update ) {
$offset = $update [ 'update_id' ] + 1 ; // Just like in the bot API, the offset must be set to the last update_id
switch ( $update [ 'update' ][ '_' ]) {
case 'updateNewEncryptedMessage' :
var_dump ( $update );
}
2017-06-05 12:23:23 +02:00
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'session.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2017-06-02 14:43:30 +02:00
}
}
2017-04-21 13:14:21 +02:00
$secret_media = [];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// Photo uploaded as document, secret chat
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/faust.jpg' , 'fausticorn.jpg' ); // This gets an inputFile object with file name magic
$secret_media [ 'document_photo' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/faust.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/faust.jpg' ), 'caption' => 'This file was uploaded using MadelineProto' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'faust.jpg' , 'size' => filesize ( 'tests/faust.jpg' ), 'attributes' => [[ '_' => 'documentAttributeImageSize' , 'w' => 1280 , 'h' => 914 ]]]]];
// Photo, secret chat
$secret_media [ 'photo' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaPhoto' , 'thumb' => file_get_contents ( 'tests/faust.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'caption' => 'This file was uploaded using MadelineProto' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'size' => filesize ( 'tests/faust.jpg' ), 'w' => 1280 , 'h' => 914 ]]];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// GIF, secret chat
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/pony.mp4' );
2017-04-21 13:14:21 +02:00
$secret_media [ 'gif' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/pony.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/pony.mp4' ), 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'pony.mp4' , 'size' => filesize ( 'tests/faust.jpg' ), 'attributes' => [[ '_' => 'documentAttributeAnimated' ]]]]];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// Sticker, secret chat
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/lel.webp' );
2017-04-21 13:14:21 +02:00
$secret_media [ 'sticker' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/lel.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/lel.webp' ), 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'lel.webp' , 'size' => filesize ( 'tests/lel.webp' ), 'attributes' => [[ '_' => 'documentAttributeSticker' , 'alt' => 'LEL' , 'stickerset' => [ '_' => 'inputStickerSetEmpty' ]]]]]];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// Document, secrey chat
$time = time ();
2017-04-21 13:14:21 +02:00
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/60' , 'magic' ); // This gets an inputFile object with file name magic
2017-06-01 18:53:05 +02:00
var_dump ( time () - $time );
2017-04-21 13:14:21 +02:00
$secret_media [ 'document' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/faust.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => 'magic/magic' , 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'magic.magic' , 'size' => filesize ( 'tests/60' ), 'attributes' => [[ '_' => 'documentAttributeFilename' , 'file_name' => 'fairy' ]]]]];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// Video, secret chat
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/swing.mp4' );
2017-04-21 13:14:21 +02:00
$secret_media [ 'video' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/swing.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/swing.mp4' ), 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'swing.mp4' , 'size' => filesize ( 'tests/swing.mp4' ), 'attributes' => [[ '_' => 'documentAttributeVideo' , 'duration' => 5 , 'w' => 1280 , 'h' => 720 ]]]]];
2017-04-21 13:13:24 +02:00
2017-06-01 18:53:05 +02:00
// audio, secret chat
$inputEncryptedFile = $MadelineProto -> upload_encrypted ( 'tests/mosconi.mp3' );
2017-04-21 13:14:21 +02:00
$secret_media [ 'audio' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/faust.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/mosconi.mp3' ), 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'mosconi.mp3' , 'size' => filesize ( 'tests/mosconi.mp3' ), 'attributes' => [[ '_' => 'documentAttributeAudio' , 'voice' => false , 'duration' => 1 , 'title' => 'AH NON LO SO IO' , 'performer' => 'IL DIO GERMANO MOSCONI' ]]]]];
2017-04-21 13:13:24 +02:00
2017-04-21 13:14:21 +02:00
$secret_media [ 'voice' ] = [ 'peer' => $secret , 'file' => $inputEncryptedFile , 'message' => [ '_' => 'decryptedMessage' , 'ttl' => 0 , 'message' => '' , 'media' => [ '_' => 'decryptedMessageMediaDocument' , 'thumb' => file_get_contents ( 'tests/faust.preview.jpg' ), 'thumb_w' => 90 , 'thumb_h' => 90 , 'mime_type' => mime_content_type ( 'tests/mosconi.mp3' ), 'caption' => 'test' , 'key' => $inputEncryptedFile [ 'key' ], 'iv' => $inputEncryptedFile [ 'iv' ], 'file_name' => 'mosconi.mp3' , 'size' => filesize ( 'tests/mosconi.mp3' ), 'attributes' => [[ '_' => 'documentAttributeAudio' , 'voice' => true , 'duration' => 1 , 'title' => 'AH NON LO SO IO' , 'performer' => 'IL DIO GERMANO MOSCONI' ]]]]];
2017-06-01 18:53:05 +02:00
2017-04-21 13:14:21 +02:00
foreach ( $secret_media as $type => $smessage ) {
$type = $MadelineProto -> messages -> sendEncryptedFile ( $smessage );
}
2017-04-21 13:13:24 +02:00
}
$mention = $MadelineProto -> get_info ( getenv ( 'TEST_USERNAME' )); // Returns an array with all of the constructors that can be extracted from a username or an id
$mention = $mention [ 'user_id' ]; // Selects only the numeric user id
2017-01-07 12:39:11 +01:00
$media = [];
// Photo uploaded as document
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/faust.jpg' , 'fausticorn.jpg' ); // This gets an inputFile object with file name magic
$media [ 'document_photo' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/faust.jpg' ), 'caption' => 'This file was uploaded using MadelineProto' , 'attributes' => [[ '_' => 'documentAttributeImageSize' , 'w' => 1280 , 'h' => 914 ]]];
2017-01-07 12:39:11 +01:00
// Photo
2017-01-22 15:50:35 +01:00
$media [ 'photo' ] = [ '_' => 'inputMediaUploadedPhoto' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/faust.jpg' ), 'caption' => 'This photo was uploaded using MadelineProto' ];
2017-01-07 12:39:11 +01:00
// GIF
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/pony.mp4' );
$media [ 'gif' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/pony.mp4' ), 'caption' => 'test' , 'attributes' => [[ '_' => 'documentAttributeAnimated' ]]];
2017-01-07 12:39:11 +01:00
// Sticker
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/lel.webp' );
$media [ 'sticker' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/lel.webp' ), 'caption' => 'test' , 'attributes' => [[ '_' => 'documentAttributeSticker' , 'alt' => 'LEL' , 'stickerset' => [ '_' => 'inputStickerSetEmpty' ]]]];
2017-01-07 12:39:11 +01:00
// Video
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/swing.mp4' );
$media [ 'video' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/swing.mp4' ), 'caption' => 'test' , 'attributes' => [[ '_' => 'documentAttributeVideo' , 'duration' => 5 , 'w' => 1280 , 'h' => 720 ]]];
2017-01-07 12:39:11 +01:00
// audio
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/mosconi.mp3' );
2017-01-28 17:03:44 +01:00
$media [ 'audio' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/mosconi.mp3' ), 'caption' => 'test' , 'attributes' => [[ '_' => 'documentAttributeAudio' , 'voice' => false , 'duration' => 1 , 'title' => 'AH NON LO SO IO' , 'performer' => 'IL DIO GERMANO MOSCONI' ]]];
2017-01-07 12:39:11 +01:00
// voice
2017-01-28 17:03:44 +01:00
$media [ 'voice' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => mime_content_type ( 'tests/mosconi.mp3' ), 'caption' => 'test' , 'attributes' => [[ '_' => 'documentAttributeAudio' , 'voice' => true , 'duration' => 1 , 'title' => 'AH NON LO SO IO' , 'performer' => 'IL DIO GERMANO MOSCONI' ]]];
2017-04-21 13:13:24 +02:00
2017-01-07 12:39:11 +01:00
// Document
$time = time ();
2017-01-22 15:50:35 +01:00
$inputFile = $MadelineProto -> upload ( 'tests/60' , 'magic' ); // This gets an inputFile object with file name magic
2017-01-07 12:39:11 +01:00
var_dump ( time () - $time );
$media [ 'document' ] = [ '_' => 'inputMediaUploadedDocument' , 'file' => $inputFile , 'mime_type' => 'magic/magic' , 'caption' => 'This file was uploaded using MadelineProto' , 'attributes' => [[ '_' => 'documentAttributeFilename' , 'file_name' => 'magic.magic' ]]];
2017-03-31 17:35:20 +02:00
2017-01-20 21:02:21 +01:00
foreach ( json_decode ( getenv ( 'TEST_DESTINATION_GROUPS' ), true ) as $peer ) {
2017-02-16 04:55:10 +01:00
$sentMessage = $MadelineProto -> messages -> sendMessage ([ 'peer' => $peer , 'message' => $message , 'entities' => [[ '_' => 'inputMessageEntityMentionName' , 'offset' => 0 , 'length' => mb_strlen ( $message ), 'user_id' => $mention ]]]);
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $sentMessage ], \danog\MadelineProto\Logger :: NOTICE );
2017-03-31 17:36:55 +02:00
2017-01-07 12:39:11 +01:00
foreach ( $media as $type => $inputMedia ) {
2017-03-11 19:54:51 +01:00
$type = $MadelineProto -> messages -> sendMedia ([ 'peer' => $peer , 'media' => $inputMedia ]);
2017-01-07 12:39:11 +01:00
}
2016-11-29 01:47:59 +01:00
}
2017-05-27 23:21:14 +02:00
//var_dump($MadelineProto->API->get_updates());
2016-12-30 21:21:36 +01:00
echo 'Serializing MadelineProto to session.madeline...' . PHP_EOL ;
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'session.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2016-11-29 01:47:59 +01:00
echo 'Size of MadelineProto instance is ' . strlen ( serialize ( $MadelineProto )) . ' bytes' . PHP_EOL ;
2016-12-30 16:32:25 +01:00
2017-01-20 21:02:21 +01:00
if ( $bot_token = getenv ( 'BOT_TOKEN' )) {
2016-12-26 18:23:46 +01:00
$MadelineProto = new \danog\MadelineProto\API ( $settings );
2017-01-20 21:02:21 +01:00
$authorization = $MadelineProto -> bot_login ( $bot_token );
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $authorization ], \danog\MadelineProto\Logger :: NOTICE );
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
}
2016-12-30 16:32:25 +01:00
$message = 'yay' ;
2017-01-20 21:02:21 +01:00
$mention = $MadelineProto -> get_info ( getenv ( 'TEST_USERNAME' )); // Returns an array with all of the constructors that can be extracted from a username or an id
2016-12-30 16:32:25 +01:00
$mention = $mention [ 'user_id' ]; // Selects only the numeric user id
2017-01-20 21:02:21 +01:00
foreach ( json_decode ( getenv ( 'TEST_DESTINATION_GROUPS' ), true ) as $peer ) {
2017-02-16 04:55:10 +01:00
$sentMessage = $MadelineProto -> messages -> sendMessage ([ 'peer' => $peer , 'message' => $message , 'entities' => [[ '_' => 'inputMessageEntityMentionName' , 'offset' => 0 , 'length' => mb_strlen ( $message ), 'user_id' => $mention ]]]);
2017-01-27 22:05:24 +01:00
\danog\MadelineProto\Logger :: log ([ $sentMessage ], \danog\MadelineProto\Logger :: NOTICE );
2016-11-29 01:47:59 +01:00
}
2017-05-27 23:21:14 +02:00
//var_dump($MadelineProto->API->get_updates());
2017-04-21 13:14:21 +02:00
var_dump ( 'HERE' );