MadelineProto was updated (8.0.0-beta101)!
After introducing plugins », bound methods », filters », a built-in cron system », IPC support for the event handler » and automatic static analysis for event handler code » in beta100, beta101 brings some bugfixes and the getDownloadLink
function!
Features:
- Added a
getDownloadLink
function, that can be used to fetch a download link for any file up to 4GB! - Added an
openFileAppendOnly
function, that can be used to asynchronously open a file in append-only mode!
Fixes:
- Improved the
markdownEscape
function! - Translated even more MadelineProto UI elements!
- Improve the static analyzer.
- Made some fixes to simple filters.
- Relax markdown parser.
- Fix quality selection of photos.
Here's an example on how to use the new getDownloadLink()
function:
<?php
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$link = $MadelineProto->getDownloadLink($MessageMedia);
$MessageMedia
can be a a media object or even a bot API file ID (files up to 4GB are supported!).
You can also use the new getDownloadLink()
bound method:
class MyEventHandler extends SimpleEventHandler {
/**
* Gets a download link for any file up to 4GB!
*/
#[FilterCommand('dl')]
public function downloadLink(Incoming&Message $message): void
{
if (!$message->replyToMsgId) {
$message->reply("This command must reply to a media message!");
return;
}
$message = $message->getReply();
if (!$message instanceof Message || !$message->media) {
$message->reply("This command must reply to a media message!");
return;
}
$message->reply("Download link: ".$message->media->getDownloadLink());
}
}
In both cases, the download link will be generated automatically if running via web.
If running via cli (or if URL rewriting is enabled), an additional step is required, see the documentation for more info.