MadelineProto | Persian Channel
332 subscribers
3 photos
1 file
44 links
کانال تلگرامی MadelineProto Farsi !
مرجع آموزش و آپدیت های مدلین به زبان فارسی!

👥 Persian Group: https://t.me/joinchat/DtxwN0RlsQoKyN-lpSuOEw

👥 English Group: https://t.me/joinchat/Bgrajz6K-aJS2Dc5HJ7dsA

📢 English Channel:
@MadelineProto
Download Telegram
Forwarded from MadelineProto | Official Channel (Daniil Gentili)
Introducing MadelineProto 7!

This update is mandatory for all MadelineProto users.

Due to 64-bit user IDs and Telegram's new API TOS, starting from January 1, 2022, old MadelineProto instances will stop working completely: even now, legacy instances can't login due to UPDATE_APP_TO_LOGIN errors.

If you're using MadelineProto 1 through 6, visit the releases page to view changelogs and upgrade tips.
You can also open an issue or visit the support group if you encounter issues while upgrading.

For most usecases, no changes are needed: however, graphical clients based on MadelineProto must implement sponsored messages.

Features:
- MadelineProto 7 provides a simple cached API to work with sponsored messages:
=> getSponsoredMessages
Get sponsored messages for channel, returns a list of sponsored message objects.
=> viewSponsoredMessage
Mark sponsored message as read.

Clients must then handle fetched sponsored messages as described in the API documentation.

- Layer 135! See the API documentation for a list of changed methods and constructors in layer 131-133.
Changes in layer 133-135:

Added methods:
- account.setAuthorizationTTL
- account.changeAuthorizationSettings
- messages.getSearchResultsCalendar
- messages.getSearchResultsPositions
- messages.hideChatJoinRequest
- messages.hideAllChatJoinRequests
- messages.toggleNoForwards
- messages.saveDefaultSendAs
- channels.getSendAs

Changed methods:
- Renamed channels.deleteUserHistory to channels.deleteParticipantHistory; the old method still works.
- Added base_theme param to account.installTheme
- Added min_date, max_date params to messages.deleteHistory
- Added send_as param to messages.sendMessage, messages.sendMedia, messages.sendMultiMedia, messages.forwardMessages, messages.sendInlineBotResult
- Added request_needed, title params to messages.exportChatInvite, messages.editExportedChatInvite
- Added requested, q params to messages.getChatInviteImporters
- Renamed user_id=>participant in channels.reportSpam


Changed Constructors
- Added requests_pending param to chatFull
- Added recent_requesters param to chatFull
- Added requests_pending param to channelFull
- Added recent_requesters param to channelFull
- Added default_send_as param to channelFull
- Added request_chat_broadcast param to peerSettings
- Added request_chat_title param to peerSettings
- Added request_chat_date param to peerSettings
- Added private_forward_name param to userFull
- Added authorization_ttl_days param to account.authorizations
- Added request_needed param to chatInviteExported
- Added requested param to chatInviteExported
- Added title param to chatInviteExported
- Added request_needed param to chatInvite
- Added about param to chatInvite
- Added via_request param to channelParticipantSelf

New Constructors
- messageActionChatJoinedByRequest
- updatePendingJoinRequests
- updateBotChatInviteRequester
- inputKeyboardButtonUserProfile
- keyboardButtonUserProfile
- channelAdminLogEventActionParticipantJoinByRequest
- channelAdminLogEventActionToggleNoForwards
- channelAdminLogEventActionSendMessage

- New simplified EventHandler::startAndLoop API!
- Added support for t.me/+ invite links!
- New sponsored message API!
- Improved DB ORM API, used for example in the event handler!
- New FFI-based prime.madelineproto.xyz factorization module!
- An all new thread-safe madeline.php autoupdater!
- PHP 8.1 support!
- Zend hashmaps are now periodically reallocated to clean up RAM!

Deprecations:
- Dropped 32-bit support.
Android users can install 64-bit builds of php using Termux.
Raspberry pi users can use a 64-bit distro like archlinuxarm.org.
- madeline.php supports only php 7.1+
- composer supports only php 8+ (7.1+ support coming back soon)

