duanhe6718 2015-10-23 12:43
浏览 51
已采纳

电报sendDocument api,更改标题

I have created a bot, and i want to send file (document) using my bot to my clients, after sending document using following code, title will be full path of my file on my own device ( my pc ), how can I change title to file name only? is that even possible?

Sending code:

 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");

This is result: enter image description here

  • 写回答

1条回答 默认 最新

  • duanchen7036 2015-10-31 12:48
    关注

    I've found a solution by using ->setPostFilename() for CURLFile here it is:

    change this method:

    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());
    }
    

    to:

    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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器