Skip to content

Commit

Permalink
Fix invalid sender issues (#11)
Browse files Browse the repository at this point in the history
* fix issues with invalid sender ID

* update readme
  • Loading branch information
ossycodes authored Sep 23, 2021
1 parent 5e4880e commit 3ae5ea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ The service provider gets loaded automatically.

You will need to [Register](https://account.africastalking.com/auth/register/) and then go to your sandbox app [Go To SandBox App](https://account.africastalking.com/apps/sandbox). [Click on settings](https://account.africastalking.com/apps/sandbox/settings/key) Within this page, you will generate your `Username and key`. Place them inside your `.env` file. Remember to add your Sender ID that you will be using to send the messages.

**Please note if you do not have a VALID sender_ID remove "AT_FROM" from .env or set this or set it to null**


```bash
AT_USERNAME=""
AT_KEY=""
AT_FROM=""
AT_FROM="" // please note if you do not have a sender_ID remove this or set it to null
```
To load them, add this to your `config/services.php` . This will load the AfricasTalking data from the `.env` file.file:
Expand Down
21 changes: 15 additions & 6 deletions src/AfricasTalkingChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ public function send($notifiable, Notification $notification)
{
$message = $notification->toAfricasTalking($notifiable);

if (! $phoneNumber = $notifiable->routeNotificationFor('africasTalking')) {
if (!$phoneNumber = $notifiable->routeNotificationFor('africasTalking')) {
$phoneNumber = $notifiable->phone_number;
}

if (is_null($message->getSender())) {
$params = [
'to' => $phoneNumber,
'message' => $message->getContent(),
];
} else {
$params = [
'to' => $phoneNumber,
'message' => $message->getContent(),
'from' => $message->getSender(),
];
}

try {
$this->africasTalking->sms()->send([
'to' => $phoneNumber,
'message' => $message->getContent(),
'from' => $message->getSender(),
]);
$this->africasTalking->sms()->send($params);
} catch (Exception $e) {
throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage());
}
Expand Down

0 comments on commit 3ae5ea8

Please sign in to comment.