Skip to content

Commit 1f0d4e2

Browse files
committed
Update TelegramPublishJob.php
1 parent e74fa37 commit 1f0d4e2

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

app/Domains/Social/Jobs/Publish/TelegramPublishJob.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,26 @@ public function handle()
113113
*/
114114
$token = $this->platform->config['access_token'];
115115
$url = "https://api.telegram.org/bot$token/sendPhoto";
116-
$response = Http::post($url, [
116+
117+
// 取得檔案副檔名
118+
$extension = pathinfo($this->cards->getPicture(), PATHINFO_EXTENSION);
119+
120+
// 根據副檔名設定 Content-Type
121+
$contentType = match(strtolower($extension)) {
122+
'jpg', 'jpeg' => 'image/jpeg',
123+
'png' => 'image/png',
124+
'gif' => 'image/gif',
125+
'webp' => 'image/webp',
126+
default => 'application/octet-stream'
127+
};
128+
129+
$response = Http::attach(
130+
'photo',
131+
$this->cards->getPicture(),
132+
basename($this->cards->getPicture()),
133+
['Content-Type' => $contentType]
134+
)->post($url, [
117135
'chat_id' => $this->platform->config['chat_id'],
118-
'photo' => $this->cards->getPicture(),
119136
'caption' => $caption,
120137
]);
121138

0 commit comments

Comments
 (0)