Fixes:
- Fixed a side-channel reported by Theo von Arx and Kenneth G. Paterson @ ETH Zürich.

Internal improvements:
- Many, many internal bugfixes and performance improvements!
- Switched to the new RSA-OAEP-based authkey flow.
- Native openssl integration for faster crypto!
- Removed loads of legacy 32-bit hacks, greatly improving performance!
Forwarded from MadelineProto | Official Channel (Daniil Gentili)
As usual, bot.php on github always contains a constantly-updated example source for the latest version of MadelineProto :)
Forwarded from MadelineProto | Official Channel (Daniil Gentili)
Note: it seems like some versions of the eio extension may cause a corruption of the phar file, make sure to disable it to avoid issues.
Forwarded from MadelineProto | Official Channel (Daniil Gentili)
Re-added php 7.1+ support for composer releases; madeline.php always supported php 7.1+.

As usual, legacy PHP versions are supported but php 8.1 is recommended for huge performance improvements with JIT and now amphp fibers :D

Also note that madeline.php phar builds will not behave properly with opcache, so use composer builds to make use of opcache and JIT on PHP 8+.
Forwarded from MadelineProto | Official Channel (Daniil Gentili)
Fixed Permission Denied errors on Windows caused by flock platform quirks.
This fixes madeline.php and downloads to files as well.
Forwarded from Daniil Gentili's news channel (Daniil Gentili)
Happy New Year everyone!

As a small present for any Blender user subscribed to this channel, I just created an AUR package for BlendNet: an open source plugin that allows distributing CPU and GPU renders across multiple machines.

BlendNet natively integrates with major cloud providers like AWS, Azure or GCP, and also supports self-hosting your own render farm.
My blendnet AUR package provides systemd units and configuration to quickly deploy your own self-hosted CUDA GPU-accelerated Blendnet render farm.

Feel free to check out the new arch BlendNet wiki page for more info: https://wiki.archlinux.org/title/Blender#BlendNet

Have fun Blendering in the new year!
MadelineProto was updated (8.0.0-beta80)!

Features:
- Introducing a new broadcasting API!
- You can now specify a custom serializer type for your ORM properties (one of the variants of the SerializerType enum, or null to choose the best serializer automatically (the default)).

Fixes:
- The documentation was updated, including human-readable descriptions for the latest layer.
- Postgres now uses the new BYTEA amphp APIs
- Multiple fixes and improvements.
MadelineProto now offers a simple broadcast API, that can be used to asynchronously broadcast messages to all users of a bot or userbot in the background, without incurring in timeouts or other issues.

Note that unlike the bot API, MadelineProto can be used to fetch the full list of users, chats and channels of a normal bot, simply using its bot token.

Here's a simple example, explaining how to broadcast a message and a photo to every user of a bot:
<?php
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

$MadelineProto = new \danog\MadelineProto\API('bot.madeline');

// The UI will ask you to insert your bot token here
$MadelineProto->start();

$id = $MadelineProto->broadcastMessages([
['message' => 'This broadcast is powered by @MadelineProto!'],
['message' => 'This media broadcast is powered by @MadelineProto!', 'media' => [
'_' => 'inputMediaUploadedPhoto',
'file' => 'https://docs.madelineproto.xyz/logo-hover.png'
]],
]);

Here's a simplified example, just for bots:

<?php
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

$MadelineProto = new \danog\MadelineProto\API('bot.madeline');

$MadelineProto->botLogin('1234:token');

$id = $MadelineProto->broadcastMessages([
['message' => 'This broadcast is powered by @MadelineProto!'],
['message' => 'This media broadcast is powered by @MadelineProto!', 'media' => [
'_' => 'inputMediaUploadedPhoto',
'file' => 'https://docs.madelineproto.xyz/logo-hover.png'
]],
]);

You can also forward messages:

// Send messages, showing the "Forwarded from" header
$id = $MadelineProto->broadcastForwardMessages(
from_peer: 101374607,
message_ids: [1, 2, 3, 4],
drop_author: false,
);

