diff --git a/README.md b/README.md index f94b5fb..7db196b 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ public function routeNotificationForOneSignal() - `button(OneSignalButton $button)`: Allows you to add buttons to the notification (Supported by iOS 8.0 and Android 4.1+ devices. Icon only works for Android). - `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). - `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). +- `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments). ### Button usage diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index c3569e7..3ba14de 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -162,6 +162,22 @@ public function button(OneSignalButton $button) return $this; } + /** + * Set an image to all possible attachment variables. + * @param string $imageUrl + * + * @return $this + */ + public function setImageAttachments($imageUrl) + { + $this->extraParameters['ios_attachments']['id1'] = $imageUrl; + $this->extraParameters['big_picture'] = $imageUrl; + $this->extraParameters['adm_big_picture'] = $imageUrl; + $this->extraParameters['chrome_big_picture'] = $imageUrl; + + return $this; + } + /** * @return array */ diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 7631f9f..732fcd5 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -108,4 +108,15 @@ public function it_can_set_a_button() $this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text')); $this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon')); } + + /** @test */ + public function it_can_set_a_image() + { + $this->message->setImageAttachments('https://url.com/to/image.jpg'); + + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'ios_attachments.id1')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'big_picture')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'adm_big_picture')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'chrome_big_picture')); + } }