diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index ca2197d..d4c0b65 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -10,20 +10,20 @@ jobs: runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} steps: - + - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.6.0 + uses: dependabot/fetch-metadata@v2 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - + - name: Auto-merge Dependabot PRs for semver-minor updates if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - + - name: Auto-merge Dependabot PRs for semver-patch updates if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} run: gh pr merge --auto --merge "$PR_URL" diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 970633c..60810ba 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -8,14 +8,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@1.0.0 + uses: aglipanci/laravel-pint-action@v2 - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Fix styling diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 557d263..d9306d6 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -11,16 +11,16 @@ jobs: name: phpstan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.3' coverage: none - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v3 - name: Run PHPStan run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 39ff7ee..882e07e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,18 +13,18 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1] - laravel: [9.*] + php: [8.3] + laravel: [11.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 9.* - testbench: 7.* + - laravel: 11.* + testbench: 9.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index b20f3b6..0cdea23 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: main @@ -21,7 +21,7 @@ jobs: release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: branch: main commit_message: Update CHANGELOG diff --git a/README.md b/README.md index aeb88a8..482b6dd 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,6 @@ In your Laravel notifications: * Add the `TwilioChannel` to your `via` return array value * Build a `toTwilio` function that returns a `TwilioMessage` object -By default, the Twilio Channel will use your notifiable's `phone_number` field -to send a phone number, which must be in a format such as `18884445555`. See -below how to override this. - ```php notify(new InvoicePaid($invoice)); ``` ## Testing @@ -137,7 +145,7 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits -- [Aaron Krauss](https://github.com/thecodeboss) +- [Aaron Krauss](https://github.com/alkrauss48) - [All Contributors](../../contributors) ## License diff --git a/composer.json b/composer.json index 9867978..0c549fb 100644 --- a/composer.json +++ b/composer.json @@ -16,22 +16,22 @@ } ], "require": { - "php": "^8.1", - "spatie/laravel-package-tools": "^1.9.2", - "twilio/sdk": "^6.40" + "php": "^8.0", + "spatie/laravel-package-tools": "^1.0", + "twilio/sdk": "^8.0" }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^6.0", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^7.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.1", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5", - "spatie/laravel-ray": "^1.26" + "nunomaduro/collision": "^8.0", + "larastan/larastan": "^3.0", + "orchestra/testbench": "^9.0", + "pestphp/pest": "^3.0", + "pestphp/pest-plugin-laravel": "^3.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^11.0", + "spatie/laravel-ray": "^1.0" }, "autoload": { "psr-4": { @@ -47,7 +47,6 @@ "scripts": { "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/pest", - "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" }, "config": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 893821b..f80155e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,5 +9,4 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: false - checkMissingIterableValueType: false - + noEnvCallsOutsideOfConfig: false diff --git a/src/Channels/TwilioChannel.php b/src/Channels/TwilioChannel.php index f9cd89f..f2bd67d 100644 --- a/src/Channels/TwilioChannel.php +++ b/src/Channels/TwilioChannel.php @@ -3,6 +3,7 @@ namespace Clevyr\LaravelTwilioChannel\Channels; use Clevyr\LaravelTwilioChannel\Contracts\TwilioNotification; +use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Log; use Twilio\Rest\Client; @@ -61,13 +62,27 @@ public function send($notifiable, TwilioNotification $notification) // Get the message object from the notification $twilioMessage = $notification->toTwilio($notifiable); + // Get the phone number from the notification. Supports on-demand + // notifications, as well as normal notifiable notifications. + $phoneNumber = $this->getRecipientPhoneNumber($notifiable); + // Send the SMS message - $this->client->messages->create( - $notifiable->{$notifiable->twilioPhoneNumberField ?? 'phone_number'}, - [ - 'from' => $this->from_phone_number, - 'body' => $twilioMessage->fullMessage(), - ] - ); + $this->client->messages->create($phoneNumber, [ + 'from' => $this->from_phone_number, + 'body' => $twilioMessage->fullMessage(), + ]); + } + + private function getRecipientPhoneNumber(mixed $notifiable): string + { + if ($notifiable instanceof AnonymousNotifiable && array_key_exists('twilio', $notifiable->routes)) { + return strval($notifiable->routes['twilio']); + } + + if ($notifiable->twilioPhoneNumberField !== null) { + return $notifiable->twilioPhoneNumberField; + } + + return $notifiable->phone_number; } } diff --git a/src/LaravelTwilioChannel.php b/src/LaravelTwilioChannel.php index 8c03821..6af86c1 100755 --- a/src/LaravelTwilioChannel.php +++ b/src/LaravelTwilioChannel.php @@ -2,6 +2,4 @@ namespace Clevyr\LaravelTwilioChannel; -class LaravelTwilioChannel -{ -} +class LaravelTwilioChannel {} diff --git a/tests/TwilioMessageTest.php b/tests/TwilioMessageTest.php index 6fef91d..fdb42f8 100644 --- a/tests/TwilioMessageTest.php +++ b/tests/TwilioMessageTest.php @@ -3,7 +3,7 @@ use Clevyr\LaravelTwilioChannel\Messages\TwilioMessage; beforeEach(function () { - $this->message = new TwilioMessage(); + $this->message = new TwilioMessage; $this->message ->line('Line 1')