diff --git a/.env.example b/.env.example index 51ec262..373e30d 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,7 @@ FOOD_PARTY_SCHEDULE="*/15 * * * *" MARKET_PARTY_SCHEDULE="*/15 * * * *" DEFAULT_LATITUDE=36.32112700482277 DEFAULT_LONGITUDE=59.53740119934083 +DEFAULT_IMAGE=https://raw.githubusercontent.com/ahbanavi/goshne/main/resource/default.jpg APP_NAME="GoshnePrro" APP_ENV=local diff --git a/README.md b/README.md index ac1540e..b36e757 100644 --- a/README.md +++ b/README.md @@ -115,17 +115,18 @@ docker compose exec app php artisan migrate Besides the default Laravel environment variables, you can set the following variables specifically for Goshne Prro: -| Var | Description | Required | Default | -|---------------------------|----------------------------------------------------------------|----------|-----------------------------| -| TELEGRAM_BOT_TOKEN | Telegram bot token | **Yes** | - | -| TELEGRAM_BOT_BASE_URI | Base URI (Bridge) for the Telegram Bot API | No | https://api.telegram.org | -| MARKET_PARTY_PRODUCTS_TTL | Time-to-live (TTL) for market party products caches in seconds | No | 900 | -| MARKET_PARTY_NOTIFY_TTL | TTL for market party notifications cache in seconds | No | 43200 | -| FOOD_PARTY_NOTIFY_TTL | TTL for food party notifications cache in seconds | No | 43200 | -| FOOD_PARTY_SCHEDULE | Cron schedule for food party runs | No | "*/15 * * * *" | -| MARKET_PARTY_SCHEDULE | Cron schedule for market party runs | No | "*/15 * * * *" | -| DEFAULT_LATITUDE | Default latitude for UI map | No | 36.32112700482277 (Mashhad) | -| DEFAULT_LONGITUDE | Default longitude for UI map | No | 59.53740119934083 (Mashhad) | +| Var | Description | Required | Default | +|---------------------------|----------------------------------------------------------------|----------|--------------------------------------------------------------------------------------| +| TELEGRAM_BOT_TOKEN | Telegram bot token | **Yes** | - | +| TELEGRAM_BOT_BASE_URI | Base URI (Bridge) for the Telegram Bot API | No | https://api.telegram.org | +| MARKET_PARTY_PRODUCTS_TTL | Time-to-live (TTL) for market party products caches in seconds | No | 900 | +| MARKET_PARTY_NOTIFY_TTL | TTL for market party notifications cache in seconds | No | 43200 | +| FOOD_PARTY_NOTIFY_TTL | TTL for food party notifications cache in seconds | No | 43200 | +| FOOD_PARTY_SCHEDULE | Cron schedule for food party runs | No | "*/15 * * * *" | +| MARKET_PARTY_SCHEDULE | Cron schedule for market party runs | No | "*/15 * * * *" | +| DEFAULT_LATITUDE | Default latitude for UI map | No | 36.32112700482277 (Mashhad) | +| DEFAULT_LONGITUDE | Default longitude for UI map | No | 59.53740119934083 (Mashhad) | +| DEFAULT_IMAGE | Default image for notifications | No | [Image](https://raw.githubusercontent.com/ahbanavi/goshne/main/resource/default.jpg) | ## License This project is licensed under the [Creative Commons Attribution-NonCommercial 4.0 International License](./LICENSE.md). You are free to share, copy and adapt the material in any medium or format for non-commercial purposes with proper attribution, providing a link to the license, and indicating if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. diff --git a/app/Notifications/MarketPartyNotification.php b/app/Notifications/MarketPartyNotification.php index 92779f3..eb046f4 100644 --- a/app/Notifications/MarketPartyNotification.php +++ b/app/Notifications/MarketPartyNotification.php @@ -44,7 +44,7 @@ public function toTelegram($notifiable) '🛵 '.($vendor['isPro'] ? ''.number_format($vendor['deliveryFee']).' ت ارسال رایگان (پرو)' : number_format($vendor['deliveryFee']).' ت')."\n\n". "⌛️ {$product['marketPartyCapacity']} موجود ({$product['capacity']} قابل سفارش، کف ".number_format($product['minOrder']).' ت)' ) - ->photo(empty($product['mainImage']) ? 'https://raw.githubusercontent.com/ahbanavi/goshne/main/resource/default.jpg' : $product['mainImage']) + ->photo(empty($product['mainImage']) ? config('goshne.default.image') : $product['mainImage']) ->button('🛒 سوپر مارکت ', $vendor_url); } diff --git a/app/Notifications/MyTelegramChannel.php b/app/Notifications/MyTelegramChannel.php new file mode 100644 index 0000000..829b5b2 --- /dev/null +++ b/app/Notifications/MyTelegramChannel.php @@ -0,0 +1,29 @@ +getMessage() == 'Telegram responded with an error `400 - Bad Request: wrong file identifier/HTTP URL specified`') { + if (empty($notification->product['main_image']) || $second) { + $notification->product['main_image'] = config('goshne.default.image'); + } else { + $notification->product['main_image'] = $notification->product['main_image'].'?v='.now()->timestamp; + } + $rsp = self::send($notifiable, $notification, true); + } else { + throw $e; + } + } + + return $rsp; + } +} diff --git a/app/Notifications/SnappFoodPartyNotification.php b/app/Notifications/SnappFoodPartyNotification.php index 28db361..a73bcae 100644 --- a/app/Notifications/SnappFoodPartyNotification.php +++ b/app/Notifications/SnappFoodPartyNotification.php @@ -19,9 +19,9 @@ public function __construct( public bool $isLast = false, ) {} - public function via($notifiable): array + public function via($notifiable): string { - return ['telegram']; + return MyTelegramChannel::class; } public function toTelegram($notifiable) @@ -43,7 +43,7 @@ public function toTelegram($notifiable) '🛵 '.number_format($product['deliveryFee'])." ت\n\n". "⌛️ {$product['remaining']} موجود ({$product['capacity']} قابل سفارش، کف ".number_format($product['minOrder']).' ت)' ) - ->photo(empty($product['main_image']) ? 'https://raw.githubusercontent.com/ahbanavi/goshne/main/resource/default.jpg' : $product['main_image']) + ->photo(empty($product['main_image']) ? config('goshne.default.image') : $product['main_image']) ->button('🛍️ خرید محصول', $product_url) ->button('🍽 منو '.$product['vendorTypeTitle'], $vendor_url); } diff --git a/config/goshne.php b/config/goshne.php index f1f95ab..4398e07 100644 --- a/config/goshne.php +++ b/config/goshne.php @@ -28,6 +28,7 @@ 'default' => [ 'latitude' => env('DEFAULT_LATITUDE', 36.32112700482277), 'longitude' => env('DEFAULT_LONGITUDE', 59.53740119934083), + 'image' => env('DEFAULT_IMAGE', 'https://raw.githubusercontent.com/ahbanavi/goshne/main/resource/default.jpg'), ], ];