دليل إعداد بوت تليجرام الجزء الثاني برمجة الملفات php






شرح وظائف PHP مع تصميم

تعريف المتغير TOKEN

هذا المتغير يُستخدم لتخزين توكن البوت الذي يُستخدم للتفاعل مع API التليجرام.

                <?php
                define("TOKEN", $TOKEN);
                ?>
            

دالة bot

هذه الدالة تستخدم للتفاعل مع API التليجرام. يمكنك إرسال طلب إلى الخادم عبر الإنترنت للقيام بأنواع مختلفة من الأنشطة.

                function bot($method, $datas = []){
                    $iBadlz = http_build_query($datas);
                    $url = "https://api.telegram.org/bot" . TOKEN . "/" . $method . "?$iBadlz";
                    $iBadlz = file_get_contents($url);
                    return json_decode($iBadlz);
                }
            

دالة Add

هذه الدالة تُستخدم لإضافة محتوى إلى ملف معين في الخادم. يمكن استخدامها لتخزين البيانات في ملفات نصية أو أي نوع آخر من الملفات.

                function Add($path, $content){
                    $file = fopen("$path", "a") or die("Unable to open file!");
                    fwrite($file, "$content");
                    fclose($file);
                }
            

دالة GetUpdates

هذه الدالة تُستخدم للحصول على التحديثات الواردة من ملقم التليجرام. يمكن تحديد المعلمات مثل الحد الأقصى لعدد التحديثات وغيرها.

                function GetUpdates($offset = null, $limit = 100, $timeout = null, $allowed_updates = []){
                    return bot('getUpdates', [
                        'offset' => $offset,
                        'limit' => $limit,
                        'timeout' => $timeout,
                        'allowed_updates' => $allowed_updates
                    ]);
                }
            

دالة SetWebhook

هذه الدالة تُستخدم لتعيين عنوان ويب للبوت. يمكن أن يُستخدم هذا لاستقبال التحديثات عبر الويب بدلاً من استخدام استطلاع الخادم.

                function SetWebhook($url, $certificate = null, $max_connections = 100, $allowed_updates = []){
                    return bot('setWebhook', [
                        'url' => $url,
                        'certificate' => $certificate,
                        'max_connections' => $max_connections,
                        'allowed_updates' => $allowed_updates,
                    ]);
                }
            
بالطبع، سأستكمل شرح الوظائف المتبقية مع التصميم المناسب في صفحة HTML وCSS:

دالة DeleteWebhook

تستخدم هذه الدالة لحذف العنوان الويب الحالي المُعين للبوت.

        function DeleteWebhook(){
            return bot('deleteWebhook');
        }
    

دالة GetWebhookInfo

هذه الدالة تُستخدم للحصول على معلومات حول العنوان الويب الحالي للبوت.

        function GetWebhookInfo(){
            return bot('getWebhookInfo');
        }
    

دالة SendChatAction

تستخدم هذه الدالة لإرسال إشارة إلى المستخدمين تظهر أن البوت يقوم بإجراء معين، مثل "الكتابة" أو "التسجيل" أو "البحث".

        function SendChatAction($chat_id, $action){
            bot('sendChatAction', [
                'chat_id' => $chat_id,
                'action' => $action
            ]);
        }
    

دالة SendMessage