// Send messages WITHOUT showing the "Forwarded from" header
$id = $MadelineProto->broadcastForwardMessages(
from_peer: 101374607,
message_ids: [1, 2, 3, 4],
drop_author: true,
);

The methods return an integer ID that can be used to:

- Get the current broadcast progress with getBroadcastProgress
- Cancel the broadcast using cancelBroadcast

Note that to avoid manually polling the progress, MadelineProto will also periodically emit updateBroadcastProgress updates to the event handler, containing a Progress object for all broadcasts currently in-progress.

Filtering is also available, as well as support for custom broadcast actions.

See here » for a full example of the broadcast API, and here » for the full documentation.
MadelineProto was updated (8.0.0-beta87)!

MadelineProto now offers an official docker image for the linux/amd64, linux/arm64 and linux/riscv64 platforms!

The image comes with all dependencies pre-configured.
Both opcache and JIT are enabled by default, for maximum performance!

To get started, install docker:

curl -fsSL https://get.docker.com | sudo sh


Then increase the max_map_count sysctl configuration to avoid "Fiber stack allocate failed" and "Fiber stack protect failed" errors, since the PHP engine mmaps two memory regions per fiber.

echo 262144 | sudo tee /proc/sys/vm/max_map_count
echo vm.max_map_count=262144 | sudo tee /etc/sysctl.d/40-madelineproto.conf


Then, create the following docker-compose.yml file:

services:
bot:
image: hub.madelineproto.xyz/danog/madelineproto
restart: unless-stopped
tty: true
volumes:
- .:/app
command: php /app/bot.php


Then, create a bot.php file with your code, and run this command to log into the bot:

docker run --rm -it --init -v $PWD:/app hub.madelineproto.xyz/danog/madelineproto php /app/bot.php


After logging in, press ctrl-c to close the temporary container.

Finally, simply run this command to start the bot in the background.

docker compose up --pull always -d


Use docker compose logs to view MadelineProto logs and docker compose ps to view the status of your bot!

See the documentation for more info about the docker image.

Other features:
- Add getType method
- Add support for emojis with <emoji id="1234">👍</emoji>, <tg-emoji emoji-id="1234>👍</tg-emoji> HTML tags and tg://emoji?id=1234 HTML/markdown links, in addition to the pre-existing emoji:id HTML/markdown links.
- Add showPrompt AppInfo setting, to allow throwing an exception instead of showing a readline/UI prompt if no API ID was configured.

Fixes:
- Change name of parameter of broadcastForwardMessages from ids to message_ids to avoid confusion.
MadelineProto | Persian Channel pinned «MadelineProto now offers a simple broadcast API, that can be used to asynchronously broadcast messages to all users of a bot or userbot in the background, without incurring in timeouts or other issues. Note that unlike the bot API, MadelineProto can be used…»
#beta100 #update
خوب بریم درباره اپدیت بزرگ بتا 100 مدلین

اول از همه قابلیت های ریز رو میگم چون اونا خودش پیام جدا میخاد:

- پارامتر pin به broadcastMessages, broadcastForwardMessages اضافه شده و خودکار پیام رو میفرسته پین هم میکنه.

- متود sendMessageToAdmins اضافه شده که به همه ادمین هایی که توسط getReportPeers تعیین شدن پیام ارسال میکنه

- اضافه شدن متودهای wrapUpdate, wrapMessage, wrapMedia برای کار کردن با bound methods

- کلاس PeerNotInDbException برای هند ارور "This peer is not present in the internal peer database" اضافه شده

- متود isForum بررسی میکنه که آیا این سوپرگروه تاپیک داره یا نه.

- متود entitiesToHtml انتیتی هارو بصورت تگ html روی متن اعمال میکنه

- اگه مشکل رم دارید از متود reportMemoryProfile استفاده کنید تا فایل pprof به ادمین ها (getReportPeers) ارسال کنه و به دنیل با اطلاعات برای رفع مشکلات رم کمک کنید.

