Skip to content

Commit 8ffe16e

Browse files
committed
Update AmazonSNS.php
Adding support for sending message in JSON format. Its useful when we want to send a different message for each protocol. For example, using one publish action, you can send a short message to your SMS subscribers and a longer message to your email subscribers.
1 parent 953504c commit 8ffe16e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/AmazonSNS.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,13 @@ public function listTopics($nextToken = null) {
306306
*
307307
* @link http://docs.amazonwebservices.com/sns/latest/api/API_Publish.html
308308
* @param string $topicArn
309-
* @param string $message
309+
* @param string $message
310310
* @param string $subject [optional] Used when sending emails
311+
* @param string $messageStructure [optional] Used when you want to send a different message for each protocol.If you set MessageStructure to json, the value of the Message parameter must: be a syntactically valid JSON object; and contain at least a top-level JSON key of "default" with a value that is a string.
311312
* @return string
312313
* @throws InvalidArgumentException
313314
*/
314-
public function publish($topicArn, $message, $subject = '') {
315+
public function publish($topicArn, $message, $subject = '', $messageStructure = '') {
315316
if(empty($topicArn) || empty($message)) {
316317
throw new InvalidArgumentException('Must supply a TopicARN and Message to publish to a topic');
317318
}
@@ -325,6 +326,10 @@ public function publish($topicArn, $message, $subject = '') {
325326
$params['Subject'] = $subject;
326327
}
327328

329+
if(!empty($messageStructure)) {
330+
$params['MessageStructure'] = $messageStructure;
331+
}
332+
328333
$resultXml = $this->_request('Publish', $params);
329334

330335
return strval($resultXml->PublishResult->MessageId);

0 commit comments

Comments
 (0)