TelegramBot / Api

Native PHP Wrapper for Telegram BOT API
MIT License
1.09k stars 325 forks source link

Unable to upload photos to the channel #479

Open Amirrezaheydari81 opened 3 months ago

Amirrezaheydari81 commented 3 months ago

Why can't the images sent by the user be uploaded to the robot in a channel? I have tested several times, but it doesn't seem to work.

bernard-ng commented 3 months ago

@Amirrezaheydari81 Can you provide a context please ? any error message ?

Amirrezaheydari81 commented 3 months ago

This is my code `<?php require_once 'vendor/autoload.php';

use TelegramBot\Api\Client; use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;

// بارگیری تنظیمات $config = require 'config.php'; $bot = new Client($config['bot_token']);

// Handle /start command $bot->command('start', function ($message) use ($bot) { $keyboard = new InlineKeyboardMarkup([ [ ['text' => 'پشتیبانی', 'callback_data' => 'support'], ['text' => 'حساب کاربری', 'callback_data' => 'account'], ['text' => 'احراز هویت', 'callback_data' => 'authentication'] ] ]); $startMessage = "سلام، به ربات پی ارز خوش آمدید⚡️"; $bot->sendMessage($message->getChat()->getId(), $startMessage, null, false, null, $keyboard); });

// Function to handle photo upload function handlePhotoUpload($bot, $config, $chatId, $data) { $bot->on(function ($update) use ($bot, $config, $chatId, $data) { $message = $update->getMessage(); if ($message && $message->getPhoto()) { $photo = $message->getPhoto()[0]->getFileId(); try { // Send photo to the channel $bot->sendPhoto($config['channel_id'], $photo, "درخواست احراز هویت با سطح: $data"); $bot->sendMessage($chatId, 'عکس شما با موفقیت ارسال شد.'); } catch (\Exception $e) { $bot->sendMessage($chatId, 'خطا در ارسال عکس به کانال: ' . $e->getMessage()); } } else { $bot->sendMessage($chatId, 'لطفاً یک عکس ارسال کنید.'); } }, function ($update) { return $update->getMessage() && $update->getMessage()->getPhoto() !== null; }); }

// Handle callback query $bot->on(function ($update) use ($bot, $config) { $callback = $update->getCallbackQuery(); if ($callback) { $data = $callback->getData(); $chatId = $callback->getMessage()->getChat()->getId();

    if ($data == 'authentication') {
        $keyboard = new InlineKeyboardMarkup([
            [
                ['text' => 'سطح روزانه 500 هزار خرید', 'callback_data' => 'level_500k'],
                ['text' => 'سطح روزانه 1 میلیون تومان خرید', 'callback_data' => 'level_1m'],
                ['text' => 'سطح روزانه 10 میلیون تومان خرید', 'callback_data' => 'level_10m']
            ]
        ]);
        $bot->sendMessage($chatId, 'لطفاً یکی از سطوح زیر را انتخاب کنید:', null, false, null, $keyboard);
    } elseif (in_array($data, ['level_500k', 'level_1m', 'level_10m'])) {
        $bot->sendMessage($chatId, 'لطفاً عکس خود را ارسال کنید:');
        handlePhotoUpload($bot, $config, $chatId, $data);
    } elseif ($data == 'account') {
        $bot->sendMessage($chatId, 'شما دکمه account را فشار دادید.');
    } elseif ($data == 'support') {
        $bot->sendMessage($chatId, 'شما دکمه support را فشار دادید.');
    }
}

}, function () { return true; });

$bot->run(); `

The user selects authentication and selects a plan again, and when he sends his photo, that photo should be uploaded to the channel so that the administrator can approve it, but this does not happen and does not give any error.

bernard-ng commented 3 months ago

This seems correct to me, without an error message it's hard to find a solution but first make sure that your bot has the right to send a photo in the channel.

Amirrezaheydari81 commented 3 months ago

The bot is in the admin channel and has all access

Amirrezaheydari81 commented 2 months ago

Did it not work?