Telegram sendDocument api,更改标题
Telegram sendDocument api, change Title
我创建了一个机器人,我想使用我的机器人向我的客户发送文件(文档),在使用以下代码发送文档后,标题将是我自己设备(我的电脑)上文件的完整路径,如何将标题更改为仅文件名?这可能吗?
发送代码:
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");
这是结果:
我找到了一个解决方案,将 ->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");
我创建了一个机器人,我想使用我的机器人向我的客户发送文件(文档),在使用以下代码发送文档后,标题将是我自己设备(我的电脑)上文件的完整路径,如何将标题更改为仅文件名?这可能吗?
发送代码:
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");
这是结果:
我找到了一个解决方案,将 ->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");