تستخدم هذه الدالة لإرسال رسائل نصية إلى مستخدمين أو مجموعات عبر البوت.

        function SendMessage($chat_id, $text, $parse_mode = "MARKDOWN", $disable_web_page_preview = true, $reply_to_message_id = null, $reply_markup = null){
            return bot('sendMessage', [
                'chat_id' => $chat_id,
                'text' => $text . "\n 👇قناة المطور الاساسي 👇\n" . '@salehalzahiri',
                'parse_mode' => $parse_mode,
                'disable_web_page_preview' => $disable_web_page_preview,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة ForwardMessage

تستخدم هذه الدالة لإعادة توجيه رسالة من مكان إلى آخر.

        function ForwardMessage($chat_id, $from_chat_id, $message_id){
            return bot('forwardMessage', [
                'chat_id' => $chat_id,
                'from_chat_id' => $from_chat_id,
                'disable_notification' => false,
                'message_id' => $message_id
            ]);
        }
    

دالة SendPhoto

تستخدم هذه الدالة لإرسال صورة إلى مستخدمين أو مجموعات عبر البوت.

        function SendPhoto($chat_id, $photo, $caption = null, $parse_mode = "MARKDOWN", $reply_to_message_id = null, $reply_markup = null){
            return bot('sendPhoto', [
                'chat_id' => $chat_id,
                'photo' => $photo,
                'caption' => $caption,
                'parse_mode' => $parse_mode,
                'disable_notification'

 => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendDocument

تستخدم هذه الدالة لإرسال مستند إلى مستخدمين أو مجموعات عبر البوت.

        function SendDocument($chat_id, $document, $caption = null, $parse_mode = "MARKDOWN", $reply_to_message_id = null, $reply_markup = null){
            return bot('sendDocument', [
                'chat_id' => $chat_id,
                'document' => $document,
                'caption' => $caption,
                'parse_mode' => $parse_mode,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendSticker

تستخدم هذه الدالة لإرسال ملصق إلى مستخدمين أو مجموعات عبر البوت.

        function SendSticker($chat_id, $sticker, $reply_to_message_id = null, $reply_markup = null){
            return bot('sendSticker', [
                'chat_id' => $chat_id,
                'sticker' => $sticker,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendLocation

تستخدم هذه الدالة لإرسال موقع جغرافي إلى مستخدمين أو مجموعات عبر البوت.

        function SendLocation($chat_id, $latitude, $longitude, $reply_to_message_id = null, $reply_markup = null){
            return bot('sendLocation', [
                'chat_id' => $chat_id,
                'latitude' => $latitude,
                'longitude' => $longitude,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendVoice

تستخدم هذه الدالة لإرسال رسالة صوتية إلى مستخدمين أو مجموعات عبر البوت.

        function SendVoice($chat_id, $voice, $caption = null, $parse_mode = "MARKDOWN", $reply_to_message_id = null, $reply_markup = null){
            return bot('sendVoice', [
                'chat_id' => $chat_id,
                'voice' => $voice,
                'caption' => $caption,
                'parse_mode' => $parse_mode,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendVideo

تستخدم هذه الدالة لإرسال فيديو إلى مستخدمين أو مجموعات عبر البوت.

        function SendVideo($chat_id, $video, $caption = null, $parse_mode = "MARKDOWN", $reply_to_message_id = null, $reply_markup = null){
            return bot('sendVideo', [
                'chat_id' => $chat_id,
                'video' => $video,
                'caption' => $caption,
                'parse_mode' => $parse_mode,
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id,
                'reply_markup' => $reply_markup
            ]);
        }
    

دالة SendChatAction

تستخدم هذه الدالة لإرسال إشارة إلى المستخدمين تظهر أن البوت يقوم بإجراء معين، مثل "الكتابة" أو "التسجيل" أو "البحث".

        function SendChatAction($chat_id, $action){
            bot('sendChatAction', [
                'chat_id' => $chat_id,
                'action' => $action
            ]);
        }
    

دالة SendMediaGroup

تستخدم هذه الدالة لإرسال مجموعة من الوسائط (صور أو فيديوهات) كمجموعة واحدة إلى مستخدمين أو مجموعات عبر البوت.

        function SendMediaGroup($chat_id, $media, $reply_to_message_id = null){
            return bot('sendMediaGroup', [
                'chat_id' => $chat_id,
                'media' => $media,
               
                'disable_notification' => false,
                'reply_to_message_id' => $reply_to_message_id
            ]);
        }
    
join Now
Join Now