Skip to content
Merged
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
7 changes: 7 additions & 0 deletions src/Twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa
]);
}

if ($message instanceof TwilioContentTemplateMessage) {
$this->fillOptionalParams($params, $message, [
'contentSid',
'contentVariables',
]);
}

return $this->twilioService->messages->create($to, $params);
}

Expand Down
44 changes: 44 additions & 0 deletions src/TwilioContentTemplateMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace NotificationChannels\Twilio;

class TwilioContentTemplateMessage extends TwilioSmsMessage
{
/**
* The SID of the content template (starting with H)
* @var null|string
*/
public $contentSid;

/**
* The variables to replace in the content template
* @var null|array|string
*/
public $contentVariables;

/**
* Set the content sid (starting with H).
*
* @param string $contentSid
* @return $this
*/
public function contentSid(string $contentSid): self
{
$this->contentSid = $contentSid;

return $this;
}

/**
* Set the content variables.
*
* @param array $contentVariables The variables to replace in the content template (i.e. ['1' => 'John Doe'])
* @return $this
*/
public function contentVariables(array $contentVariables): self
{
$this->contentVariables = json_encode($contentVariables);

return $this;
}
}