- برای ساختار کیبورد bot API کیبورد های جدید : pay, loginurl, webapp و لینک
tg://user?id=
هم اکنون پشتیبانی میشه.

- متود getAdminIds اضافه شده که لیست ایدی هایی رو میده که توسط getReportPeers شما مشخص کردید.

- با وجود enum ParseMode از این ببعد برای پارامتر mark_down باید ازش استفاده کنیم:
\danog\MadelineProto\ParseMode::HTM
\danog\MadelineProto\ParseMode::MARKDOWN
\danog\MadelineProto\ParseMode::TEXT

- برای پارس مود HTML lists هم پشتیبانی میشه.

- پارس مود مارک داون تگ های html رو دیگه تبدیل(پارس) نمیکنه.

- پارس مود ورژن 2 اپدیت هایی داشته : bot API MarkdownV2

باگ های رفع شده :

- مشکل دوباره اپلود کردن فایل ها حل شد.

- با استفاده از ReadableBuffer میتونیم از این ببعد یک رشته (باینری مدیا) رو توسط متودها در تلگرام اپلود کنیم.

- مشکلات رم تا حدودی بهینه شدند.

- اگه اروری تو onStart اتفاق بیافته باعث نمیشه اپدیت ها هندل نشن.
#handle_update #simple_filter
هندل آپدیت ها در نسخه 100 بتا

با توجه به php8 و قابلیت جدید Attribute مدلین قابلیت جدیدی برای هندل اپدیت ها ارائه کرده.
* هندل اپدیت بصورت قدیمی هنوز ممکنه ولی این روش کار رو بسیار آسون کرده.

برای هندل آپدیت ها ابتدا یک متود با Attribute Handler مینویسیم :

use danog\MadelineProto\EventHandler\Attributes\Handler;

#[Handler]
public function h1(Incoming & Message $message): void
{
// Handle all incoming messages (private+groups+channels).
}

هر متودی که اتربیوت Handler رو داشته باشه اپدیت ها به اون ارسال میشن.
برای فیلتر آپدیت ها دوتا راه دارید:
1- استفاده از Attribute Filter
2- استفاده از Simple Filter
- Simple Filter :
شما میتونید آبجکت هارو با هم ترکیب کنید
A|B , A&B
(A&B)|(C&D) ->
(فقط در php 8.2^)

مثال ها:
( پیام های ورودی: پیام هایی که دیگران میفرستند.
پیام های خروجی: پیام هایی که ربات میفرستد. )
Message
‎پیام های ورودی و خروجی

ChannelMessage
‎پیام های ورودی و خروجی کانال

GroupMessage
‎پیام های ورودی و خروجی گروه

PrivateMessage
‎پیام های ورودی و خروجی پیوی

ServiceMessage
‎پیام های ورودی و خروجی سرویس مسیج

AbstractMessage
‎پیام های ورودی و خروجی سرویس مسیج و پیام های عادی

Incoming & Message
‎پیام های ورودی

Incoming & GroupMessage & HasMedia
‎پیام های ورودی دارای رسانه گروه

موارد بیشتر رو میتونید از داکیومنت بررسی کنید.
#handle_update #attribute_filter

هندل آپدیت ها در نسخه 100 بتا - 2

- Attribute Filter :

use danog\MadelineProto\EventHandler\Filter\FilterIncoming;
#[FilterIncoming]
public function h1(Message $message): void
{
// Handle all incoming messages (private+groups+channels).
}

*نکته:
Attribute Filter ها کاملا با Simple Filter سازگار هستن و میتونن با همدیگه ترکیب بشن:

#[new FilterOr(new FilterGroup, new FilterChannel)]
public function h4(Incoming&Message&HasMedia $message)

#[new FilterAnd(new FilterIncoming, new FilterMessage, new FilterMedia, new FilterOr(new FilterGroup, new FilterChannel))]
public function h3($message): void

که این دو حالت کاملا شبیه زیر هست :
#[Handler]
public function h3(
(Incoming & GroupMessage & HasMedia) |
(Incoming & ChannelMessage & HasMedia)
$message
): void

