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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料