Skip to content

Commit 1c7dcbb

Browse files
committed
Added support for content templates (i.e. whatsapp)
1 parent c5a78ce commit 1c7dcbb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Twilio.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa
8989
]);
9090
}
9191

92+
if ($message instanceof TwilioContentTemplateMessage) {
93+
$this->fillOptionalParams($params, $message, [
94+
'contentSid',
95+
'contentVariables',
96+
]);
97+
}
98+
9299
return $this->twilioService->messages->create($to, $params);
93100
}
94101

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace NotificationChannels\Twilio;
4+
5+
class TwilioContentTemplateMessage extends TwilioSmsMessage
6+
{
7+
/**
8+
* The SID of the content template (starting with H)
9+
* @var null|string
10+
*/
11+
public $contentSid;
12+
13+
/**
14+
* The variables to replace in the content template
15+
* @var null|array|string
16+
*/
17+
public $contentVariables;
18+
19+
/**
20+
* Set the content sid (starting with H).
21+
*
22+
* @param string $contentSid
23+
* @return $this
24+
*/
25+
public function contentSid(string $contentSid): self
26+
{
27+
$this->contentSid = $contentSid;
28+
29+
return $this;
30+
}
31+
32+
/**
33+
* Set the content variables.
34+
*
35+
* @param array $contentVariables The variables to replace in the content template (i.e. ['1' => 'John Doe'])
36+
* @return $this
37+
*/
38+
public function contentVariables(array $contentVariables): self
39+
{
40+
$this->contentVariables = json_encode($contentVariables);
41+
42+
return $this;
43+
}
44+
}

0 commit comments

Comments
 (0)