Skip to content
Open
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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.editorconfig export-ignore
/tests export-ignore
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on: [push, pull_request]

jobs:
phplint:
runs-on: ubuntu-latest

name: PHP Linting (Pint)

steps:
- name: Checkout
uses: actions/checkout@v4

- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@latest
with:
preset: laravel
verboseMode: true
testMode: true
configPath: "pint.json"
pintVersion: 1.18.2
onlyDirty: true

test:
runs-on: ubuntu-latest
strategy:
max-parallel: 15
fail-fast: false
matrix:
php: [8.3, 8.2]
laravel: [11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*

name: PHP${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, xdebug
coverage: xdebug

- name: Install dependencies
run: |
composer require "illuminate/support:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest

- name: Lint composer.json
run: composer validate

- name: Run Tests
run: composer test:unit

- name: Run Integration Tests
run: composer test:integration
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# Mac DS_Store Files
.DS_Store

# composer
/vendor
composer.phar
composer.lock

# phpunit
phpunit.phar
/phpunit.xml
.phpunit.result.cache

# build
build

# laravel/pint
.pint.cache.json
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog

All notable changes to `twilio` will be documented in this file
All notable changes to `laravel-notification-channels/twilio` will be documented in this file.

## 4.0.0

- Added PHP Linting (Pint) to CI workflow
- Additional tests to achieve 100% code coverage by @pascalbaljet
- Update PhpUnit to 10.5 and fixed all tests.
- Bump `twilio/sdk` to 8.3
- Improved types and use constructor property promotion everywhere.
- Added Pint and fixed PHP syntax.
- Drop support for PHP < 8.2 **BREAKING CHANGE**
- Drop support for Laravel 7.x, 8.x, 9.x, and 10.x **BREAKING CHANGE**
- Enable overriding the Twilio message source #142
- Add enabled config option (`TWILIO_ENABLED`) to disable the channel #121

## 3.0.0

Expand Down
68 changes: 49 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Twilio notifications channel for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/github/workflow/status/laravel-notification-channels/twilio/PHP?style=flat-square)](https://travis-ci.org/laravel-notification-channels/twilio)
[![StyleCI](https://styleci.io/repos/65543339/shield)](https://styleci.io/repos/65543339)
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/twilio.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/twilio/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg)](https://packagist.org/packages/laravel-notification-channels/twilio)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)
[![Build Status](https://github.com/laravel-notification-channels/twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/laravel-notification-channels/twilio/actions/workflows/ci.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg)](https://packagist.org/packages/laravel-notification-channels/twilio)

This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 5.5+, 6.x and 7.x

You are viewing the `3.x` documentation. [Click here](https://github.com/laravel-notification-channels/twilio/tree/2.x) to view the `2.x` documentation.
This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x

## Contents

Expand All @@ -26,10 +21,10 @@ You are viewing the `3.x` documentation. [Click here](https://github.com/laravel

## Installation

You can install the package via composer:
You can install the package via Composer:

``` bash
composer require laravel-notification-channels/twilio
$ composer require laravel-notification-channels/twilio
```

### Configuration
Expand All @@ -44,7 +39,8 @@ TWILIO_ACCOUNT_SID=1234 # always required
TWILIO_FROM=100000000 # optional default from
TWILIO_ALPHA_SENDER=HELLO # optional
TWILIO_DEBUG_TO=23423423423 # Set a number that call calls/messages should be routed to for debugging
TWILIO_SMS_SERVICE_SID=MG0a0aaaaaa00aa00a00a000a00000a00a # Optional but recommended
TWILIO_SMS_SERVICE_SID=MG0a0aaaaaa00aa00a00a000a00000a00a # Optional but recommended
TWILIO_SHORTEN_URLS=true # optional, enable URL shortener
```

### Advanced configuration
Expand All @@ -57,7 +53,7 @@ Run `php artisan vendor:publish --provider="NotificationChannels\Twilio\TwilioPr
#### Suppressing specific errors or all errors

Publish the config using the above command, and edit the `ignored_error_codes` array. You can get the list of
exception codes from [the documentation](https://www.twilio.com/docs/api/errors).
exception codes from [the documentation](https://www.twilio.com/docs/api/errors).

If you want to suppress all errors, you can set the option to `['*']`. The errors will not be logged but notification
failed events will still be emitted.
Expand All @@ -69,15 +65,19 @@ Twilio recommends always using a [Messaging Service](https://www.twilio.com/docs

Having issues with SMS? Check Twilio's [best practices](https://www.twilio.com/docs/sms/services/services-best-practices).

## Upgrading from 3.x to 4.x

We have dropped support for PHP < 8.2 and the minimum Laravel version is now 11. Other than that, there are no breaking changes.

## Upgrading from 2.x to 3.x

If you're upgrading from version `2.x`, you'll need to make sure that your set environment variables match those above
in the config section. None of the environment variable names have changed, but if you used different keys in your
If you're upgrading from version `2.x`, you'll need to make sure that your set environment variables match those above
in the config section. None of the environment variable names have changed, but if you used different keys in your
`services.php` config then you'll need to update them to match the above, or publish the config file and change the
`env` key.

You should also remove the old entry for `twilio` from your `services.php` config, since it's no longer used.

The main breaking change between `2.x` and `3.x` is that failed notification will now throw an exception unless they are
in the list of ignored error codes (publish the config file to edit these).

Expand Down Expand Up @@ -131,6 +131,34 @@ class AccountApproved extends Notification
}
```

You can also send using Content Templates:

``` php
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioContentTemplateMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
public function via($notifiable)
{
return [TwilioChannel::class];
}

public function toTwilio($notifiable)
{
return (new TwilioContentTemplateMessage())
->contentSid("HXXXXXXXXXXXXXXXXXXXXXXXX")
->contentVariables([
'1' => 'John Doe',
'2' => 'ACME Inc.',
]);
}
}
```

*Note: if sending via WhatsApp, you must add `whatsapp:` to the beginning of the phone number (i.e. `->from('whatsapp:+61428000382')`). The number must also be approved as a [WhatsApp Sender](https://www.twilio.com/console/sms/whatsapp/senders).*

Or create a Twilio call:

``` php
Expand Down Expand Up @@ -187,14 +215,16 @@ $ composer test

## Security

If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker.
If you discover any security related issues, please email pipo@onlime.ch instead of using the issue tracker.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Credits

- [Philip Iezzi (Pipo)](https://github.com/onlime)
- [Pascal Baljet](https://github.com/pascalbaljet)
- [Gregorio Hernández Caso](https://github.com/gregoriohc)
- [atymic](https://github.com/atymic)
- [All Contributors](../../contributors)
Expand Down
37 changes: 26 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
{
"name": "laravel-notification-channels/twilio",
"description": "Provides Twilio notification channel for Laravel",
"keywords": ["laravel", "twilio", "notification", "sms", "call", "mms"],
"keywords": [
"laravel",
"twilio",
"notification",
"sms",
"call",
"mms"
],
"license": "MIT",
"support": {
"issues": "https://github.com/laravel-notification-channels/twilio/issues",
"source": "https://github.com/laravel-notification-channels/twilio"
},
"authors": [
{
"name": "Philip Iezzi",
"email": "pipo@onlime.ch",
"homepage": "https://github.com/onlime",
"role": "Developer"
},
{
"name": "Gregorio Hernández Caso",
"email": "gregoriohc@gmail.com",
Expand All @@ -22,16 +35,18 @@
}
],
"require": {
"php": ">=7.2",
"twilio/sdk": "~6.0",
"illuminate/notifications": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/events": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/queue": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0"
"php": "^8.2",
"twilio/sdk": "^7.16 || ^8.3",
"illuminate/notifications": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"illuminate/events": "^11.0|^12.0|^13.0",
"illuminate/queue": "^11.0|^12.0|^13.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^8.5"
"laravel/pint": "^1.18",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^9.0",
"phpunit/phpunit": "^10.5"
},
"autoload": {
"psr-4": {
Expand All @@ -45,8 +60,8 @@
},
"scripts": {
"test": "vendor/bin/phpunit",
"test:unit": "phpunit --verbose --testsuite Unit",
"test:integration": "phpunit --verbose --testsuite Integration"
"test:unit": "phpunit --testsuite Unit",
"test:integration": "phpunit --testsuite Integration"
},
"config": {
"sort-packages": true
Expand Down
2 changes: 2 additions & 0 deletions config/twilio-notification-channel.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

return [
'enabled' => (bool) env('TWILIO_ENABLED', true),
'username' => env('TWILIO_USERNAME'), // optional when using auth token
'password' => env('TWILIO_PASSWORD'), // optional when using auth token
'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password
'account_sid' => env('TWILIO_ACCOUNT_SID'),

'from' => env('TWILIO_FROM'), // optional
'alphanumeric_sender' => env('TWILIO_ALPHA_SENDER'),
'shorten_urls' => (bool) env('TWILIO_SHORTEN_URLS', false), // optional, enable twilio URL shortener

/**
* See https://www.twilio.com/docs/sms/services.
Expand Down
26 changes: 26 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
13 changes: 13 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": false,
"binary_operator_spaces": false,
"phpdoc_separation": false,
"modernize_strpos": true
},
"exclude": [
"node_modules"
],
"cache-file": ".pint.cache.json"
}
Loading
Loading