Skip to content

Commit 66c16f4

Browse files
author
Joe FRANCOIS
committed
feat(config): makes the push notifications per request limit configurable
1 parent 8aa6c0f commit 66c16f4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ You must publish the configuration file with:
2020
php artisan vendor:publish --provider="YieldStudio\LaravelExpoNotifier\ExpoNotificationsServiceProvider" --tag="expo-notifications-config" --tag="expo-notifications-migration"
2121
```
2222

23+
### Available environment variables
24+
- `EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT` : sets the max notifications sent on a bulk request. [The official documentation says the limit should be 100](https://docs.expo.dev/push-notifications/sending-notifications/#request-errors) but in fact it's failing. You can tweak it by setting a value under 100.
25+
2326
## Usage
2427

2528
### Send notification

config/expo-notifications.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@
2525
'service' => [
2626
'api_url' => 'https://exp.host/--/api/v2/push',
2727
'host' => 'exp.host',
28+
'limits' => [
29+
// https://docs.expo.dev/push-notifications/sending-notifications/#request-errors
30+
'push_notifications_per_request' => (int) env('EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT', 99),
31+
],
2832
],
2933
];

src/ExpoNotificationsService.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
final class ExpoNotificationsService implements ExpoNotificationsServiceInterface
2323
{
24-
public const PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT = 100;
25-
2624
public const SEND_NOTIFICATION_ENDPOINT = '/send';
2725

2826
private PendingRequest $http;
@@ -35,12 +33,16 @@ final class ExpoNotificationsService implements ExpoNotificationsServiceInterfac
3533

3634
private Collection $tickets;
3735

36+
private int $pushNotificationsPerRequestLimit;
37+
3838
public function __construct(
3939
string $apiUrl,
4040
string $host,
4141
protected readonly ExpoPendingNotificationStorageInterface $notificationStorage,
4242
protected readonly ExpoTicketStorageInterface $ticketStorage
4343
) {
44+
$this->pushNotificationsPerRequestLimit = config('expo-notifications.service.limits.push_notifications_per_request');
45+
4446
$this->http = Http::withHeaders([
4547
'host' => $host,
4648
'accept' => 'application/json',
@@ -148,7 +150,7 @@ private function prepareNotificationsToSendNow(): ExpoNotificationsService
148150
->values();
149151

150152
// Splits into multiples chunks of max limitation
151-
$this->notificationChunks = $this->notificationsToSend->chunk(self::PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT);
153+
$this->notificationChunks = $this->notificationsToSend->chunk($this->pushNotificationsPerRequestLimit);
152154

153155
return $this;
154156
}

0 commit comments

Comments
 (0)