Skip to content

Commit ce3eebe

Browse files
authored
Merge pull request #18 from clevyr/update-v1.1.0
Update v1.1.0
2 parents dfe7d0b + eb59c01 commit ce3eebe

11 files changed

Lines changed: 72 additions & 53 deletions

.github/workflows/dependabot-auto-merge.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ jobs:
1010
runs-on: ubuntu-latest
1111
if: ${{ github.actor == 'dependabot[bot]' }}
1212
steps:
13-
13+
1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1.6.0
16+
uses: dependabot/fetch-metadata@v2
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
19-
19+
2020
- name: Auto-merge Dependabot PRs for semver-minor updates
2121
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
2222
run: gh pr merge --auto --merge "$PR_URL"
2323
env:
2424
PR_URL: ${{github.event.pull_request.html_url}}
2525
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
26-
26+
2727
- name: Auto-merge Dependabot PRs for semver-patch updates
2828
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
2929
run: gh pr merge --auto --merge "$PR_URL"

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ jobs:
88

99
steps:
1010
- name: Checkout code
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212
with:
1313
ref: ${{ github.head_ref }}
1414

1515
- name: Fix PHP code style issues
16-
uses: aglipanci/laravel-pint-action@1.0.0
16+
uses: aglipanci/laravel-pint-action@v2
1717

1818
- name: Commit changes
19-
uses: stefanzweifel/git-auto-commit-action@v4
19+
uses: stefanzweifel/git-auto-commit-action@v5
2020
with:
2121
commit_message: Fix styling

.github/workflows/phpstan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ jobs:
1111
name: phpstan
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: '8.1'
19+
php-version: '8.3'
2020
coverage: none
2121

2222
- name: Install composer dependencies
23-
uses: ramsey/composer-install@v1
23+
uses: ramsey/composer-install@v3
2424

2525
- name: Run PHPStan
2626
run: ./vendor/bin/phpstan --error-format=github