لیست کامل فیلترها و مثال داخل داکیومنت وجود داره.
شما حتی میتونید یک فیلتر دلخواه ایجاد کنید یا حتی حالت فیلتر هارو تغییر بدید. (اطلاعات بیشتر)
#handle_update #bound_methods

در صورت استفاده از Filter ها شما میتونید از Bound Methods استفاده کنید.
برای این مورد واقعا اصطلاح فارسی بذهنم نمیرسه بنابراین مستقیم میرم سراغ مثال:

use danog\MadelineProto\EventHandler\Attributes\Handler;

#[Handler]
public function h1(Incoming & Message $message): void
{
$message->reply('HI');
}

معادل این کد:
public function onUpdateNewMessage($update): void
{
if(
!$update['message']['out'] &&
$update['message']['_'] == 'message'
)
$this->messages->sendMessage(
peer: $update,
message: 'Hi',
reply_to_msg_id: $update['message']['id']
);
}

واضحه که کارمون راحتتره.

همچنین پراپرتی ها و متودهایی داره که کارمون رو راحتتر کرده و میتونید از اینجا لیست کامل رو بچکید.
👎1
#cron

با آپدیت بتا 100 از این ببعد برای لوپ میشه اینشکلی استفاده کرد:

use danog\MadelineProto\EventHandler\Attributes\Cron;

#[Cron(period: 60.0)]
public function cron1(): void
{
$this->sendMessageToAdmins("The bot is online, current time ".date(DATE_RFC850)."!");
}

این متود هر شصت ثانیه اجرا میشه.

شما میتونید برای اتربیوت ها اعشار هم بدید که معادل میلی ثانیه میشه.
همچنین میتونید برای دریافت اطلاعات و سیگنال دادن از متود زیر استفاده کنید:
$this->getPeriodicLoop('اسم متود');

اطلاعات بیشتر
#beta102 #update

- اضافه شدن متود openFileAppendOnly برای بازکردن یک فایل بصورت async و مود a (فقط نوشتن)

- اضافه شدن متود getDownloadLink برای گرفتن لینک دانلود (تا 4 گیگ)

مثال:
<?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->botLogin('توکن');

$link = $MadelineProto->getDownloadLink($fileId);

شما میتونید از MessageMedia هم استفاده کنید.

حتی میتونید تو 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());
}
}

* نکته: درصورت اجرا توسط web لینک دانلود بصورت خودکار ساخته میشود.

در غیر اینصورت برای استفاده در حالت cli یا تغییر لینک باید مراحل زیر رو دنبال کنید.
فایل dl.php شما باید این شکلی باشه:
<?php

if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

danog\MadelineProto\API::downloadServer('session.madeline');

و هنگام استفاده:
$link = $MadelineProto->getDownloadLink(
$botApiFileId,
'https://yourhost.com/dl.php',
size: $fileSize,
name: $fileName,
mime: $mimeType
);

و در صورت استفاده از فایل ایدی برای دریافت لینک باید اسم و سایز و نوع فایل رو بصورت دستی به متود بدید.

$botApiFileId = '...';
$fileName = '...';
$fileSize = 123..;
$mimeType = '...';

$link = $MadelineProto->getDownloadLink(
$botApiFileId,
size: $fileSize,
name: $fileName,
mime: $mimeType
);
#beta107 #update

قابلیت های جدید
- اضافه شدن متود getPeriodicLoops برای گرفتن تمام لوپ هایی که توسط اتربیوت cron ایجاد میشوند.
- اضافه شدن isReply به bound methods
#bound_methods
- لیست پراپرتی های bound methods :
- $message->message: string
متن پیام

- $message->fwdInfo: ?ForwardedInfo
اطلاعات درباره پیام هدایت شده

- $message->command: ?string
دستور ربات (در صورت وجود)

- $message->commandType: ?CommandType
نوع دستورات ربات (درصورت وجود)

- $message->commandArgs: list<string>
لیست دستورات بات (در صورت وجود)

- $message->protected: bool
آیا پیام حفاظت شده است؟

- $message->matches: list<string>
FilterRegex

