File tree Expand file tree Collapse file tree
app/Domains/Social/Jobs/Publish Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments