Mencari Sesuatu ?

Selasa, 06 Desember 2022

PHP FUNCTION Send document Telegram bot channel

 



function send_file_telegram($file,$message,$channelid,$token){  
    $curl = curl_init();
    $fh=new CURLFile(realpath($file));
    curl_setopt_array($curl, [
      CURLOPT_URL => "https://api.telegram.org/bot".urlencode($token)."/sendDocument",  
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => array(
        "document"=>$fh,
        "caption"=>$message,
        "disable_notification"=>true,
        "chat_id"=>$channelid,
      ),
      CURLOPT_HTTPHEADER => [
        "User-Agent: Telegram Bot SDK",
        "Content-Type: multipart/form-data;charset=utf-8"
      ],
    ]);
   
    $response = curl_exec($curl);
    $err = curl_error($curl);
   
    curl_close($curl);
   
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
   
}


Tidak ada komentar:

Posting Komentar