if(stripos(readline('Do you want to handle incoming calls? (y/n): '),'y')!==false){
$howmany=readline('How many calls would you like me to handle? ');
$offset=0;
while($howmany>0){
$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
foreach($updatesas$update){
\danog\MadelineProto\Logger::log($update);
$offset=$update['update_id']+1;// Just like in the bot API, the offset must be set to the last update_id
$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
$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);
foreach($updatesas$update){
$offset=$update['update_id']+1;// Just like in the bot API, the offset must be set to the last update_id
$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]]];
$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']]]]];
$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']]]]];
$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
$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']]];
// voice
$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']]];
// Document
$time=time();
$inputFile=$MadelineProto->upload('tests/60','magic');// This gets an inputFile object with file name magic
\danog\MadelineProto\Logger::log(time()-$time);
$media['document']=['_'=>'inputMediaUploadedDocument','file'=>$inputFile,'mime_type'=>'magic/magic','caption'=>'This file was uploaded using MadelineProto','attributes'=>[['_'=>'documentAttributeFilename','file_name'=>'magic.magic']]];
$message='yay';
$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