.github/workflows/run-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.1]
17-
laravel: [9.*]
16+
php: [8.3]
17+
laravel: [11.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20-
- laravel: 9.*
21-
testbench: 7.*
20+
- laravel: 11.*
21+
testbench: 9.*
2222

2323
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2424

2525
steps:
2626
- name: Checkout code
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828

2929
- name: Setup PHP
3030
uses: shivammathur/setup-php@v2

.github/workflows/update-changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1414
with:
1515
ref: main
1616

@@ -21,7 +21,7 @@ jobs:
2121
release-notes: ${{ github.event.release.body }}
2222

2323
- name: Commit updated CHANGELOG
24-
uses: stefanzweifel/git-auto-commit-action@v4
24+
uses: stefanzweifel/git-auto-commit-action@v5
2525
with:
2626
branch: main
2727
commit_message: Update CHANGELOG

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ In your Laravel notifications:
4747
* Add the `TwilioChannel` to your `via` return array value
4848
* Build a `toTwilio` function that returns a `TwilioMessage` object
4949

50-
By default, the Twilio Channel will use your notifiable's `phone_number` field
51-
to send a phone number, which must be in a format such as `18884445555`. See
52-
below how to override this.
53-
5450
```php
5551
<?php
5652

@@ -88,9 +84,12 @@ class MyNotification extends Notification implements TwilioNotification {
8884
}
8985
```
9086

91-
### Overriding the Notifiable Phone Number Field
9287
By default, `TwilioChannel` will use your notifiable's `phone_number` field
93-
to send an SMS message. To override this and use a different field, set the
88+
to send an SMS message, which must be in a format such as `8884445555`.
89+
90+
### Overriding the Notifiable Phone Number Field
91+
92+
To override the `phone_number` and use a different field, set the
9493
`twilioPhoneNumberField` instance variable in your notifiable class:
9594

9695
```php
@@ -100,9 +99,18 @@ class User extends Authenticatable
10099

101100
//
102101
}
102+
```
103+
104+
### On-Demand Notifications
105+
106+
If you wish to send an on-demand notification, and not use a `notifiable` object
107+
at all, you can do that:
108+
109+
```
110+
use Illuminate\Support\Facades\Notification;
103111
104-
Now if you generate a notification from a `User` object, `TwilioChannel`
105-
will use the user's `primary_phone_number` field to send messages.
112+
Notification::route('twilio', '5555555555')
113+
->notify(new InvoicePaid($invoice));
106114
```
107115

108116
## Testing
@@ -137,7 +145,7 @@ Please review [our security policy](../../security/policy) on how to report secu
137145

138146
## Credits
139147

140-
- [Aaron Krauss](https://github.com/thecodeboss)
148+
- [Aaron Krauss](https://github.com/alkrauss48)
141149
- [All Contributors](../../contributors)
142150

143151
## License

composer.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.1",
20-
"spatie/laravel-package-tools": "^1.9.2",
21-
"twilio/sdk": "^6.40"
19+
"php": "^8.0",
20+
"spatie/laravel-package-tools": "^1.0",
21+
"twilio/sdk": "^8.0"
2222
},
2323
"require-dev": {
2424
"laravel/pint": "^1.0",
25-
"nunomaduro/collision": "^6.0",
26-
"nunomaduro/larastan": "^2.0.1",
27-
"orchestra/testbench": "^7.0",
28-
"pestphp/pest": "^1.21",
29-
"pestphp/pest-plugin-laravel": "^1.1",
30-
"phpstan/extension-installer": "^1.1",
31-
"phpstan/phpstan-deprecation-rules": "^1.0",
32-
"phpstan/phpstan-phpunit": "^1.0",
33-
"phpunit/phpunit": "^9.5",
34-
"spatie/laravel-ray": "^1.26"
25+
"nunomaduro/collision": "^8.0",
26+
"larastan/larastan": "^3.0",
27+
"orchestra/testbench": "^9.0",
28+
"pestphp/pest": "^3.0",
29+
"pestphp/pest-plugin-laravel": "^3.0",
30+
"phpstan/extension-installer": "^1.0",
31+
"phpstan/phpstan-deprecation-rules": "^2.0",
32+
"phpstan/phpstan-phpunit": "^2.0",
33+
"phpunit/phpunit": "^11.0",
34+
"spatie/laravel-ray": "^1.0"
3535
},
3636
"autoload": {
3737
"psr-4": {
@@ -47,7 +47,6 @@
4747
"scripts": {
4848
"analyse": "vendor/bin/phpstan analyse",
4949
"test": "vendor/bin/pest",
50-
"test-coverage": "vendor/bin/pest --coverage",
5150
"format": "vendor/bin/pint"
5251
},
5352
"config": {

phpstan.neon.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ parameters:
99
tmpDir: build/phpstan
1010
checkOctaneCompatibility: true
1111
checkModelProperties: false
12-
checkMissingIterableValueType: false
13-
12+
noEnvCallsOutsideOfConfig: false

src/Channels/TwilioChannel.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Clevyr\LaravelTwilioChannel\Channels;
44

55
use Clevyr\LaravelTwilioChannel\Contracts\TwilioNotification;
6+
use Illuminate\Notifications\AnonymousNotifiable;
67
use Illuminate\Support\Facades\App;
78
use Illuminate\Support\Facades\Log;
89
use Twilio\Rest\Client;
@@ -61,13 +62,27 @@ public function send($notifiable, TwilioNotification $notification)
6162
// Get the message object from the notification
6263
$twilioMessage = $notification->toTwilio($notifiable);
6364

65+
// Get the phone number from the notification. Supports on-demand
66+
// notifications, as well as normal notifiable notifications.
67+
$phoneNumber = $this->getRecipientPhoneNumber($notifiable);
68+
6469
// Send the SMS message
65-
$this->client->messages->create(
66-
$notifiable->{$notifiable->twilioPhoneNumberField ?? 'phone_number'},
67-
[
68-
'from' => $this->from_phone_number,
69-
'body' => $twilioMessage->fullMessage(),
70-
]
71-
);
70+
$this->client->messages->create($phoneNumber, [
71+
'from' => $this->from_phone_number,
72+
'body' => $twilioMessage->fullMessage(),
73+
]);
74+
}
75+
76+
private function getRecipientPhoneNumber(mixed $notifiable): string
77+
{
78+
if ($notifiable instanceof AnonymousNotifiable && array_key_exists('twilio', $notifiable->routes)) {
79+
return strval($notifiable->routes['twilio']);
80+
}
81+
82+
if ($notifiable->twilioPhoneNumberField !== null) {
83+
return $notifiable->twilioPhoneNumberField;
84+
}
85+
86+
return $notifiable->phone_number;
7287
}
7388
}

src/LaravelTwilioChannel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
namespace Clevyr\LaravelTwilioChannel;
44

5-
class LaravelTwilioChannel
6-
{
7-
}
5+
class LaravelTwilioChannel {}

0 commit comments

Comments
 (0)