- $message->fromScheduled: bool
آیا این یک پیام زمان بندی شده بوده است؟

- $message->viaBotId: ?int
در صورتی که پیام بصورت اینلاین ارسال شده باشد آیدی بات را نشان میدهد.

- $message->editDate: ?int
آخرین زمان ویرایش پیام

- $message->keyboard: InlineKeyboard|ReplyKeyboard|null
کیبورد پیام

- $message->nextSent: ?self @readonly
اگه پیام بیش از 4096 کاراکتر باشه ادامه پیام رو در قالب کلاس برمیگردونه

- $message->id: int
آیدی مسیج

- $message->out: bool
آیا این پیام از سمت خود اکانت ارسال شده

- $message->chatId: int
آیدی جایی که پیام ارسال شده

- $message->senderId: int
آیدی فرد فرستنده

- $message->replyToMsgId: ?int
آیدی پیامی که روی آن ریپلی شده

- $message->date: int
زمان ارسال پیام

- $message->topicId: ?int
آیدی تاپیکی که پیام در آن ارسال شده

- $message->replyToScheduled: bool
آیا پیام ریپلی شده یک پیام زمان بندی شده است؟

- $message->mentioned: bool
آیا اکانت در این پیام منشن شده است؟

- $message->silent: bool
آیا پیام بصورت بی صدا ارسال شده است؟

- $message->ttlPeriod: ?int
مدت زمان یک پیام نابود شونده

- $message->media
Media|null رسانه پیام
- $message->media->botApiFileId
    - $message->media->botApiFileUniqueId
‎ فایل ایدی رسانه
- $message->media->fileName, fileExt, creationDate, size, ...
لیست کامل پراپرتی های رسانه در اینجا موجود است.
#bound_methods
- لیست متود های bound methods :

- $message->getHTML(
bool $allowTelegramTags = false
): string
یک نسخه پیام با تگ های html برمیگرداند.
پارامتر allowTelegramTags مشخص میکند که تگ های خاص تلگرام مثل اسپویلر، منشن و ... نیز نمایش داده شوند یا نه.

- $message->getReply(): ?self
گرفتن اطلاعات پیام ریپلی شده.
درصورت پاک شدن پیام ریپلی شده null برمیگرداند.

- $message->delete(bool $revoke = true): void
پاک کردن پیام.
بصورت پیش فرض true = revoke است.
اگر false باشد پیام ها بصورت یک طرفه پاک میشوند.


- $message->reply(
string $message,
ParseMode $parseMode,
...
): \danog\MadelineProto\EventHandler\Message

ریپلی بر روی پیام.
برای پارامتر های بیشتر به داکیومنت مراجعه کنید.


برای کلیک کردن بر روی دکمه های کیبورد از روش زیر میتوانید کمک بگیرید:

- کلیک بر روی اولین دکمه ای که مقدارش برابر با label باشد.
$message->keyboard->press(
string $label,
bool $waitForResult
);

- کلیک بر روی دکمه با مختصات
$message->keyboard->pressByCoordinates(
int $row,
int $column,
bool $waitForResult
);
#beta108 #update
قابلیت های جدید :
- اضافه شدن پارامتر اختیاری type به FilterCommand و اضافه شدن ثابت های مربوط به آن(CommandType)
شما میتونید از این به بعد علاوه بر کامند به فیلتر مربوط به کامند تایپ هم بدین
مثال :
#[CommandFilter('hello',[CommandType::DOT,Command::SLASH])]
public function replyHello(Message&Incoming $message){
$message->reply('hello');
}

تو این حالت ربات فقط به ۲ تا کامند /hello , .hello جواب میده . در حال حاظر فقط ۳ تا حالت DOT,SLASH,BANG رو میتونید استفاده کنید و حتماباید به صورت ارایه ای از ثابت های CommandType به فیلترتون بدین(فیلتر کامند پارامتر دومش اختیاری هست و به صور دیفالت هر ۳ حالت رو درنظر میگیره)
مشکل های حل شده :
- حل مشکل مربوط به IPC در نسخه های Phar
- حل مشکل یکسری از مشکلات داخلی