2015-10-23 2 views
0

Я создал бота, и я хочу отправить файл (документ) с помощью моего бота на своих клиентов, после отправки документа с использованием следующего кода заголовок будет полным путем моего файла на моем собственном устройстве (мой компьютер), как я могу изменить название только для имени файла? что это возможно?Telegram sendDocument api, change Название

Отправив код:

protected function perform($method, $params) { 
     $url = new Url(TELEGRAM_API_URL . $this->bot->tokken . "/" . $method); 
     $fields = []; 
     foreach($params as $param => $val) 
      if($val != NULL && !cnull::is($val) && substr($param, 0, 1) != '_') 
       $fields[$param] = $val; 
# 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url->getUrl()); 
      curl_setopt($ch, CURLOPT_POST, count($fields)); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:multipart/form-data']); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

      $out = curl_exec($ch); 
      curl_close($ch); 
# 
      $content = json_decode($out); 
      return $content; 
} 
public function sendDocument($chat_id,$_document,$_is_file_id=false,$reply_to_message_id = NULL, $reply_markup = NULL) { 
     if($_is_file_id) 
      $document = $_document; 
     else 
      $document = new CURLFile(realpath($_document)); 
     return self::perform(__FUNCTION__, get_defined_vars()); 
} 

// ...... 
    $tg->sendDocument(USER_CHAT_ID,"filename.mp4"); 

Это результат: enter image description here

ответ

0

Я нашел решение, используя ->setPostFilename() для CURLFile здесь это:

изменить этот метод:

public function sendDocument($chat_id,$_document,$_is_file_id=false,$reply_to_message_id = NULL, $reply_markup = NULL) { 
     if($_is_file_id) 
      $document = $_document; 
     else 
      $document = new CURLFile(realpath($_document)); 
     return self::perform(__FUNCTION__, get_defined_vars()); 
} 

к:

public function sendDocument($chat_id,$_document,$_title=null,$_is_file_id=false,$reply_to_message_id = NULL, $reply_markup = NULL) { 
     if($_is_file_id) 
      $document = $_document; 
     else{ 
      $document = new CURLFile(realpath($_document)); 
      $document->setPostFilename($_title); 
     } 
     return self::perform(__FUNCTION__, get_defined_vars()); 
} 

// ...... 
    $tg->sendDocument(USER_CHAT_ID,"filename.mp4","title of file");