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
55 changes: 24 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
<?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="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/Integration</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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
17 changes: 17 additions & 0 deletions src/Twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NotificationChannels\Twilio;

use DateTime;
use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification;
use Twilio\Exceptions\TwilioException;
use Twilio\Rest\Api\V2010\Account\CallInstance;
Expand Down Expand Up @@ -74,6 +75,11 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa

if ($messagingServiceSid = $this->getMessagingServiceSid($message)) {
$params['messagingServiceSid'] = $messagingServiceSid;

if ($sendAt = $this->getSendAt($message)) {
$params['sendAt'] = $sendAt;
$params['scheduleType'] = 'fixed';
}
}

if ($this->config->isShortenUrlsEnabled()) {
Expand Down Expand Up @@ -171,6 +177,17 @@ protected function getMessagingServiceSid(TwilioSmsMessage $message): ?string
return $message->getMessagingServiceSid() ?: $this->config->getServiceSid();
}

/**
* Get the send at time from the message.
*
* @param TwilioSmsMessage $message
* @return DateTime|null
*/
protected function getSendAt(TwilioSmsMessage $message): ?DateTime
{
return $message->getSendAt();
}

/**
* Get the alphanumeric sender from config, if one exists.
*
Expand Down
26 changes: 26 additions & 0 deletions src/TwilioSmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace NotificationChannels\Twilio;

use DateTime;
use Illuminate\Support\Facades\Date;

class TwilioSmsMessage extends TwilioMessage
{
/**
Expand Down Expand Up @@ -34,6 +37,11 @@ class TwilioSmsMessage extends TwilioMessage
*/
public $provideFeedback;

/**
* @var null|DateTime|string
*/
public $sendAt;

/**
* @var null|int
*/
Expand Down Expand Up @@ -145,6 +153,24 @@ public function provideFeedback(bool $provideFeedback): self
return $this;
}

/**
* Set the date and time at which the message will be sent.
*/
public function sendAt(DateTime $sendAt): self
{
$this->sendAt = $sendAt;

return $this;
}

/**
* Get sendAt of this message.
*/
public function getSendAt(): ?DateTime
{
return $this->sendAt;
}

/**
* Set the validity period (in seconds).
*
Expand Down
31 changes: 31 additions & 0 deletions tests/Unit/TwilioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ public function it_can_send_a_sms_message_to_twilio_with_messaging_service()
$this->twilio->sendMessage($message, '+1111111111');
}

/** @test */
public function it_can_schedule_a_sms_message_to_twilio_with_messaging_service()
{
$message = new TwilioSmsMessage('Message text');

$this->config->shouldReceive('getFrom')
->once()
->andReturn('+1234567890');

$this->config->shouldReceive('getServiceSid')
->once()
->andReturn('service_sid');

$this->config->shouldReceive('getDebugTo')
->once()
->andReturn(null);

$this->twilioService->messages->shouldReceive('create')
->atLeast()->once()
->with('+1111111111', [
'from' => '+1234567890',
'body' => 'Message text',
'messagingServiceSid' => 'service_sid',
"sendAt" => new \DateTime('+30 min'),
"scheduleType" => "fixed"
])
->andReturn(Mockery::mock(MessageInstance::class));

$this->twilio->sendMessage($message, '+1111111111');
}

/** @test */
public function it_can_send_a_call_to_twilio()
{
Expand Down