-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Textlocal Channel #37
base: master
Are you sure you want to change the base?
Changes from all commits
16f5684
0feceaa
ccf2195
9ea8b72
a194c6a
519cd62
30ec260
e51d5ac
83e3f76
b37a672
5e0e269
0b5230f
e7906c6
1792aea
3e2438f
c4c5604
964f1bd
09f53ab
e14ddd6
ed07e6d
e3b5ef9
244e5fb
34d77ac
0db2909
b4d67d8
56bf3c9
9ad75cf
2b94219
6e7607f
d24268b
ffebe51
5c0f0da
620d6a4
8c62761
00fb886
4495ca3
4c981b0
203efc2
8bb4701
56795f2
8deb52c
0378869
610ba82
8a6196e
4881869
ee8e7e5
610c6e8
37ad613
e41ddde
4431763
1d3cde6
5ae212f
f57475a
d75d588
0ecbbe6
f645e05
8273965
be0bc25
38bda2c
1ae7cf2
2409b6f
d509d17
8a2349f
30cac8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: composer | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
time: "23:30" | ||
open-pull-requests-limit: 10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Changelog | ||
|
||
All notable changes to `Textlocal` will be documented in this file | ||
|
||
|
||
## 2.4.0 - 2022-08-17 | ||
|
||
`public function getSenderId($notifiable)` | ||
|
||
method has changed from `public function getSenderId()`, so now the notifiable is passed as parameter | ||
giving more control to the imeplementation to decide based on user/recipent in case want to use some alternate deciding factor | ||
|
||
## 0.0.1 - 2017-08-07 | ||
|
||
- initial release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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**! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) Manash Jyoti Sonowal <[email protected]> | ||
|
||
> 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,174 @@ | ||
# new-channels | ||
This package allows to send SMS using Textlocal API using laravel notifications channel textlocal sms | ||
|
||
Discuss about new channel proposals our share your finished channels in the [proposal issue](https://github.com/laravel-notification-channels/new-channels/issues/6). | ||
Supports Laravel 5.5 upto 10.x | ||
|
||
Take a look at our [FAQ](http://laravel-notification-channels.com/) to see our small list of rules, to provide top-notch notification channels. | ||
[](https://packagist.org/packages/msonowal/laravel-notification-channel-textlocal) | ||
[](https://packagist.org/packages/msonowal/laravel-notification-channel-textlocal) | ||
[](https://packagist.org/packages/msonowal/laravel-notification-channel-textlocal) | ||
|
||
This package makes it easy to send notifications using [textlocal](https://www.textlocal.in/) with Laravel 5.3.+ | ||
|
||
|
||
To use version ^2.3.0 onwards will require PHP 8.0 | ||
|
||
for other PHP version use upto ^2.2.0 | ||
|
||
## Contents | ||
|
||
- [Installation](#installation) | ||
- [Setting up the textlocal service](#setting-up-the-textlocal-service) | ||
- [Usage](#usage) | ||
- [Available Message methods](#available-message-methods) | ||
- [Changelog](#changelog) | ||
- [Testing](#testing) | ||
- [Security](#security) | ||
- [Contributing](#contributing) | ||
- [Credits](#credits) | ||
- [License](#license) | ||
|
||
|
||
## Installation | ||
|
||
Create an account in textlocal then create an API key or hash(password). | ||
|
||
`composer require msonowal/laravel-notification-channel-textlocal` | ||
|
||
### Setting up the textlocal service | ||
|
||
default config `textlocal.php` update where desired | ||
|
||
Important Either specify a Key OR a Hash - don't enter both! | ||
|
||
``` | ||
return [ | ||
'username' => env('TEXTLOCAL_USERNAME'), | ||
'password' => env('TEXTLOCAL_PASSWORD'), | ||
'hash' => env('TEXTLOCAL_HASH'), //optional if api_key is set | ||
'api_key' => env('TEXTLOCAL_API_KEY'), //optional if hash is set | ||
'sender' => env('TEXTLOCAL_SENDER'), | ||
'request_urls' => [ | ||
'IN' => 'https://api.textlocal.in/', | ||
'UK' => 'https://api.txtlocal.com/' | ||
], | ||
'country' => env('TEXTLOCAL_COUNTRY', 'IN'), | ||
'extra' => [ | ||
// extra config define keys as desired for use within the textlocal client config | ||
// if you want to use the custom client config for each notification or notifiable | ||
// INotificationUsesTextlocalClientConfig | ||
]public function getSenderId($notifiable) | ||
### Configuring .env | ||
``` | ||
TEXTLOCAL_USERNAME=Your email id or api key | ||
TEXTLOCAL_HASH=get it from url '/docs/' under your API KEYS section | ||
TEXTLOCAL_API_KEY get it from url '/docs/' under your API KEYS section | ||
TEXTLOCAL_SENDER=Name of the Sender that will be displayed to the recipient (max 6 Characters). | ||
TEXTLOCAL_COUNTRY=Your Two letter(ISO-3166-alpha-2) Country Code. It should be the Country of the TEXTLOCAL account. defaults to IN | ||
``` | ||
|
||
### Publish Config | ||
``` | ||
php artisan vendor:publish --tag=textlocal | ||
``` | ||
|
||
Currently, only textlocal of two country is supported IN(India) and UK(United Kingdom). | ||
|
||
## Usage | ||
|
||
Implement this method `routeNotificationForTextlocal()` in your notifiable class/model which will return array of mobile numbers. Please make sure the mobile number contains the dial code as well (e.g +91 for India). And lastly implement `toSms()` method in the notification class which will return the (string) sms or template that is defined in textlocal account that needs to be send. | ||
|
||
|
||
## Usage | ||
|
||
You can use the channel in your `via()` method inside the notification: | ||
|
||
```php | ||
use Illuminate\Notifications\Notification; | ||
use NotificationChannels\Textlocal\TextlocalChannel; | ||
|
||
class TestOTPNotification extends Notification | ||
{ | ||
public function via($notifiable) | ||
{ | ||
return [TextlocalChannel::class]; | ||
} | ||
|
||
public function toSms($notifiable) | ||
{ | ||
return 'Use 1234 as OTP for resetting your password.'; | ||
} | ||
} | ||
``` | ||
|
||
In your notifiable model, make sure to include a `routeNotificationForTextlocal()` method, which returns a phone number or multiple numbers in array | ||
or an array of phone numbers. | ||
|
||
```php | ||
public function routeNotificationForTextlocal(): array | ||
{ | ||
return [$this->mobile_no]; | ||
} | ||
``` | ||
|
||
Annoynmous Notifable when say mobile no is not added to a notifiable model you can directly send to mobile no by using that | ||
|
||
```php | ||
Notification::route('Textlocal', $mobileNo')->notify(new VerifyMobileNotification($otp)); | ||
``` | ||
|
||
### Available Message methods | ||
|
||
And if you want to have a specific sender based on Notification, e.g. like you are sending promotional notification using one and another for transaction then you can just define this method in your notification class which will return your sender id for that notification only | ||
``` | ||
public function getSenderId($notifiable) | ||
{ | ||
return 'YOUR_SENDER_ID'; | ||
} | ||
``` | ||
|
||
|
||
Unicode support | ||
If you want to send the notification content to have unicode support. Define this method in your notification which will return boolean based on which the sms will set the unicode mode in textlocal API | ||
``` | ||
public function getUnicodeMode() | ||
{ | ||
return true; | ||
} | ||
``` | ||
|
||
A list of all available options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing |
||
|
||
## 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 [email protected] instead of using the issue tracker. | ||
|
||
# Found any bugs or improvement open an issue or send me a PR | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
## Credits | ||
|
||
- [Manash Jyoti Sonowal](https://github.com/msonowal) | ||
- [Mr Ejang](https://github.com/tomonsoejang) | ||
- [Sinadh](https://github.com/tsainadh) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. | ||
|
||
## TODO | ||
Need to convert to Guzzle Http as a Client in core | ||
Add more countries | ||
add tests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "msonowal/laravel-notification-channel-textlocal", | ||
"description": "Textlocal Notifications Channel for Laravel", | ||
"homepage": "https://github.com/laravel-notification-channels/textlocal", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Manash Jyoti Sonowal", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/msonowal", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0", | ||
"ext-json": "*", | ||
"illuminate/notifications": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", | ||
"illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "^0.9.5|^1.0", | ||
"phpunit/phpunit": "~5|^8.0|^9.0|^10.0|~11.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"NotificationChannels\\Textlocal\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"NotificationChannels\\Textlocal\\Test\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"NotificationChannels\\Textlocal\\TextlocalServiceProvider" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
return [ | ||
'username' => env('TEXTLOCAL_USERNAME'), | ||
'password' => env('TEXTLOCAL_PASSWORD'), | ||
'hash' => env('TEXTLOCAL_HASH'), | ||
'api_key' => env('TEXTLOCAL_API_KEY'), | ||
'sender' => env('TEXTLOCAL_SENDER', 'DOCONL'), | ||
'request_urls' => [ | ||
'IN' => 'https://api.textlocal.in/', | ||
'UK' => 'https://api.txtlocal.com/', | ||
], | ||
'country' => env('TEXTLOCAL_COUNTRY', 'IN'), | ||
/* | ||
// a sample way to organize custom config when using mutliple on demand config | ||
// uncomment this for that purpose or feel free to use your own implementations | ||
'UK' => [ | ||
'username' => env('TEXTLOCAL_USERNAME_UK'), | ||
'password' => env('TEXTLOCAL_PASSWORD_UK'), | ||
'hash' => env('TEXTLOCAL_HASH_UK'), | ||
'api_key' => env('TEXTLOCAL_API_KEY_UK'), | ||
'sender' => env('TEXTLOCAL_SENDER_UK', 'DOCONL'), | ||
'country' => env('TEXTLOCAL_COUNTRY_UK', 'UK'), | ||
], | ||
*/ | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name=":service_name Test Suite"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Service name here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still missing |
||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="tap" target="build/report.tap"/> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.