Skip to content

Commit ee3fff9

Browse files
committed
Added tests for TwilioContentTemplateMessage
Minor README tweaks Updated CHANGELOG for v4.1.1
1 parent d1144fd commit ee3fff9

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [4.1.1](https://github.com/laravel-notification-channels/twilio/releases/tag/4.1.1) (2025-07-07)
6+
7+
- Added support for content templates (i.e. whatsapp) #152 by @alexw23
8+
59
## [4.1.0](https://github.com/laravel-notification-channels/twilio/releases/tag/4.1.0) (2025-03-03)
610

711
- Added Laravel 12 support #155 #157

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![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)
66
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg)](https://packagist.org/packages/laravel-notification-channels/twilio)
77

8-
This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x
8+
This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x / 12.x
99

1010
## Contents
1111

@@ -86,7 +86,7 @@ suppressed.
8686

8787
## Usage
8888

89-
Now you can use the channel in your `via()` method inside the notification:
89+
Now you can use the channel in your `via()` method inside the notification to send an **SMS**:
9090

9191
``` php
9292
use NotificationChannels\Twilio\TwilioChannel;
@@ -108,7 +108,7 @@ class AccountApproved extends Notification
108108
}
109109
```
110110

111-
You can also send an MMS:
111+
You can also send an **MMS**:
112112

113113
``` php
114114
use NotificationChannels\Twilio\TwilioChannel;
@@ -131,7 +131,7 @@ class AccountApproved extends Notification
131131
}
132132
```
133133

134-
You can also send using Content Templates:
134+
You can also send using **Content Templates**:
135135

136136
``` php
137137
use NotificationChannels\Twilio\TwilioChannel;
@@ -157,9 +157,10 @@ class AccountApproved extends Notification
157157
}
158158
```
159159

160-
*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).*
160+
> [!NOTE]
161+
> 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).
161162
162-
Or create a Twilio call:
163+
Or create a **Twilio Call Message**:
163164

164165
``` php
165166
use NotificationChannels\Twilio\TwilioChannel;
@@ -198,6 +199,15 @@ public function routeNotificationForTwilio()
198199
- `content('')`: Accepts a string value for the notification body.
199200
- `messagingServiceSid('')`: Accepts a messaging service SID to handle configuration.
200201

202+
#### TwilioMmsMessage
203+
204+
- `mediaUrl('')`: Set the message media url.
205+
206+
#### TwilioContentTemplateMessage
207+
208+
- `contentSid('')`: Set the content sid (starting with H).
209+
- `contentVariables([...])`: Set the content variables.
210+
201211
#### TwilioCallMessage
202212

203213
- `from('')`: Accepts a phone to use as the notification sender.

src/TwilioContentTemplateMessage.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ class TwilioContentTemplateMessage extends TwilioSmsMessage
66
{
77
/**
88
* The SID of the content template (starting with H)
9-
* @var null|string
109
*/
11-
public $contentSid;
10+
public ?string $contentSid;
1211

1312
/**
1413
* The variables to replace in the content template
15-
* @var null|array|string
1614
*/
17-
public $contentVariables;
15+
public string|array|null $contentVariables;
1816

1917
/**
2018
* Set the content sid (starting with H).
21-
*
22-
* @param string $contentSid
23-
* @return $this
2419
*/
2520
public function contentSid(string $contentSid): self
2621
{
@@ -33,7 +28,6 @@ public function contentSid(string $contentSid): self
3328
* Set the content variables.
3429
*
3530
* @param array $contentVariables The variables to replace in the content template (i.e. ['1' => 'John Doe'])
36-
* @return $this
3731
*/
3832
public function contentVariables(array $contentVariables): self
3933
{
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace NotificationChannels\Twilio\Tests\Unit;
4+
5+
use NotificationChannels\Twilio\TwilioContentTemplateMessage;
6+
use PHPUnit\Framework\Attributes\Test;
7+
8+
class TwilioContentTemplateMessageTest extends TwilioMessageTestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
parent::setUp();
13+
14+
$this->message = new TwilioContentTemplateMessage;
15+
}
16+
17+
#[Test]
18+
public function it_can_accept_a_message_when_constructing_a_message()
19+
{
20+
$message = new TwilioContentTemplateMessage('myMessage');
21+
22+
$this->assertEquals('myMessage', $message->content);
23+
}
24+
25+
#[Test]
26+
public function it_provides_a_create_method()
27+
{
28+
$message = TwilioContentTemplateMessage::create('myMessage');
29+
30+
$this->assertEquals('myMessage', $message->content);
31+
}
32+
33+
#[Test]
34+
public function it_sets_alphanumeric_sender()
35+
{
36+
$message = TwilioContentTemplateMessage::create('myMessage');
37+
$message->sender('TestSender');
38+
39+
$this->assertEquals('TestSender', $message->alphaNumSender);
40+
}
41+
42+
#[Test]
43+
public function it_sets_content_sid()
44+
{
45+
$message = TwilioContentTemplateMessage::create('myMessage');
46+
$message->contentSid('HXXXXXXXXXXXXXXXXXXXXXXXX');
47+
48+
$this->assertEquals('HXXXXXXXXXXXXXXXXXXXXXXXX', $message->contentSid);
49+
}
50+
51+
#[Test]
52+
public function it_sets_content_variables()
53+
{
54+
$message = TwilioContentTemplateMessage::create('myMessage');
55+
$message->contentVariables([
56+
'1' => 'John Doe',
57+
'2' => 'ACME Inc.',
58+
]);
59+
60+
$this->assertEquals('{"1":"John Doe","2":"ACME Inc."}', $message->contentVariables);
61+
}
62+
}

0 commit comments

Comments
 (0)