Skip to content

Commit

Permalink
Merge pull request #2 from simonkub/master
Browse files Browse the repository at this point in the history
add laravel notifications driver for sipgate
  • Loading branch information
simonkub committed Oct 23, 2019
2 parents ac30d4e + 0001714 commit 56c91e8
Show file tree
Hide file tree
Showing 20 changed files with 1,165 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -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
10 changes: 10 additions & 0 deletions .gitattributes
@@ -0,0 +1,10 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
/vendor
build
composer.phar
composer.lock
.idea
.phpunit.result.cache
22 changes: 22 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,22 @@
filter:
excluded_paths: [tests/*]

checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

tools:
external_code_coverage:
timeout: 600
6 changes: 6 additions & 0 deletions .styleci.yml
@@ -0,0 +1,6 @@
preset: laravel
enabled:
- alpha_ordered_imports
disabled:
- length_ordered_imports
- unused_use
22 changes: 22 additions & 0 deletions .travis.yml
@@ -0,0 +1,22 @@
language: php

php:
- 7.2
- 7.3

env:
matrix:
- COMPOSER_FLAGS="--prefer-lowest"
- COMPOSER_FLAGS=""

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- bash <(curl -s https://codecov.io/bash)
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,11 @@
# Changelog

All notable changes to `laravel-sipgate-notification` will be documented in this file

## 1.1.0 - 2019-09-30

- feature: enable/disable sipgate notification channel via .env

## 1.0.0 - 2019-09-30

- initial release
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,55 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.

## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.

## Procedure

Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.

## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) Simon Kubiak <mail@simonkubiak.de>

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
216 changes: 214 additions & 2 deletions README.md
@@ -1,2 +1,214 @@
# sipgate
Sipgate Notifications Channel for Laravel 5.5+ and 6.0
# Laravel Notifications for sipgate

[**Todo: Project Badges**]

This package makes it easy to send notifications using [sipgate](https://sipgate.de) with Laravel 5.5+ and 6.0.

## Contents

- [Installation](#installation)
- [Setting up the sipgate service](#setting-up-the-sipgate-service)
- [Web SMS Extensions / SMS ID](#web-sms-extensions--sms-id)
- [Send SMS with custom sender number](#send-sms-with-custom-sender-number)
- [Usage](#usage)
- [Create a Notification](#create-a-notification)
- [Add a recipient](#add-a-recipient)
- [Sending On-Demand Notifications](#sending-on-demand-notifications)
- [Available Message methods](#available-message-methods)
- [Common Issues](#common-issues)
- [SMS sent successfully but no message received](#sms-sent-successfully-but-no-message-received)
- [HTTP Errors](#http-errors)
- [Resources](#resources)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)


## Installation

Install the package via composer:

```bash
composer require laravel-notification-channels/sipgate
```

### Setting up the sipgate service

Extend `config/services.php` to read your sipgate credentials from your `.env`:

```php
return [

...

'sipgate' => [
'username' => env('SIPGATE_USERNAME'),
'password' => env('SIPGATE_PASSWORD'),
'smsId' => env('SIPGATE_SMSID'),
'enabled' => env('SIPGATE_NOTIFICATIONS_ENABLED', true),
]
];
```

Add your sipgate credentials to your `.env`:
```bash
SIPGATE_NOTIFICATIONS_ENABLED=true
SIPGATE_USERNAME=mail@example.com
SIPGATE_PASSWORD=1234567890
SIPGATE_SMSID=s0
```

#### Web SMS Extensions / SMS ID

A Web SMS extension consists of the letter 's' followed by a number (e.g. `s0`). The sipgate API uses the concept of Web SMS extensions to identify devices within your account that are enabled to send SMS. In this context the term 'device' does not necessarily refer to a hardware phone but rather a virtual connection.

You can find out what your extension is as follows:

1. Log into your [sipgate account](https://app.sipgate.com/connections/sms)
2. Use the sidebar to navigate to the **Connections** (_Anschlüsse_) tab
3. Click **SMS** (if this option is not displayed you might need to book the **Web SMS** feature from the Feature Store)
4. The URL of the page should have the form `https://app.sipgate.com/{...}/connections/sms/{smsId}` where `{smsId}` is your Web SMS extension.

#### Send SMS with custom sender number

By default 'sipgate' will be used as the sender. It is only possible to change the sender to a mobile phone number by verifying ownership of said number. In order to accomplish this, proceed as follows:

1. Log into your [sipgate account](https://app.sipgate.com/connections/sms)
2. Use the sidebar to navigate to the **Connections** (_Anschlüsse_) tab
3. Click **SMS** (if this option is not displayed you might need to book the **Web SMS** feature from the Feature Store)
4. Click the gear icon on the right side of the **Caller ID** box and enter the desired sender number.
5. Proceed to follow the instructions on the website to verify the number.


## Usage

### Create a Notification

When your credentials are configured, you can use the `sipgate` channel in your notifications.

```php
class ExampleNotification extends Notification
{
public function via($notifiable)
{
return ['sipgate'];
}

public function toSipgate($notifiable)
{
return SipgateMessage::create('Your message goes here…');
}
}
```

### Add a recipient

You can either choose to add the recipients number to the message itself:

```php
public function toSipgate($notifiable)
{
return SipgateMessage::create('Your message goes here…')->recipient('00491234567890');
}
```

Or add a `routeNotificationForSipgate` method to your notifiable class:

```php
class User extends Authenticatable
{
use Notifiable;

public function routeNotificationForSipgate($notification)
{
return $this->phone_number;
}
}
```

> If you define both, the message will be send to the number you defined in the message.
### Sending On-Demand Notifications

If you want to send a notification to someone who is not registered in your application, use on-demand notifications:

```php
Notification::route('sipgate', '00491234567890')
->notify(new ExampleNotification($message));
```

### Available Message methods
```php
public function toSipgate($notifiable)
{
return (new SipgateMessage('Your message goes here…'))
->message('…or here')
->recipient('00491234567890')
->sendAt(time() + 60)
->smsId('s0');
}
```

> **Optional:**
> In order to send a delayed message set the desired date and time in the future (up to one month):
>
> ```php
> $message->sendAt(time() + 60);
> ```
>
> **Note:** The `sendAt` method accepts a [Unix timestamp](https://www.unixtimestamp.com/).

## Common Issues

#### SMS sent successfully but no message received

Possible reasons are:

- incorrect or mistyped phone number
- recipient phone is not connected to network
- long message text - delivery can take a little longer

#### HTTP Errors

| reason | errorcode |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | :-------: |
| bad request (e.g. request body fields are empty or only contain spaces, timestamp is invalid etc.) | 400 |
| username and/or password are wrong | 401 |
| insufficient account balance | 402 |
| no permission to use specified SMS extension (e.g. SMS feature not booked, user password must be reset in [web app](https://app.sipgate.com/login)) | 403 |
| internal server error or unhandled bad request (e.g. `smsId` not set) | 500 |

## Resources

- [sipgate team FAQ (DE)](https://teamhelp.sipgate.de/hc/de)
- [sipgate basic FAQ (DE)](https://basicsupport.sipgate.de/hc/de)

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Testing

``` bash
$ composer test
```

## Security

If you discover any security related issues, please email mail@simonkubiak.de instead of using the issue tracker.

## Contributing

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

## Credits

- [Simon Kubiak](https://github.com/simonkub)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 comments on commit 56c91e8

Please sign in to comment.