this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Add fallback to fetch image from originalImageUrl if cache is missing

+27
+27
bot/telegrambot/helpers/mediaHelper.js
··· 186 186 return false; 187 187 } 188 188 } 189 + } else if (mediaData.originalImageUrl && /^https?:\/\//i.test(mediaData.originalImageUrl)) { 190 + // If cache is missing, try to fetch from originalImageUrl 191 + try { 192 + const imageResponse = await axios({ 193 + method: 'GET', 194 + url: mediaData.originalImageUrl, 195 + responseType: 'stream', 196 + validateStatus: status => status >= 200 && status < 300 // Only accept 2xx 197 + }); 198 + const contentType = imageResponse.headers['content-type'] || ''; 199 + if (!contentType.startsWith('image/')) { 200 + console.error(`OriginalImageUrl did not return an image. Content-Type: ${contentType}`); 201 + return false; 202 + } 203 + await this.bot.sendPhoto( 204 + config.channelId, 205 + imageResponse.data, 206 + { 207 + caption: caption, 208 + reply_markup: inlineKeyboard 209 + } 210 + ); 211 + return true; 212 + } catch (originalError) { 213 + console.error('Error fetching and sending image from originalImageUrl:', originalError); 214 + // If this fails, fall back to sourceUrl below 215 + } 189 216 } else if (mediaData.sourceUrl && /^https?:\/\//i.test(mediaData.sourceUrl)) { 190 217 // If cache is missing, try to fetch from sourceUrl 191 218 try {