Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

public function sendPhotoAdmin($chatid, $fileid, $caption, $buttons = NULL) { $postdata…

  1. User

    public function sendPhotoAdmin(chatid,chat_id, file_id, caption,caption, buttons = NULL) { postdata=[′chatid′=>post_data = [ 'chat_id' => chat_id, 'photo' => fileid,′caption′=>file_id, 'caption' => caption, ]; // Если переданы кнопки, добавляем их к сообщению if (!is_null(buttons) && is_array(buttons)) { postdata[′replymarkup′]=post_data['reply_markup'] = this->buildInlineKeyBoard($buttons); }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendPhoto');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_exec($ch);
        curl_close($ch);
    }
    

    мне нужно написать рассылку всем пользователям с фото и текстом к ней

  2. Assistant

    Для отправки рассылки всем пользователям с фото и текстом вы можете использовать следующий код:

    public function sendPhotoToAllUsers($file_id, $caption, $buttons = NULL)
    {
        // Получаем список всех пользователей
        $users = $this->getAllUsers();
    
        // Отправляем фото и текст каждому пользователю
        foreach ($users as $user) {
            $chat_id = $user['chat_id'];
            $this->sendPhotoAdmin($chat_id, $file_id, $caption, $buttons);
        }
    }
    
    public function sendPhotoAdmin($chat_id, $file_id, $caption, $buttons = NULL)
    {
        $post_data = [
            'chat_id' => $chat_id,
            'photo' => $file_id,
            'caption' => $caption,
        ];
        // Если переданы кнопки, добавляем их к сообщению
        if (!is_null($buttons) && is_array($buttons)) {
            $post_data['reply_markup'] = $this->buildInlineKeyBoard($buttons);
        }
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendPhoto');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_exec($ch);
        curl_close($ch);
    }
    

    Вызовите функцию sendPhotoToAllUsers и передайте ей file_id (идентификатор файла фото), caption (текст к фото) и, если нужно, массив buttons (массив с кнопками). Этот код пройдет по списку всех пользователей и отправит фото и текст каждому пользователю.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.