1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 20:35:23 +01:00
MadelineProto/tests/testing.php

364 lines
18 KiB
PHP
Raw Normal View History

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
/*
2020-02-17 14:13:46 +01:00
Copyright 2016-2020 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/>.
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
*/
2017-08-25 18:28:08 +02:00
/**
2018-03-23 16:39:58 +01:00
* Various ways to load MadelineProto.
*/
2019-09-03 18:21:43 +02:00
use Amp\ByteStream\ReadableBuffer;
use danog\MadelineProto\API;
use danog\MadelineProto\FileCallback;
2022-12-30 19:21:36 +01:00
use danog\MadelineProto\Logger;
2023-09-26 14:29:09 +02:00
use danog\MadelineProto\Settings\AppInfo;
2022-12-30 19:21:36 +01:00
use danog\MadelineProto\VoIP;
2023-07-14 16:34:52 +02:00
use Webmozart\Assert\Assert;
use function Amp\File\read;
2019-09-03 18:21:43 +02:00
2019-12-26 19:17:31 +01:00
$loader = false;
2022-12-08 20:16:40 +01:00
if (getenv('ACTIONS_PHAR')) {
2021-09-06 16:52:05 +02:00
$loader = include 'madeline.php';
2022-12-08 20:16:40 +01:00
} elseif (!file_exists(__DIR__.'/../vendor/autoload.php') || getenv('ACTIONS_FORCE_PREVIOUS')) {
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
2022-12-08 20:16:40 +01:00
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
2021-04-05 17:58:35 +02:00
include 'madeline.php';
} else {
require_once 'vendor/autoload.php';
}
2022-12-08 20:16:40 +01:00
define('MADELINEPROTO_TEST', 'testing');
2019-12-26 19:17:31 +01:00
if ($loader) {
foreach ($loader->getClassMap() as $class => $file) {
2022-12-08 20:16:40 +01:00
if (in_array($class, [
2021-09-04 18:52:21 +02:00
'Amp\\Sync\\Internal\\MutexStorage',
'Amp\\Sync\\Internal\\SemaphoreStorage',
'Amp\\Parallel\\Sync\\Internal\\ParcelStorage',
'Amp\\Parallel\\Context\\Internal\\Thread',
'Monolog\\Test\\TestCase',
'Phabel\\Amp\\Sync\\Internal\\MutexStorage',
'Phabel\\Amp\\Sync\\Internal\\SemaphoreStorage',
'Phabel\\Amp\\Parallel\\Sync\\Internal\\ParcelStorage',
'Phabel\\Amp\\Parallel\\Context\\Internal\\Thread',
'Phabel\\Monolog\\Test\\TestCase',
2021-09-04 19:04:22 +02:00
'Phabel\\Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface',
'Phabel\\Symfony\\Component\\String\\Slugger\\AsciiSlugger',
2021-09-24 18:58:33 +02:00
'Phabel\\Composer\\Plugin',
'PhabelVendor\\Amp\\Sync\\Internal\\MutexStorage',
'PhabelVendor\\Amp\\Sync\\Internal\\SemaphoreStorage',
'PhabelVendor\\Amp\\Parallel\\Sync\\Internal\\ParcelStorage',
'PhabelVendor\\Amp\\Parallel\\Context\\Internal\\Thread',
'PhabelVendor\\Monolog\\Test\\TestCase',
'PhabelVendor\\Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface',
'PhabelVendor\\Symfony\\Component\\String\\Slugger\\AsciiSlugger',
2023-11-11 16:55:29 +01:00
], true)) {
2019-12-26 19:17:31 +01:00
continue;
}
2024-04-06 20:33:27 +02:00
if (str_starts_with($class, 'Symfony\\Thanks')) {
continue;
}
2022-12-08 20:16:40 +01:00
if (str_starts_with($class, 'PhabelVendor\\Symfony\\Component\\Console') || str_starts_with($class, 'Phabel\\Symfony\\Component\\Console') || str_ends_with($class, 'Test') || class_exists($class) || interface_exists($class)) {
2021-04-05 18:29:46 +02:00
continue;
}
2019-12-26 19:17:31 +01:00
require_once($file);
}
}
echo 'Loading settings...'.PHP_EOL;
2023-09-26 14:29:09 +02:00
$settings = (new AppInfo)
2023-01-16 13:32:28 +01:00
->setApiId((int) getenv('API_ID'))
->setApiHash(getenv('API_HASH'));
2017-06-23 22:40:55 +02:00
2018-03-23 16:39:58 +01:00
/*
* Load MadelineProto
*/
echo 'Loading MadelineProto...'.PHP_EOL;
2022-12-30 19:21:36 +01:00
$MadelineProto = new API(__DIR__.'/../testing.madeline', $settings);
2023-08-13 12:26:52 +02:00
$MadelineProto->start();
$MadelineProto->fileGetContents('https://google.com');
/*
* Test logging
*/
$MadelineProto->logger('hey', Logger::ULTRA_VERBOSE);
$MadelineProto->logger('hey', Logger::VERBOSE);
$MadelineProto->logger('hey', Logger::NOTICE);
$MadelineProto->logger('hey', Logger::WARNING);
$MadelineProto->logger('hey', Logger::ERROR);
$MadelineProto->logger('hey', Logger::FATAL_ERROR);
2017-07-09 12:08:01 +02:00
2023-08-13 12:26:52 +02:00
/**
* A small example message to use for tests.
*/
$message = getenv('GITHUB_SHA') == '' ?
'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' :
('Github actions tests in progress: commit '.getenv('GITHUB_SHA').', job '.getenv('GITHUB_JOB').', PHP version: '.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION);
2023-08-13 12:26:52 +02:00
/*
* Try making a phone call
*/
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to make a call? (y/n): ')) ?? '', 'y') !== false) {
$controller = $MadelineProto->requestCall(getenv('TEST_SECRET_CHAT'))->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
while ($controller->getCallState() < VoIP::CALL_STATE_READY) {
$MadelineProto->sleep(1);
}
$MadelineProto->logger($controller->configuration);
while ($controller->getCallState() < VoIP::CALL_STATE_ENDED) {
$MadelineProto->sleep(1);
2017-07-23 16:11:02 +02:00
}
2023-08-13 12:26:52 +02:00
}
2023-08-13 12:26:52 +02:00
/*
* Try receiving a phone call
*/
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to handle incoming calls? (y/n): ')) ?? '', 'y') !== false) {
$howmany = $MadelineProto->readline('How many calls would you like me to handle? ');
}
/*
* Secret chat usage
*/
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to make the secret chat tests? (y/n): ')) ?? '', 'y') !== false) {
if (!getenv('TEST_SECRET_CHAT')) {
throw new Exception('No TEST_SECRET_CHAT environment variable was provided!');
}
/**
* Request a secret chat.
*/
$secret_chat_id = $MadelineProto->requestSecretChat(getenv('TEST_SECRET_CHAT'));
echo 'Waiting 10 seconds for '.getenv('TEST_SECRET_CHAT').' (secret chat id '.$secret_chat_id.') to accept the secret chat...'.PHP_EOL;
2023-08-13 12:26:52 +02:00
$MadelineProto->sleep(10);
/**
* Send a markdown-formatted text message with expiration after 10 seconds.
*/
2023-08-13 12:26:52 +02:00
$sentMessage = $MadelineProto->messages->sendEncrypted([
'peer' => $secret_chat_id,
'message' => [
'_' => 'decryptedMessage',
'media' => ['_' => 'decryptedMessageMediaEmpty'], // No media
'ttl' => 10, // This message self-destructs 10 seconds after reception
'message' => '```'.$message.'```', // Code Markdown
'parse_mode' => 'Markdown',
],
]);
$MadelineProto->logger($sentMessage, Logger::NOTICE);
/**
* Send secret media.
*/
$secret_media = [];
// Photo uploaded as document, secret chat
$secret_media['document_photo'] = [
'peer' => $secret_chat_id,
'file' => __DIR__.'/faust.jpg', // The file to send
'message' => [
'_' => 'decryptedMessage',
'ttl' => 0, // This message does not self-destruct
'message' => '', // No text message, only media
'media' => [
'_' => 'decryptedMessageMediaDocument',
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), // The thumbnail must be generated manually, it must be in jpg format, 90x90
'thumb_w' => 90,
'thumb_h' => 90,
'mime_type' => mime_content_type(__DIR__.'/faust.jpg'), // The file's mime type
'caption' => 'This file was uploaded using @MadelineProto', // The caption
'file_name' => 'faust.jpg', // The file's name
'size' => filesize(__DIR__.'/faust.jpg'), // The file's size
'attributes' => [
['_' => 'documentAttributeImageSize', 'w' => 1280, 'h' => 914], // Image's resolution
2018-03-23 16:39:58 +01:00
],
],
2023-08-13 12:26:52 +02:00
],
];
// Photo, secret chat
$secret_media['photo'] = [
'peer' => $secret_chat_id,
'file' => __DIR__.'/faust.jpg',
'message' => [
'_' => 'decryptedMessage',
'ttl' => 0,
'message' => '',
'media' => [
'_' => 'decryptedMessageMediaPhoto',
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'),
'thumb_w' => 90,
'thumb_h' => 90,
'caption' => 'This file was uploaded using @MadelineProto',
'size' => filesize(__DIR__.'/faust.jpg'),
'w' => 1280,
'h' => 914,
2018-03-23 16:39:58 +01:00
],
2023-08-13 12:26:52 +02:00
],
];
2023-08-13 12:26:52 +02:00
// GIF, secret chat
$secret_media['gif'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/pony.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/pony.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/pony.mp4'), 'caption' => 'test', 'file_name' => 'pony.mp4', 'size' => filesize(__DIR__.'/faust.jpg'), 'attributes' => [['_' => 'documentAttributeAnimated']]]]];
2023-08-13 12:26:52 +02:00
// Sticker, secret chat
$secret_media['sticker'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/lel.webp', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/lel.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/lel.webp'), 'caption' => 'test', 'file_name' => 'lel.webp', 'size' => filesize(__DIR__.'/lel.webp'), 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]]]];
2023-08-13 12:26:52 +02:00
// Document, secret chat
$secret_media['document'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/60', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => 'magic/magic', 'caption' => 'test', 'file_name' => 'magic.magic', 'size' => filesize(__DIR__.'/60'), 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'fairy']]]]];
2023-08-13 12:26:52 +02:00
// Video, secret chat
$secret_media['video'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/swing.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/swing.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/swing.mp4'), 'caption' => 'test', 'file_name' => 'swing.mp4', 'size' => filesize(__DIR__.'/swing.mp4'), 'attributes' => [['_' => 'documentAttributeVideo']]]]];
2023-08-13 12:26:52 +02:00
// audio, secret chat
$secret_media['audio'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
$secret_media['voice'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
2017-06-01 18:53:05 +02:00
2023-08-13 12:26:52 +02:00
foreach ($secret_media as $type => $smessage) {
$MadelineProto->logger("Encrypting and uploading $type...");
$type = $MadelineProto->messages->sendEncryptedFile($smessage);
2017-04-21 13:14:21 +02:00
}
2023-08-13 12:26:52 +02:00
}
2017-06-30 15:36:33 +02:00
2023-08-13 12:26:52 +02:00
if (!getenv('TEST_USERNAME')) {
throw new Exception('No TEST_USERNAME environment variable was provided!');
}
$mention = $MadelineProto->getInfo(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 = [];
2023-08-13 12:26:52 +02:00
// Image
$media['photo'] = ['_' => 'inputMediaUploadedPhoto', 'file' => __DIR__.'/faust.jpg'];
2023-08-13 12:26:52 +02:00
// Image by URL
$media['photo_url'] = ['_' => 'inputMediaPhotoExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/faust.jpg'];
2023-08-13 12:26:52 +02:00
// Sticker
$media['sticker'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/lel.webp', 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL']]];
2023-08-13 12:26:52 +02:00
// Video
$media['video'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/swing.mp4', 'attributes' => [['_' => 'documentAttributeVideo']]];
2023-08-13 12:26:52 +02:00
// audio
$media['audio'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
2023-08-13 12:26:52 +02:00
// voice
$media['voice'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
2023-08-13 12:26:52 +02:00
// Document
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/60', 'mime_type' => 'magic/magic', 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'magic.magic']]];
2018-02-19 12:48:43 +01:00
2023-08-13 12:26:52 +02:00
// Document by URL
$media['document_url'] = ['_' => 'inputMediaDocumentExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/60'];
2023-08-13 12:26:52 +02:00
$message = 'yay '.PHP_VERSION_ID;
$mention = $MadelineProto->getInfo(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
2021-04-23 15:51:33 +02:00
2023-08-13 12:26:52 +02:00
$peers = json_decode(getenv('TEST_DESTINATION_GROUPS'), true);
if (!$peers) {
die("No TEST_DESTINATION_GROUPS array was provided!");
}
foreach ($media as &$inputMedia) {
$inputMedia['content'] = isset($inputMedia['file'])
? read($inputMedia['file'])
: $MadelineProto->fileGetContents($inputMedia['url']);
}
2023-09-11 09:53:35 +02:00
function eq(string $file, string $contents, string $type, string $subtype): void
{
if ($type !== 'photo' && $type !== 'photo_url') {
2023-09-11 09:53:35 +02:00
Assert::eq(read($file), $contents, "Not equal $type $subtype!");
}
}
function sendMedia(API $MadelineProto, array $media, string $message, string $mention, mixed $peer, string $type): void
{
$medias = [
2023-11-11 16:55:29 +01:00
'base' => $media,
];
if (isset($media['file']) && is_string($media['file'])) {
$MadelineProto->sendDocument(
peer: $peer,
file: new ReadableBuffer(read($media['file'])),
2023-11-11 16:55:29 +01:00
callback: static fn ($v) => $MadelineProto->logger($v),
fileName: basename($media['file'])
);
$medias['callback'] = array_merge(
$media,
2023-11-11 16:55:29 +01:00
['file' => new FileCallback($media['file'], static fn ($v) => $MadelineProto->logger(...))]
);
$medias['stream'] = array_merge(
$media,
['file' => new ReadableBuffer(read($media['file']))]
);
$medias['callback stream'] = array_merge(
$media,
2023-11-11 16:55:29 +01:00
['file' => new FileCallback(new ReadableBuffer(read($media['file'])), static fn ($v) => $MadelineProto->logger(...))]
);
} elseif (isset($media['url'])) {
$medias['callback'] = array_merge(
$media,
2023-11-11 16:55:29 +01:00
['url' => new FileCallback($media['url'], static fn ($v) => $MadelineProto->logger(...))]
);
}
foreach ($medias as $subtype => $m) {
$MadelineProto->logger("Sending $type $subtype");
$dl = $MadelineProto->extractMessage($MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $m, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']));
$MadelineProto->logger("Downloading $type $subtype");
$file = $MadelineProto->downloadToDir($dl, '/tmp');
2023-09-11 09:53:35 +02:00
eq($file, $m['content'], $type, $subtype);
}
}
2023-08-13 12:26:52 +02:00
foreach ($peers as $peer) {
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
$MadelineProto->logger($sentMessage, Logger::NOTICE);
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => str_repeat('a', 4096*4)]);
$MadelineProto->logger($sentMessage, \danog\MadelineProto\Logger::NOTICE);
foreach ($media as $type => $inputMedia) {
if ($type !== 'sticker' && $type !== 'voice') {
$MadelineProto->logger("Sending multi $type");
$MadelineProto->messages->sendMultiMedia(['peer' => $peer, 'multi_media' => [
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
]]);
}
sendMedia($MadelineProto, $inputMedia, $message, $mention, $peer, $type);
2023-07-14 16:34:52 +02:00
2023-08-13 12:26:52 +02:00
$MadelineProto->logger("Uploading $type");
$media = $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
2023-07-14 16:34:52 +02:00
2023-08-13 12:26:52 +02:00
$MadelineProto->logger("Downloading $type");
$file = $MadelineProto->downloadToDir($media, '/tmp');
2023-09-11 09:53:35 +02:00
eq($file, $inputMedia['content'], $type, "upload");
2023-07-14 16:34:52 +02:00
2023-08-13 12:26:52 +02:00
$MadelineProto->logger("Re-sending $type");
$inputMedia['file'] = $media;
2023-07-14 16:34:52 +02:00
2023-08-13 12:26:52 +02:00
$dl = $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
2023-07-14 16:34:52 +02:00
2023-08-13 12:26:52 +02:00
$MadelineProto->logger("Re-downloading $type");
$file = $MadelineProto->downloadToDir($dl, '/tmp');
2023-09-11 09:53:35 +02:00
eq($file, $inputMedia['content'], $type, "re-upload");
}
2023-08-13 12:26:52 +02:00
}
2023-08-13 12:26:52 +02:00
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
$MadelineProto->logger($sentMessage, Logger::NOTICE);
}