Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

Expand All @@ -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
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php

Expand Down Expand Up @@ -88,9 +84,12 @@ class MyNotification extends Notification implements TwilioNotification {
}
```

### Overriding the Notifiable Phone Number Field
By default, `TwilioChannel` will use your notifiable's `phone_number` field
to send an SMS message. To override this and use a different field, set the
to send an SMS message, which must be in a format such as `8884445555`.

### Overriding the Notifiable Phone Number Field

To override the `phone_number` and use a different field, set the
`twilioPhoneNumberField` instance variable in your notifiable class:

```php
Expand All @@ -100,9 +99,18 @@ class User extends Authenticatable

//
}
```

### On-Demand Notifications

If you wish to send an on-demand notification, and not use a `notifiable` object
at all, you can do that:

```
use Illuminate\Support\Facades\Notification;

Now if you generate a notification from a `User` object, `TwilioChannel`
will use the user's `primary_phone_number` field to send messages.
Notification::route('twilio', '5555555555')
->notify(new InvoicePaid($invoice));
```

## Testing
Expand Down Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ parameters:
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: false
checkMissingIterableValueType: false

noEnvCallsOutsideOfConfig: false
29 changes: 22 additions & 7 deletions src/Channels/TwilioChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
4 changes: 1 addition & 3 deletions src/LaravelTwilioChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Clevyr\LaravelTwilioChannel;

class LaravelTwilioChannel
{
}
class LaravelTwilioChannel {}
2 changes: 1 addition & 1 deletion tests/TwilioMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Clevyr\LaravelTwilioChannel\Messages\TwilioMessage;

beforeEach(function () {
$this->message = new TwilioMessage();
$this->message = new TwilioMessage;

$this->message
->line('Line 1')
Expand Down
Loading