Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload photos to the channel #479

Open
Amirrezaheydari81 opened this issue Jul 29, 2024 · 5 comments
Open

Unable to upload photos to the channel #479

Amirrezaheydari81 opened this issue Jul 29, 2024 · 5 comments

Comments

@Amirrezaheydari81
Copy link

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
Copy link
Contributor

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

@Amirrezaheydari81
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

The bot is in the admin channel and has all access

@Amirrezaheydari81
Copy link
Author

Did it not work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants